跳到主内容
@wquguru
精选88elvis技巧与观点

从零构建 Agent Harness 的实操指南与架构拆解

On building an agent harness from scratch.

原文
发到 X
推荐理由

Agent 开发者必读,从底层组件拆解到调试日志策略都给出了具体可落地的步骤,比单纯调用 API 更有深度。

On building an agent harness from scratch.

从零开始构建 Agent 框架。

Got so many questions about where to get started.

关于从哪里入手,我收到了太多问题。

My short guide (feed it to your agent):

我的简短指南(喂给你的 Agent):

If you really want to learn harnesses well, it's worth building one from scratch using a programming language (TypeScript or Python) of your choice.

如果你真的想学好框架(Harness),值得用你选择的编程语言(TypeScript 或 Python)从头构建一个。

When I got started, I implemented my first harness using ReAct from Google: https://academy.dair.ai/papers/react-synergizing-reasoning-and-acting-in-language-models-2210.03629

刚开始时,我使用 Google 的 ReAct 实现了我的第一个框架:https://academy.dair.ai/papers/react-synergizing-reasoning-and-acting-in-language-models-2210.03629

At the time, I built this from scratch, but you can easily prompt your agent to consume the paper and produce a minimal implementation you can inspect and understand.

当时我是从零开始构建的,但你也可以轻松提示你的 Agent 去阅读这篇论文,并生成一个你可以检查和理解的极简实现版本。

You want to target having three parts:

你希望目标包含三个部分:

  • an LLM module for all things inference, and it should ideally support several models. I used OpenRouter when I got started. This can include the system prompt, but you can also separate it out if you plan to explore context-engineering ideas more deeply.
  • a tools module (I recommend building them as MCP tools for interoperability, but you can design functions from scratch if you have experience).
  • an agent loop that encapsulates the tools and LLM. ReAct is one of the more basic loops you can implement.
  • 一个用于所有推理任务的 LLM 模块,它 ideally 应支持多种模型。我刚开始时使用了 OpenRouter。这可以包含系统提示词,但如果你计划更深入地探索上下文工程(context-engineering)理念,你也可以将其分离出来。
  • 一个工具模块(我建议将它们构建为 MCP 工具以实现互操作性,但如果你有经验,也可以从头设计函数)。
  • 一个封装了工具和 LLM 的 Agent 循环。ReAct 是你可以实现的较为基本的循环之一。

Primarily, aim to understand the main components and how they work with each other.

主要目标是理解各个核心组件及其相互协作的方式。

Pro tips:

进阶技巧:

  • try to keep your system prompt minimal and experiment with different models; a mini version of all frontier lab models should be good enough to get you started.
  • look at the code and log things as you experiment with different tasks. You want to log inputs/outputs to the loop, inputs/outputs from LLMs, and inputs/outputs from tool calls as a starting point. Set up a simple set of diverse tasks to test your agent loop on. So with every change, you can run the tasks and inspect the results manually.
  • 尽量保持系统提示词精简,并尝试不同的模型;所有前沿实验室模型的迷你版本应该足以让你起步。
  • 在尝试不同任务时,查看代码并记录日志。作为起点,你需要记录循环的输入/输出、LLM 的输入/输出以及工具调用的输入/输出。设置一组简单的多样化任务来测试你的 Agent 循环。这样每次更改后,你都可以运行这些任务并手动检查结果。

Once you have a good grasp of this, you can easily add other things like skills, memory, etc., once you have a good idea of how to tune them. It helps to keep things modular if you are planning for this. I would recommend playing with memory, skill, and subagent as good next steps.

一旦你很好地掌握了这一点,当你清楚如何调整它们时,就可以轻松添加技能、记忆等其他功能。如果计划这样做,保持模块化会有所帮助。我建议将记忆、技能和子 Agent 作为接下来的良好尝试方向。

If you don't want to build the components or want to start building a more serious agent harness, I recommend using the Pi SDK or LangChain harness tools. I am also going to release something soon to help with this.

如果你不想构建这些组件,或者想开始构建更严肃的 Agent 框架,我建议使用 Pi SDK 或 LangChain 框架工具。我也即将发布一些相关内容来帮助解决这个问题。

Let me know if you have questions. I am planning a longer write-up on this, but this should be enough to give you something to experiment with.

如果有问题请告诉我。我计划写一篇更详细的文章,但这应该足以让你开始实验。

更进一步:量化金融体系

看懂新闻只是起点——沿量化金融路径,把它变成能交付的工程能力

进入量化体系 →

相似阅读

关联信息,但可能不是同一事件