Skip to main content
以下为此前页面的历史文字,签名、默认值和导出清单可能不匹配当前源码;不可作为当前 API 契约。 Current API 本页列出的符号都可以直接这样导入: Signature reference (not executable):

AgentModule 是 QitOS 的策略层。你通过继承它来定义智能体的状态形状、系统提示词、决策逻辑与归约规则;真正的执行循环由 Engine(执行内核)驱动。Signature reference (not executable):
构造函数Signature reference (not executable):
钩子只要求实现 init_statereduce;其余钩子全部可选。
Signature reference (not executable):
创建并返回本次运行的初始状态。
Signature reference (not executable):
把当前观测结果(每步后智能体接收的结构化观察结果)与决策(智能体每步的结构化决策)折叠进下一步状态。
Signature reference (not executable):
返回动态系统提示词;默认返回 None
Signature reference (not executable):
把状态转成模型输入文本;默认是 str(state)
Signature reference (not executable):
自定义决策钩子。返回 Decision 时跳过默认模型调用;返回 None 时继续走 Engine 的模型路径。
Signature reference (not executable):
额外停止条件;默认返回 False
.run() 方法Signature reference (not executable):
这是最常用入口。它会构建 Engine、执行任务,并默认返回 state.final_result;当 return_state=True 时,返回完整 EngineResult
Engine 是执行内核,负责阶段循环、工具执行、恢复、追踪与停止条件评估。Signature reference (not executable):
核心构造参数包括:
  • agent
  • budget(预算)
  • parser
  • stop_criteria
  • critics(评估器)
  • env
  • history_policy
  • trace_writer
  • hooks(钩子)
最常用方法:Signature reference (not executable):
示意片段(非独立程序;完整执行文件见本页链接)。
其中:
  • state:最终强类型状态
  • records:每步 StepRecord
  • events:所有运行时事件
  • step_count:执行步数
  • task_result:结构化任务结果
AsyncEngine 提供非阻塞的智能体执行能力。它封装了同样的 Engine 循环,但把阻塞调用放到线程池中执行,适用于 asyncio 事件循环。Signature reference (not executable):
构造函数Signature reference (not executable):
所有关键字参数会转发给内部的 Engine 构造函数(参数与 Engine.__init__ 相同)。方法Signature reference (not executable):
异步执行智能体循环,返回与 Engine.run() 相同的 EngineResult
Signature reference (not executable):
异步执行智能体循环,并实时产出 EngineEvent 对象。流以 run_start 开始,以 run_end 结束。
Signature reference (not executable):
同步回退——委托给底层 Engine.run()属性
EngineEventAsyncEngine.arun_stream() 产出的结构化事件。示意片段(非独立程序;完整执行文件见本页链接)。
示意片段(非独立程序;完整执行文件见本页链接)。
EventStream 是一个异步兼容的事件队列,用于消费引擎事件:Signature reference (not executable):
Decision 是决策阶段的规范输出(智能体每步的结构化决策)。推荐用工厂方法构造:示意片段(非独立程序;完整执行文件见本页链接)。
四种模式分别对应:
  • "act":执行动作(标准化工具调用)
  • "final":给出最终答案并结束
  • "wait":本步不执行动作
  • "branch":提出多个候选决策
常用基础数据结构包括:
  • StateSchema
  • Task
  • TaskBudget
  • TaskResource
  • Action
  • StopReason
它们共同定义了一次运行的输入、状态与输出语义。当 Engine 已识别立即取消请求时,StopReason.CANCELLED_IMMEDIATE 会把 "cancelled_immediate" 同步写入最终 State、任务/运行结果与 END event;对应的 trace manifest 使用终态 status="stopped",而不是正常完成状态。