taolib.symphony.agent.appserver#
Codex app-server stdio 客户端。
通过 JSON 行协议与 Codex app-server 子进程通信, 支持会话初始化、轮次运行、流式事件处理和会话停止。
Exceptions#
AppServer 通信错误。 |
Classes#
Codex app-server stdio 客户端。 |
Module Contents#
- exception taolib.symphony.agent.appserver.AppServerError#
Bases:
taolib.symphony.errors.AgentErrorAppServer 通信错误。
- class taolib.symphony.agent.appserver.AppServerClient(transport: taolib.symphony.agent.transport.AgentTransport)#
Codex app-server stdio 客户端。
通过 stdin/stdout JSON 行协议与 Codex app-server 子进程通信, 实现会话初始化、轮次运行、流式事件解析等核心交互。
- _transport#
- _process: taolib.symphony.agent.transport.AgentProcess | None = None#
- _token_accounting#
- property token_accounting: taolib.symphony.agent.events.TokenAccounting#
令牌使用追踪器。
- async start(command: str, workspace_path: str, *, approval_policy: str = 'never', sandbox_policy: dict | None = None) None#
启动 app-server 进程。
- 参数:
command -- 启动 app-server 的命令。
workspace_path -- 工作区路径(作为 cwd)。
approval_policy -- 审批策略(默认 never)。
sandbox_policy -- 沙箱策略配置。
- async initialize_session(config: dict[str, Any] | None = None) str#
发送 initialize 消息,返回 session_id。
- 参数:
config -- 初始化配置(工具定义、审批策略等)。
- 返回:
会话 ID 字符串。
- 抛出:
AppServerError -- 初始化失败或通信错误。
- async run_turn(session_id: str, prompt: str, on_event: collections.abc.Callable[[taolib.symphony.agent.events.AppServerEvent], None] | None = None) taolib.symphony.agent.events.TurnResult#
运行一个轮次,流式处理事件。
- 参数:
session_id -- 会话 ID。
prompt -- 轮次提示词。
on_event -- 事件回调函数。
- 返回:
轮次执行结果。
- 抛出:
AppServerError -- 通信错误。
- async _stream_events()#
异步迭代接收事件。