Skip to content

Runtime Adapters

Adapter 实现 RuntimeAdapter 接口,封装具体 Agent 运行时(Mock、Pi、HTTP、MCP)。

工厂总览

工厂类型用途
createMockAdapter(options?)mock测试 / 演示
createPiAgentAdapter(config)pi-agentpi-agent-core 集成
createHttpAdapter(config)httpRemote Unit HTTP 调用
createMcpAdapter(config)mcpMCP 工具调用

createMockAdapter

typescript
function createMockAdapter(options?: MockAdapterOptions): MockRuntimeAdapter

MockAdapterOptions

字段类型说明
responseFn(input: AgentInput) => AgentOutput | Promise<AgentOutput>自定义响应
delayMsnumber模拟延迟
frameworkNamestring框架标识

YAML uses: builtin.mock 内部使用 MockAdapter;config.response / config.route 注入 mock 行为。

createPiAgentAdapter

typescript
function createPiAgentAdapter(config: PiAgentAdapterConfig): PiAgentAdapter

PiAgentAdapterConfig

字段类型必填说明
executeFn(input, ctx) => Promise<AgentOutput>Agent 执行逻辑
systemPromptstring系统提示
steerFn(content: string) => voidsteering 回调
followUpFn(content: string) => voidfollow-up 回调
cancelFn() => void取消回调

依赖:@mariozechner/pi-agent-core

createHttpAdapter

typescript
function createHttpAdapter(config: HttpAdapterConfig): HttpAdapter

HttpAdapterConfig

字段类型必填说明
endpointstringRemote Unit POST URL
headersRecord<string, string>附加头
fetchFntypeof fetch自定义 fetch

请求体:{ input, context }contextExecutionContext)。
inputtask、可选 context / delegatedBy / params(业务策略信封,透传;勿放密钥)。
响应:AgentOutput JSON。

契约:Remote Unit HTTP Contract

YAML bindings { type: "http", endpoint } 通过 registryFromBindings 生成 HttpAdapter 插件。

createMcpAdapter

typescript
function createMcpAdapter(config: McpAdapterConfig): McpAdapter

McpAdapterConfig

字段类型必填说明
serverUrlstringMCP 服务地址
toolNamestring默认工具名
callFn(serverUrl, input, ctx) => Promise<AgentOutput>是*MCP 调用实现

* 未配置 callFnexecute 抛出错误。生产环境需注入真实 MCP 客户端。

RuntimeAdapter 通用方法

方法说明
execute(input, ctx)执行 Agent
steer(content)运行中注入
followUp(content)追加输入
subscribe(handler)事件订阅
cancel()取消
frameworkInfo()框架名与版本

相关

MIT Licensed