Agent 研习舱
Harness 与运行时2026-07-11

Runtime Loop

定义

Runtime Loop 是 Agent 框架内部那个隐藏的主循环:反复"加载上下文 → 调用 LLM → 若有工具调用则执行并回写 → 若需切换 Agent 则 handoff → 若需人类则中断 → 否则返回结果"。判断一个框架是不是 Runtime,不看它能否调模型,而看它是否拥有这个循环。

要点

  • 从协议角度看,这个循环就是 Task/Run 状态机的内部实现:SUBMITTED → WORKING → INPUT_REQUIRED → WORKING → COMPLETED,外加 FAILED / CANCELED 分支。
  • 按"谁拥有循环"分四类:开发者拥有(Responses API、Claude Client SDK)、SDK 拥有(OpenAI/Claude Agent SDK)、图引擎拥有(LangGraph 拆成节点/边/Checkpoint/SuperStep)、服务端拥有(OpenAI Assistants)。
  • 拥有者越靠上游,灵活度越高但要自己写状态/重试/工具执行;越靠下游越省心但控制权和可观测性越少。
  • Agent Harness(如 Deep Agents)不重新发明 Runtime Loop,而是把已有 Runtime 的 durable execution、streaming、checkpointing、HITL 包装成默认可用体验。

示例

while not done:
    messages = load_context()
    output = call_llm(messages, tools)
    if output.tool_calls: execute_tools(...); continue
    if output.handoff: transfer_to_next_agent(); continue
    if output.needs_human: interrupt(); break
    return final_output

相关概念

参考资料

  • 主笔记:Agent Runtime Protocol 稳定对象〔待补〕

被这些概念引用

来自本站知识库 · 全部概念