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) => void否steering 回调
followUpFn(content: string) => void否follow-up 回调
cancelFn() => void否取消回调

依赖:@mariozechner/pi-agent-core

createHttpAdapter ​

typescript
function createHttpAdapter(config: HttpAdapterConfig): HttpAdapter

HttpAdapterConfig ​

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

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

契约:Remote Unit HTTP Contract

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

createMcpAdapter ​

typescript
function createMcpAdapter(config: McpAdapterConfig): McpAdapter

McpAdapterConfig ​

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

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

RuntimeAdapter 通用方法 ​

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

相关 ​

MIT Licensed