|
|
@@ -1,47 +1,94 @@
|
|
|
# Agent 功能需求与架构设计文档
|
|
|
|
|
|
-> **可执行规格书**:本文档是系统的核心设计。代码修改必须同步更新此文档。
|
|
|
-> 如文档与代码冲突,以代码为准,并立即修复文档。
|
|
|
-
|
|
|
----
|
|
|
|
|
|
## 文档维护规范
|
|
|
|
|
|
-**维护原则**:
|
|
|
-1. **谁改代码谁更新文档** - 功能变更后,相关文档必须同步修改
|
|
|
-2. **保持结构稳定** - 只增删内容,不随意调整层级结构
|
|
|
-3. **流程优先** - 新功能先写入核心流程,再补充模块详情
|
|
|
-4. **链接代码** - 关键实现标注文件路径,格式:`module/file.py:function_name`
|
|
|
-5. **简洁原则** - 只记录最重要的、与代码准确对应的或者明确的已完成的设计的信息,避免推测、建议,或大量代码
|
|
|
-6. **文档分层** - 每层文档是不同层次的overview,在上层文档对应位置引用下层详细文档
|
|
|
+0. **先改文档,再动代码** - 新功能或重大修改需先完成文档更新、并完成审阅后,再进行代码实现;除非改动较小、不被文档涵盖
|
|
|
+1. **文档分层,链接代码** - 重要或复杂设计可以另有详细文档;关键实现需标注代码文件路径;格式:`module/file.py:function_name`
|
|
|
+2. **简洁快照,日志分离** - 只记录最重要的、与代码准确对应的或者明确的已完成的设计的信息,避免推测、建议,或大量代码;决策依据或修改日志若有必要,可在`docs/decisions.md`另行记录
|
|
|
|
|
|
---
|
|
|
|
|
|
## 系统概览
|
|
|
|
|
|
-**单次调用是 Agent 的特例**:
|
|
|
+**核心理念:所有 Agent 都是 Trace**
|
|
|
|
|
|
-| 特性 | 单次调用 | Agent 模式 | Sub-Agent 模式 |
|
|
|
-|------|---------|-----------|--------------|
|
|
|
-| 循环次数 | 1 | N (可配置) | N (可配置,受限) |
|
|
|
-| 工具调用 | 可选 | 常用 | 受限工具集 |
|
|
|
-| 状态管理 | 无 | 有 (Trace) | 有 (独立 Trace + 父子关系) |
|
|
|
-| 记忆检索 | 无 | 有 (Experience/Skill) | 有 (继承主 Agent) |
|
|
|
-| 执行图 | 1 条 Message | N 条 Messages 的 DAG | 嵌套 DAG(多个 Trace) |
|
|
|
-| 触发方式 | 直接调用 | 直接调用 | 通过 Task 工具 |
|
|
|
-| 权限范围 | 完整 | 完整 | 受限(可配置) |
|
|
|
+| 类型 | 创建方式 | 父子关系 | 状态 |
|
|
|
+|------|---------|---------|------|
|
|
|
+| 主 Agent | 直接调用 `runner.run()` | 无 parent | 正常执行 |
|
|
|
+| 子 Agent | 通过 `task` 工具 | `parent_trace_id` 指向父 | 正常执行 |
|
|
|
+| 人类协助 | 通过 `ask_human` 工具 | `parent_trace_id` 指向父 | 阻塞等待 |
|
|
|
|
|
|
---
|
|
|
|
|
|
## 核心架构
|
|
|
|
|
|
+### 模块结构
|
|
|
+
|
|
|
+```
|
|
|
+agent/
|
|
|
+├── core/ # 核心引擎
|
|
|
+│ ├── runner.py # AgentRunner + 运行时配置
|
|
|
+│ └── presets.py # Agent 预设(explore、analyst 等)
|
|
|
+│
|
|
|
+├── trace/ # 执行追踪(含计划管理)
|
|
|
+│ ├── models.py # Trace, Message
|
|
|
+│ ├── goal_models.py # Goal, GoalTree, GoalStats
|
|
|
+│ ├── protocols.py # TraceStore 接口
|
|
|
+│ ├── store.py # FileSystemTraceStore 实现
|
|
|
+│ ├── goal_tool.py # goal 工具(计划管理)
|
|
|
+│ ├── explore.py # 探索式子任务
|
|
|
+│ ├── delegate.py # 委派式子任务
|
|
|
+│ ├── compaction.py # Context 压缩
|
|
|
+│ ├── api.py # REST API
|
|
|
+│ ├── websocket.py # WebSocket API
|
|
|
+│ └── trace_id.py # Trace ID 生成工具
|
|
|
+│
|
|
|
+├── tools/ # 外部交互工具
|
|
|
+│ ├── registry.py # 工具注册表
|
|
|
+│ ├── schema.py # Schema 生成器
|
|
|
+│ ├── models.py # ToolResult, ToolContext
|
|
|
+│ └── builtin/
|
|
|
+│ ├── file/ # 文件操作(read, write, edit, glob, grep)
|
|
|
+│ ├── browser/ # 浏览器自动化
|
|
|
+│ ├── bash.py # 命令执行
|
|
|
+│ ├── sandbox.py # 沙箱环境
|
|
|
+│ ├── search.py # 网络搜索
|
|
|
+│ ├── webfetch.py # 网页抓取
|
|
|
+│ ├── skill.py # 技能加载
|
|
|
+│ └── ask_human.py # 人类协助
|
|
|
+│
|
|
|
+├── memory/ # 跨会话记忆
|
|
|
+│ ├── models.py # Experience, Skill
|
|
|
+│ ├── protocols.py # MemoryStore 接口
|
|
|
+│ ├── stores.py # 存储实现
|
|
|
+│ ├── skill_loader.py # Skill 加载器
|
|
|
+│ └── skills/ # 内置 Skills
|
|
|
+│ └── core.md # Core Skill(自动加载)
|
|
|
+│
|
|
|
+├── llm/ # LLM 集成
|
|
|
+│ ├── gemini.py # Gemini Provider
|
|
|
+│ ├── openrouter.py # OpenRouter Provider
|
|
|
+│ └── prompts/ # Prompt 工具
|
|
|
+```
|
|
|
+
|
|
|
+### 职责划分
|
|
|
+
|
|
|
+| 模块 | 职责 |
|
|
|
+|-----|------|
|
|
|
+| **core/** | Agent 执行引擎 + 预设配置 |
|
|
|
+| **trace/** | 执行追踪 + 计划管理 + 子任务(goal, explore, delegate) |
|
|
|
+| **tools/** | 与外部世界交互(文件、命令、网络、浏览器) |
|
|
|
+| **memory/** | 跨会话知识(Skills、Experiences) |
|
|
|
+| **llm/** | LLM Provider 适配 |
|
|
|
+
|
|
|
### 三层记忆模型
|
|
|
|
|
|
```
|
|
|
┌─────────────────────────────────────────────────────────────┐
|
|
|
│ Layer 3: Skills(技能库) │
|
|
|
-│ - Markdown 文件,存储详细的能力描述 │
|
|
|
-│ - 通过 skill 工具按需加载 │
|
|
|
+│ - Markdown 文件,存储领域知识和能力描述 │
|
|
|
+│ - 通过 skill 工具按需加载到对话历史 │
|
|
|
└─────────────────────────────────────────────────────────────┘
|
|
|
▲
|
|
|
│ 归纳
|
|
|
@@ -53,43 +100,39 @@
|
|
|
▲
|
|
|
│ 提取
|
|
|
┌─────────────────────────────────────────────────────────────┐
|
|
|
-│ Layer 1: Task State(任务状态) │
|
|
|
+│ Layer 1: Trace(任务状态) │
|
|
|
│ - 当前任务的工作记忆 │
|
|
|
│ - Trace + Messages 记录执行过程 │
|
|
|
-│ - GoalTree 管理执行计划 │
|
|
|
+│ - Goals 管理执行计划 │
|
|
|
└─────────────────────────────────────────────────────────────┘
|
|
|
```
|
|
|
|
|
|
-**注入方式**:
|
|
|
-- **Skills**:通过 `skill` 工具动态加载到对话历史
|
|
|
-- **Experiences**:检索后注入到 system prompt
|
|
|
-
|
|
|
---
|
|
|
|
|
|
## 核心流程:Agent Loop
|
|
|
|
|
|
```python
|
|
|
-async def run(task: str, max_steps: int = 50) -> AsyncIterator[Union[Trace, Message]]:
|
|
|
+async def run(task: str, agent_type: str = "default") -> AsyncIterator[Union[Trace, Message]]:
|
|
|
# 1. 创建 Trace
|
|
|
- trace = Trace.create(mode="agent", task=task, status="in_progress")
|
|
|
- await trace_store.create_trace(trace)
|
|
|
- yield trace # 返回 Trace(表示开始)
|
|
|
+ trace = Trace.create(
|
|
|
+ mode="agent",
|
|
|
+ task=task,
|
|
|
+ agent_type=agent_type,
|
|
|
+ model=config.model
|
|
|
+ )
|
|
|
+ await store.create_trace(trace)
|
|
|
+ yield trace
|
|
|
|
|
|
- # 2. 加载 Skills(内置 + 自定义)
|
|
|
+ # 2. 加载 Skills,构建 system prompt
|
|
|
skills = load_skills_from_dir(skills_dir)
|
|
|
- skills_text = format_skills(skills)
|
|
|
-
|
|
|
- # 3. 检索 Experiences,构建 system prompt
|
|
|
- experiences = await search_experiences(task)
|
|
|
- system_prompt = build_system_prompt(experiences, skills_text)
|
|
|
+ system_prompt = build_system_prompt(skills)
|
|
|
|
|
|
- # 4. 初始化消息和 GoalTree
|
|
|
+ # 3. 初始化
|
|
|
messages = [{"role": "user", "content": task}]
|
|
|
- goal_tree = GoalTree(mission=task)
|
|
|
|
|
|
- # 5. ReAct 循环
|
|
|
- for step in range(max_steps):
|
|
|
- # 注入当前计划到 system prompt
|
|
|
+ # 4. ReAct 循环
|
|
|
+ for step in range(max_iterations):
|
|
|
+ # 注入当前计划
|
|
|
plan_text = goal_tree.to_prompt()
|
|
|
|
|
|
# 调用 LLM
|
|
|
@@ -100,67 +143,35 @@ async def run(task: str, max_steps: int = 50) -> AsyncIterator[Union[Trace, Mess
|
|
|
)
|
|
|
|
|
|
# 记录 assistant Message
|
|
|
- assistant_msg = Message.create(
|
|
|
+ await store.add_message(Message.create(
|
|
|
trace_id=trace.trace_id,
|
|
|
role="assistant",
|
|
|
- goal_id=goal_tree.current_id,
|
|
|
- content=response.content, # text + tool_calls
|
|
|
- )
|
|
|
- await trace_store.add_message(assistant_msg)
|
|
|
+ sequence=next_seq,
|
|
|
+ content=response
|
|
|
+ ))
|
|
|
yield assistant_msg
|
|
|
|
|
|
# 没有工具调用,完成
|
|
|
if not response.tool_calls:
|
|
|
break
|
|
|
|
|
|
- # 执行工具
|
|
|
+ # 执行工具,记录 tool Message
|
|
|
for tool_call in response.tool_calls:
|
|
|
result = await execute_tool(tool_call)
|
|
|
-
|
|
|
- # 记录 tool Message
|
|
|
- tool_msg = Message.create(
|
|
|
+ await store.add_message(Message.create(
|
|
|
trace_id=trace.trace_id,
|
|
|
role="tool",
|
|
|
- goal_id=goal_tree.current_id,
|
|
|
- tool_call_id=tool_call.id,
|
|
|
- content=result,
|
|
|
- )
|
|
|
- await trace_store.add_message(tool_msg)
|
|
|
+ sequence=next_seq,
|
|
|
+ content=result
|
|
|
+ ))
|
|
|
yield tool_msg
|
|
|
|
|
|
- # 添加到消息历史
|
|
|
- messages.append({"role": "assistant", "tool_calls": [tool_call]})
|
|
|
- messages.append({"role": "tool", "tool_call_id": tool_call.id, "content": result})
|
|
|
-
|
|
|
- # 6. 完成
|
|
|
+ # 5. 完成
|
|
|
trace.status = "completed"
|
|
|
- await trace_store.update_trace(trace.trace_id, status="completed")
|
|
|
yield trace
|
|
|
```
|
|
|
|
|
|
-**关键机制**:
|
|
|
-- **统一返回类型**:`AsyncIterator[Union[Trace, Message]]` - 实时返回执行状态
|
|
|
-- **GoalTree 注入**:每次 LLM 调用前注入当前计划(过滤废弃目标,连续编号)
|
|
|
-- **Message 关联 Goal**:每条 Message 通过 `goal_id` 关联所属 Goal
|
|
|
-- **Doom Loop 检测**:跟踪最近 3 次工具调用,如果都是同一个工具且参数相同,中断循环
|
|
|
-
|
|
|
-### Sub-Agent 执行流程
|
|
|
-
|
|
|
-主 Agent 通过 `task` 工具启动 Sub-Agent。
|
|
|
-
|
|
|
-**层级关系**:
|
|
|
-```
|
|
|
-Main Trace (primary agent)
|
|
|
- └─▶ Sub Trace (parent_trace_id 指向主 Trace)
|
|
|
- └─▶ Steps...
|
|
|
-```
|
|
|
-
|
|
|
-**关键字段**:
|
|
|
-- `Trace.parent_trace_id` - 指向父 Trace
|
|
|
-- `Trace.agent_definition` - Sub-Agent 类型(如 "explore")
|
|
|
-- Sub-Agent 有独立的工具权限配置
|
|
|
-
|
|
|
-**实现位置**:`agent/tools/builtin/task.py`(待实现)
|
|
|
+**实现**:`agent/core/runner.py:AgentRunner`
|
|
|
|
|
|
---
|
|
|
|
|
|
@@ -168,270 +179,360 @@ Main Trace (primary agent)
|
|
|
|
|
|
### Trace(任务执行)
|
|
|
|
|
|
+一次完整的 Agent 执行。所有 Agent(主、子、人类协助)都是 Trace。
|
|
|
+
|
|
|
```python
|
|
|
@dataclass
|
|
|
class Trace:
|
|
|
trace_id: str
|
|
|
- mode: Literal["call", "agent"]
|
|
|
+ mode: Literal["call", "agent"] # 单次调用 or Agent 模式
|
|
|
+
|
|
|
+ # Prompt 标识
|
|
|
+ prompt_name: Optional[str] = None
|
|
|
+
|
|
|
+ # Agent 模式特有
|
|
|
task: Optional[str] = None
|
|
|
agent_type: Optional[str] = None
|
|
|
- status: Literal["running", "completed", "failed"] = "running"
|
|
|
|
|
|
- # Sub-Agent 支持
|
|
|
- parent_trace_id: Optional[str] = None # 父 Trace ID
|
|
|
- agent_definition: Optional[str] = None # Agent 类型名称
|
|
|
- spawned_by_tool: Optional[str] = None # 启动此 Sub-Agent 的 Message ID
|
|
|
+ # 父子关系(Sub-Trace 特有)
|
|
|
+ parent_trace_id: Optional[str] = None # 父 Trace ID
|
|
|
+ parent_goal_id: Optional[str] = None # 哪个 Goal 启动的
|
|
|
+
|
|
|
+ # 状态
|
|
|
+ status: Literal["running", "completed", "failed"] = "running"
|
|
|
|
|
|
# 统计
|
|
|
total_messages: int = 0
|
|
|
- total_tokens: int = 0
|
|
|
+ total_tokens: int = 0 # 总 tokens(prompt + completion)
|
|
|
+ total_prompt_tokens: int = 0
|
|
|
+ total_completion_tokens: int = 0
|
|
|
total_cost: float = 0.0
|
|
|
+ total_duration_ms: int = 0
|
|
|
|
|
|
- # 上下文
|
|
|
+ # 进度追踪
|
|
|
+ last_sequence: int = 0 # 最新 message 的 sequence
|
|
|
+ last_event_id: int = 0 # 最新事件 ID(用于 WS 续传)
|
|
|
+
|
|
|
+ # 配置
|
|
|
uid: Optional[str] = None
|
|
|
- context: Dict[str, Any] = field(default_factory=dict)
|
|
|
- current_goal_id: Optional[str] = None # 当前焦点 goal
|
|
|
+ model: Optional[str] = None # 默认模型
|
|
|
+ tools: Optional[List[Dict]] = None # 工具定义(OpenAI 格式)
|
|
|
+ llm_params: Dict[str, Any] = {} # LLM 参数(temperature 等)
|
|
|
+ context: Dict[str, Any] = {} # 其他元数据
|
|
|
+
|
|
|
+ # 当前焦点
|
|
|
+ current_goal_id: Optional[str] = None
|
|
|
+
|
|
|
+ # 结果
|
|
|
+ result_summary: Optional[str] = None
|
|
|
+ error_message: Optional[str] = None
|
|
|
+
|
|
|
+ # 时间
|
|
|
+ created_at: datetime
|
|
|
+ completed_at: Optional[datetime] = None
|
|
|
+```
|
|
|
+
|
|
|
+**实现**:`agent/trace/models.py`
|
|
|
+
|
|
|
+### Goal(目标节点)
|
|
|
+
|
|
|
+计划中的一个目标,支持层级结构。单独存储于 `goal.json`。
|
|
|
+
|
|
|
+```python
|
|
|
+@dataclass
|
|
|
+class Goal:
|
|
|
+ id: str # 内部 ID("1", "2"...)
|
|
|
+ description: str
|
|
|
+ reason: str = "" # 创建理由
|
|
|
+ parent_id: Optional[str] = None # 父 Goal ID
|
|
|
+ type: GoalType = "normal" # normal | agent_call
|
|
|
+ status: GoalStatus = "pending" # pending | in_progress | completed | abandoned
|
|
|
+ summary: Optional[str] = None # 完成/放弃时的总结
|
|
|
+
|
|
|
+ # agent_call 特有(启动 Sub-Trace)
|
|
|
+ sub_trace_ids: Optional[List[str]] = None
|
|
|
+ agent_call_mode: Optional[str] = None # explore | delegate | sequential
|
|
|
+ sub_trace_metadata: Optional[Dict] = None
|
|
|
+
|
|
|
+ # 统计
|
|
|
+ self_stats: GoalStats # 自身 Messages 统计
|
|
|
+ cumulative_stats: GoalStats # 包含子孙的累计统计
|
|
|
+
|
|
|
+ created_at: datetime
|
|
|
```
|
|
|
|
|
|
-**实现**:`agent/execution/models.py:Trace`
|
|
|
+**Goal 操作**(通过 goal 工具):
|
|
|
+- `add` - 添加顶层目标
|
|
|
+- `under` - 在指定目标下添加子目标
|
|
|
+- `after` - 在指定目标后添加兄弟目标
|
|
|
+- `focus` - 切换焦点到指定目标
|
|
|
+- `done` - 完成当前目标(附带 summary)
|
|
|
+- `abandon` - 放弃当前目标(附带原因)
|
|
|
+
|
|
|
+**实现**:`agent/trace/goal_models.py`, `agent/trace/goal_tool.py`
|
|
|
|
|
|
### Message(执行消息)
|
|
|
|
|
|
-对应 LLM API 的消息,加上元数据。不再有 parent_id 树结构。
|
|
|
+对应 LLM API 的消息,每条 Message 关联一个 Goal。
|
|
|
|
|
|
```python
|
|
|
@dataclass
|
|
|
class Message:
|
|
|
- message_id: str
|
|
|
+ message_id: str # 格式:{trace_id}-{sequence:04d}
|
|
|
trace_id: str
|
|
|
- role: Literal["assistant", "tool"] # 和 LLM API 一致
|
|
|
- sequence: int # 全局顺序
|
|
|
- goal_id: str # 关联的 Goal 内部 ID
|
|
|
- tool_call_id: Optional[str] = None # tool 消息关联对应的 tool_call
|
|
|
- content: Any = None # 消息内容(和 LLM API 格式一致)
|
|
|
- description: str = "" # 系统自动提取的摘要
|
|
|
-
|
|
|
- # 元数据
|
|
|
- tokens: Optional[int] = None
|
|
|
+ role: Literal["system", "user", "assistant", "tool"]
|
|
|
+ sequence: int # 全局顺序
|
|
|
+ goal_id: Optional[str] = None # 关联的 Goal ID
|
|
|
+ description: str = "" # 系统自动生成的摘要
|
|
|
+ tool_call_id: Optional[str] = None
|
|
|
+ content: Any = None
|
|
|
+
|
|
|
+ # 统计
|
|
|
+ prompt_tokens: Optional[int] = None
|
|
|
+ completion_tokens: Optional[int] = None
|
|
|
cost: Optional[float] = None
|
|
|
+ duration_ms: Optional[int] = None
|
|
|
+
|
|
|
+ # LLM 响应信息(仅 role="assistant")
|
|
|
+ finish_reason: Optional[str] = None
|
|
|
+
|
|
|
+ created_at: datetime
|
|
|
+```
|
|
|
+
|
|
|
+**实现**:`agent/trace/models.py`
|
|
|
+
|
|
|
+---
|
|
|
+
|
|
|
+## Agent 预设
|
|
|
+
|
|
|
+不同类型 Agent 的配置模板,控制工具权限和参数。
|
|
|
+
|
|
|
+```python
|
|
|
+@dataclass
|
|
|
+class AgentPreset:
|
|
|
+ allowed_tools: Optional[List[str]] = None # None 表示允许全部
|
|
|
+ denied_tools: Optional[List[str]] = None # 黑名单
|
|
|
+ max_iterations: int = 30
|
|
|
+ temperature: Optional[float] = None
|
|
|
+ description: Optional[str] = None
|
|
|
+
|
|
|
+
|
|
|
+AGENT_PRESETS = {
|
|
|
+ "default": AgentPreset(
|
|
|
+ allowed_tools=None,
|
|
|
+ max_iterations=30,
|
|
|
+ description="默认 Agent,拥有全部工具权限",
|
|
|
+ ),
|
|
|
+ "explore": AgentPreset(
|
|
|
+ allowed_tools=["read", "glob", "grep", "list_files"],
|
|
|
+ denied_tools=["write", "edit", "bash", "task"],
|
|
|
+ max_iterations=15,
|
|
|
+ description="探索型 Agent,只读权限,用于代码分析",
|
|
|
+ ),
|
|
|
+ "analyst": AgentPreset(
|
|
|
+ allowed_tools=["read", "glob", "grep", "web_search", "webfetch"],
|
|
|
+ denied_tools=["write", "edit", "bash", "task"],
|
|
|
+ temperature=0.3,
|
|
|
+ max_iterations=25,
|
|
|
+ description="分析型 Agent,用于深度分析和研究",
|
|
|
+ ),
|
|
|
+}
|
|
|
```
|
|
|
|
|
|
-**实现**:`agent/execution/models.py:Message`
|
|
|
+**实现**:`agent/core/presets.py`
|
|
|
|
|
|
-**Message 类型**:
|
|
|
-- `role="assistant"`:模型的一次返回(可能同时包含文本和多个 tool_calls)
|
|
|
-- `role="tool"`:一个工具的执行结果(通过 `tool_call_id` 关联)
|
|
|
+**用户自定义**:项目级配置 `.agent/presets.json` 可覆盖或添加预设。
|
|
|
|
|
|
---
|
|
|
|
|
|
-## 模块详情
|
|
|
-
|
|
|
-详细的模块文档请参阅:
|
|
|
-
|
|
|
-### [项目结构](./project-structure.md)
|
|
|
-- 框架与应用分层设计
|
|
|
-- 框架内置预设(agent/presets/, agent/skills/)
|
|
|
-- 项目层配置(./skills/, ./subagents/, ./tools/)
|
|
|
-- 加载优先级和覆盖机制
|
|
|
-
|
|
|
-### [Sub-Agent 机制](./sub-agents.md)
|
|
|
-- 数据模型:AgentDefinition、Trace 扩展
|
|
|
-- 内置 Sub-Agent:general、explore、analyst
|
|
|
-- Task Tool 实现
|
|
|
-- Agent Registry 和权限控制
|
|
|
-- 配置文件格式
|
|
|
-
|
|
|
-**使用示例**:`examples/subagent_example.py`
|
|
|
-
|
|
|
-### [Context 管理与可视化](./context-management.md)
|
|
|
-- GoalTree:层级目标管理(嵌套 JSON,注入 LLM)
|
|
|
-- Goal ID 设计:内部 ID(稳定)vs 显示序号(连续,给 LLM)
|
|
|
-- goal 工具:计划管理(add, after, under, done, abandon, focus)
|
|
|
-- 位置控制:after(同层级追加)、under(子任务拆解)
|
|
|
-- Plan 注入策略:完整展示当前目标及其父链
|
|
|
-- explore 工具:并行探索-合并,收集每个 Sub-Trace 的最后消息作为元数据
|
|
|
-- 回溯机制:未执行直接修改 / 已执行标记废弃+新分支
|
|
|
-- DAG 可视化:节点=结果,边=动作,边可展开/折叠
|
|
|
-- 数据结构:GoalTree + Messages(扁平列表,goal_id 关联)
|
|
|
-- Sub-Trace 元数据:last_message, summary, stats(用于辅助决策和可视化)
|
|
|
-
|
|
|
-### [工具系统](./tools.md)
|
|
|
-- 工具定义和注册
|
|
|
-- 双层记忆管理
|
|
|
-- 域名过滤、敏感数据处理
|
|
|
-- 最佳实践
|
|
|
-
|
|
|
-**工具接入规范**:
|
|
|
-- **高频&简单工具**:Python 原生实现 → `agent/tools/builtin/`
|
|
|
-- **复杂&低频工具**:第三方仓库 → `vendor/` + 适配器 → `agent/tools/advanced/`
|
|
|
-- **CLI 命令行工具**:pip 安装 → `bash_command` 调用(如 browser-use)
|
|
|
-
|
|
|
-**内置工具**(`builtin/`):
|
|
|
-- `read_file`, `edit_file`, `write_file` - 文件操作
|
|
|
-- `bash_command` - 命令执行
|
|
|
-- `glob_files`, `grep_content` - 文件搜索
|
|
|
-- `skill`, `list_skills` - 技能库管理
|
|
|
-
|
|
|
-**高级工具**(`advanced/`):
|
|
|
-- `webfetch` - 网页抓取(调用 opencode)
|
|
|
-- `lsp_diagnostics` - LSP 诊断(调用 opencode)
|
|
|
-
|
|
|
-**Skills**(`agent/skills/`):
|
|
|
-- `browser_use` - 浏览器自动化(包含环境配置工具)
|
|
|
-
|
|
|
-**详细设计**:参考 [`docs/tools-adapters.md`](./tools-adapters.md)
|
|
|
-
|
|
|
-**核心特性**:
|
|
|
+## 子 Trace 机制
|
|
|
+
|
|
|
+### explore 模式
|
|
|
+
|
|
|
+并行探索多个分支,汇总结果返回。
|
|
|
+
|
|
|
```python
|
|
|
-from reson_agent import tool, ToolResult, ToolContext
|
|
|
+# 创建多个探索分支
|
|
|
+child_traces = await create_explore_traces(
|
|
|
+ parent_trace_id=ctx.trace_id,
|
|
|
+ prompts=["分析 A 方案", "分析 B 方案", "分析 C 方案"]
|
|
|
+)
|
|
|
+# 并行执行
|
|
|
+results = await asyncio.gather(*[run_trace(t) for t in child_traces])
|
|
|
+```
|
|
|
+
|
|
|
+**实现**:`agent/trace/explore.py`
|
|
|
+
|
|
|
+### delegate 模式
|
|
|
|
|
|
-@tool(
|
|
|
- url_patterns=["*.google.com"],
|
|
|
- requires_confirmation=True
|
|
|
+委派子任务给专门的 Agent 执行。
|
|
|
+
|
|
|
+```python
|
|
|
+child_trace = await create_delegate_trace(
|
|
|
+ parent_trace_id=ctx.trace_id,
|
|
|
+ task=prompt,
|
|
|
+ agent_type="analyst" # 使用 analyst 预设
|
|
|
)
|
|
|
-async def my_tool(arg: str, ctx: ToolContext) -> ToolResult:
|
|
|
- return ToolResult(
|
|
|
- title="Success",
|
|
|
- output="Result content",
|
|
|
- long_term_memory="Short summary"
|
|
|
- )
|
|
|
+result = await run_trace(child_trace)
|
|
|
```
|
|
|
|
|
|
-### [多模态支持](./multimodal.md)
|
|
|
-- Prompt 层多模态消息构建
|
|
|
-- OpenAI 格式消息规范
|
|
|
-- Gemini Provider 适配
|
|
|
-- 图片资源处理
|
|
|
+**实现**:`agent/trace/delegate.py`
|
|
|
|
|
|
-**实现**:
|
|
|
-- `agent/llm/prompts/wrapper.py:SimplePrompt` - Prompt 包装器
|
|
|
-- `agent/llm/gemini.py:_convert_messages_to_gemini` - 格式转换
|
|
|
+### ask_human 工具
|
|
|
|
|
|
-**使用示例**:`examples/feature_extract/run.py`
|
|
|
+创建阻塞式 Trace,等待人类通过 IM/邮件等渠道回复。
|
|
|
|
|
|
-### Prompt Loader(提示加载器)
|
|
|
+```python
|
|
|
+@tool(name="ask_human")
|
|
|
+async def ask_human_tool(question: str, channel: str, ctx: ToolContext) -> ToolResult:
|
|
|
+ human_trace = await ctx.store.create_trace(
|
|
|
+ task=question,
|
|
|
+ parent_trace_id=ctx.trace_id,
|
|
|
+ blocked=True,
|
|
|
+ blocked_reason=f"等待人类通过 {channel} 回复"
|
|
|
+ )
|
|
|
+ await send_to_channel(channel, question)
|
|
|
+ response = await wait_for_human_response(human_trace.id)
|
|
|
+ return ToolResult(output=response)
|
|
|
+```
|
|
|
|
|
|
-**职责**:加载和处理 `.prompt` 文件,支持多模态消息构建
|
|
|
+**实现**:`agent/tools/builtin/ask_human.py`
|
|
|
|
|
|
-**文件格式**:
|
|
|
-```yaml
|
|
|
----
|
|
|
-model: gemini-2.5-flash
|
|
|
-temperature: 0.3
|
|
|
---
|
|
|
|
|
|
-$system$
|
|
|
-系统提示...
|
|
|
+## 工具系统
|
|
|
|
|
|
-$user$
|
|
|
-用户提示:%variable%
|
|
|
+### 核心概念
|
|
|
+
|
|
|
+```python
|
|
|
+@tool()
|
|
|
+async def my_tool(arg: str, ctx: ToolContext) -> ToolResult:
|
|
|
+ return ToolResult(
|
|
|
+ title="Success",
|
|
|
+ output="Result content",
|
|
|
+ long_term_memory="Short summary" # 可选:压缩后保留的摘要
|
|
|
+ )
|
|
|
```
|
|
|
|
|
|
-**核心功能**:
|
|
|
-- YAML frontmatter 解析(配置)
|
|
|
-- `$section$` 分节语法
|
|
|
-- `%variable%` 参数替换
|
|
|
-- 多模态消息支持(图片等)
|
|
|
+| 类型 | 作用 |
|
|
|
+|------|------|
|
|
|
+| `@tool` | 装饰器,自动注册工具并生成 Schema |
|
|
|
+| `ToolResult` | 工具执行结果,支持双层记忆 |
|
|
|
+| `ToolContext` | 工具执行上下文,依赖注入 |
|
|
|
|
|
|
-**实现**:
|
|
|
-- `agent/llm/prompts/loader.py:load_prompt()` - 文件解析
|
|
|
-- `agent/llm/prompts/loader.py:get_message()` - 参数替换
|
|
|
-- `agent/llm/prompts/wrapper.py:SimplePrompt` - Prompt 包装器
|
|
|
+### 工具分类
|
|
|
+
|
|
|
+| 目录 | 工具 | 说明 |
|
|
|
+|-----|------|------|
|
|
|
+| `trace/` | goal | Agent 内部计划管理 |
|
|
|
+| `trace/` | explore, delegate | 子 Trace 创建 |
|
|
|
+| `builtin/file/` | read, write, edit, glob, grep | 文件操作 |
|
|
|
+| `builtin/browser/` | browser actions | 浏览器自动化 |
|
|
|
+| `builtin/` | bash, sandbox, search, webfetch, skill, ask_human | 其他工具 |
|
|
|
+
|
|
|
+### 双层记忆管理
|
|
|
+
|
|
|
+大输出(如网页抓取)只传给 LLM 一次,之后用摘要替代:
|
|
|
|
|
|
-**使用**:
|
|
|
```python
|
|
|
-prompt = SimplePrompt("task.prompt")
|
|
|
-messages = prompt.build_messages(text="...", images="img.png")
|
|
|
+ToolResult(
|
|
|
+ output="<10K tokens 的完整内容>",
|
|
|
+ long_term_memory="Extracted 10000 chars from amazon.com",
|
|
|
+ include_output_only_once=True
|
|
|
+)
|
|
|
```
|
|
|
|
|
|
-### Skills(技能库)
|
|
|
+**详细文档**:[工具系统](./tools.md)
|
|
|
+
|
|
|
+---
|
|
|
+
|
|
|
+## Skills 系统
|
|
|
|
|
|
-**分类**:
|
|
|
+### 分类
|
|
|
|
|
|
| 类型 | 加载位置 | 加载时机 |
|
|
|
|------|---------|---------|
|
|
|
-| **Core Skill** | System Prompt | Agent 启动时自动 |
|
|
|
+| **Core Skill** | System Prompt | Agent 启动时自动加载 |
|
|
|
| **普通 Skill** | 对话消息 | 模型调用 `skill` 工具时 |
|
|
|
|
|
|
-**目录结构**:
|
|
|
+### 目录结构
|
|
|
|
|
|
```
|
|
|
-./agent/skills/
|
|
|
-├── core.md # Core Skill(自动加载到 System Prompt)
|
|
|
-└── browser_use/ # 普通 Skill(按需加载到对话消息)
|
|
|
- ├── browser-use.md
|
|
|
- ├── setup.py
|
|
|
- └── __init__.py
|
|
|
-```
|
|
|
-
|
|
|
-**Core Skill**(`agent/skills/core.md`):
|
|
|
-- 核心系统功能:Step 管理、进度追踪
|
|
|
-- 框架自动注入到 System Prompt
|
|
|
-
|
|
|
-**普通 Skill**:通过 `skill` 工具动态加载
|
|
|
+agent/memory/skills/
|
|
|
+├── core.md # Core Skill(自动加载到 System Prompt)
|
|
|
+└── browser_use/ # 普通 Skill(按需加载)
|
|
|
|
|
|
-```python
|
|
|
-# Agent 运行时调用
|
|
|
-await tools.execute("skill", {"skill_name": "browser-use"})
|
|
|
-# 内容注入到对话历史
|
|
|
+./skills/ # 项目自定义 Skills(按需加载)
|
|
|
```
|
|
|
|
|
|
-**实现**:
|
|
|
-- `agent/memory/skill_loader.py:SkillLoader` - Markdown 解析器
|
|
|
-- `agent/memory/skill_loader.py:load_skills_from_dir()` - Skills 自动加载(内置 + 自定义)
|
|
|
-- `agent/tools/builtin/skill.py:skill()` - skill 工具实现
|
|
|
-- `agent/tools/builtin/skill.py:list_skills()` - 列出可用 skills
|
|
|
-
|
|
|
-**详细文档**:参考 [`docs/skills.md`](./skills.md)
|
|
|
+**实现**:`agent/memory/skill_loader.py`
|
|
|
|
|
|
-### Experiences(经验库)
|
|
|
+**详细文档**:[Skills 使用指南](./skills.md)
|
|
|
|
|
|
-**存储**:PostgreSQL + pgvector
|
|
|
+---
|
|
|
|
|
|
-```sql
|
|
|
-CREATE TABLE experiences (
|
|
|
- exp_id TEXT PRIMARY KEY,
|
|
|
- scope TEXT, -- "agent:executor" 或 "user:123"
|
|
|
- condition TEXT, -- "当遇到数据库连接超时"
|
|
|
- rule TEXT, -- "增加重试次数到5次"
|
|
|
- evidence JSONB, -- 证据(step_ids)
|
|
|
+## Experiences 系统
|
|
|
|
|
|
- source TEXT, -- "execution", "feedback", "manual"
|
|
|
- confidence FLOAT,
|
|
|
- usage_count INT,
|
|
|
- success_rate FLOAT,
|
|
|
+从执行历史中提取的经验规则,用于指导未来任务。
|
|
|
|
|
|
- embedding vector(1536), -- 向量检索
|
|
|
+### 数据结构
|
|
|
|
|
|
- created_at TIMESTAMP,
|
|
|
- updated_at TIMESTAMP
|
|
|
-);
|
|
|
+```python
|
|
|
+@dataclass
|
|
|
+class Experience:
|
|
|
+ id: str
|
|
|
+ scope: str # "agent:executor" 或 "user:123"
|
|
|
+ condition: str # "当遇到数据库连接超时"
|
|
|
+ rule: str # "增加重试次数到5次"
|
|
|
+ evidence: Dict # 证据(trace_ids)
|
|
|
+ confidence: float
|
|
|
+ usage_count: int
|
|
|
+ success_rate: float
|
|
|
+ embedding: List[float] # 向量,用于检索
|
|
|
```
|
|
|
|
|
|
-**检索和注入**:
|
|
|
+### 检索和注入
|
|
|
|
|
|
```python
|
|
|
# 1. 检索相关 Experiences
|
|
|
experiences = await db.query(
|
|
|
- """
|
|
|
- SELECT condition, rule, success_rate
|
|
|
- FROM experiences
|
|
|
- WHERE scope = $1
|
|
|
- ORDER BY embedding <-> $2
|
|
|
- LIMIT 10
|
|
|
- """,
|
|
|
- f"agent:{agent_type}",
|
|
|
- embed(task)
|
|
|
+ "SELECT * FROM experiences WHERE scope = $1 ORDER BY embedding <-> $2 LIMIT 10",
|
|
|
+ f"agent:{agent_type}", embed(task)
|
|
|
)
|
|
|
|
|
|
# 2. 注入到 system prompt
|
|
|
-system_prompt = base_prompt + "\n\n# Learned Experiences\n" + "\n".join([
|
|
|
- f"- When {e.condition}, then {e.rule} (success rate: {e.success_rate:.1%})"
|
|
|
- for e in experiences
|
|
|
-])
|
|
|
+system_prompt += "\n# Learned Experiences\n" + format_experiences(experiences)
|
|
|
```
|
|
|
|
|
|
-**实现**:`agent/memory/stores.py:ExperienceStore`(待实现 PostgreSQL 版本)
|
|
|
+**存储**:PostgreSQL + pgvector
|
|
|
+
|
|
|
+**实现**:`agent/memory/stores.py:ExperienceStore`
|
|
|
+
|
|
|
+---
|
|
|
+
|
|
|
+## Context 压缩
|
|
|
+
|
|
|
+### 压缩时机
|
|
|
+
|
|
|
+Goal 完成(done)或放弃(abandon)时,将详细 Messages 替换为 Summary Message。
|
|
|
+
|
|
|
+### 压缩策略
|
|
|
+
|
|
|
+```
|
|
|
+Goal 状态变化
|
|
|
+ ↓
|
|
|
+收集该 Goal 下的所有 Messages
|
|
|
+ ↓
|
|
|
+生成 Summary(由 LLM 提供)
|
|
|
+ ↓
|
|
|
+替换原始 Messages 为单条 Summary Message
|
|
|
+ ↓
|
|
|
+更新统计信息
|
|
|
+```
|
|
|
+
|
|
|
+**实现**:`agent/trace/compaction.py`
|
|
|
+
|
|
|
+**详细文档**:[Context 管理](./context-management.md)
|
|
|
|
|
|
---
|
|
|
|
|
|
@@ -439,81 +540,47 @@ system_prompt = base_prompt + "\n\n# Learned Experiences\n" + "\n".join([
|
|
|
|
|
|
```python
|
|
|
class TraceStore(Protocol):
|
|
|
- async def save(self, trace: Trace) -> None: ...
|
|
|
- async def get(self, trace_id: str) -> Trace: ...
|
|
|
+ async def create_trace(self, trace: Trace) -> None: ...
|
|
|
+ async def get_trace(self, trace_id: str) -> Trace: ...
|
|
|
+ async def update_trace(self, trace_id: str, **updates) -> None: ...
|
|
|
async def add_message(self, message: Message) -> None: ...
|
|
|
async def get_messages(self, trace_id: str) -> List[Message]: ...
|
|
|
async def get_messages_by_goal(self, trace_id: str, goal_id: str) -> List[Message]: ...
|
|
|
-
|
|
|
-class ExperienceStore(Protocol):
|
|
|
- async def search(self, scope: str, query: str, limit: int) -> List[Dict]: ...
|
|
|
- async def add(self, exp: Dict) -> None: ...
|
|
|
- async def update_stats(self, exp_id: str, success: bool) -> None: ...
|
|
|
-
|
|
|
-class SkillLoader(Protocol):
|
|
|
- async def scan(self) -> List[str]: # 返回 skill names
|
|
|
- """扫描并返回所有可用的 skill 名称"""
|
|
|
-
|
|
|
- async def load(self, name: str) -> str: # 返回内容
|
|
|
- """加载指定 skill 的 Markdown 内容"""
|
|
|
```
|
|
|
|
|
|
**实现**:
|
|
|
-- Trace/Message 协议:`agent/execution/protocols.py`
|
|
|
-- Memory 协议:`agent/memory/protocols.py`
|
|
|
-
|
|
|
-**实现策略**:
|
|
|
-- Trace/Message: 文件系统(JSON)
|
|
|
- - `FileSystemTraceStore` - 文件持久化(支持跨进程)
|
|
|
-- Experience: PostgreSQL + pgvector
|
|
|
-- Skill: 文件系统(Markdown)
|
|
|
+- 协议定义:`agent/trace/protocols.py`
|
|
|
+- 文件存储:`agent/trace/store.py:FileSystemTraceStore`
|
|
|
|
|
|
----
|
|
|
-
|
|
|
-## 模块结构(v0.2.2)
|
|
|
+### 存储结构
|
|
|
|
|
|
```
|
|
|
-agent/
|
|
|
-├── __init__.py # 公开 API
|
|
|
-│
|
|
|
-├── core/ # 核心引擎
|
|
|
-│ ├── runner.py # AgentRunner
|
|
|
-│ └── config.py # AgentConfig, CallResult
|
|
|
-│
|
|
|
-├── execution/ # 执行追踪
|
|
|
-│ ├── models.py # Trace, Message
|
|
|
-│ ├── protocols.py # TraceStore
|
|
|
-│ ├── fs_store.py # FileSystemTraceStore
|
|
|
-│ ├── api.py # RESTful API(DAG 视图)
|
|
|
-│ └── websocket.py # WebSocket
|
|
|
-│
|
|
|
-├── memory/ # 记忆系统
|
|
|
-│ ├── models.py # Experience, Skill
|
|
|
-│ ├── protocols.py # MemoryStore, StateStore
|
|
|
-│ ├── stores.py # 存储实现
|
|
|
-│ └── skill_loader.py # Skill 加载器(自动加载内置 skills)
|
|
|
-│
|
|
|
-├── tools/ # 工具系统
|
|
|
-│ ├── registry.py # ToolRegistry
|
|
|
-│ ├── models.py # ToolResult, ToolContext
|
|
|
-│ ├── schema.py # SchemaGenerator
|
|
|
-│ ├── url_matcher.py # URL 模式匹配
|
|
|
-│ ├── sensitive.py # 敏感数据处理
|
|
|
-│ ├── builtin/ # 核心工具
|
|
|
-│ ├── advanced/ # 高级工具
|
|
|
-│ └── adapters/ # 外部集成
|
|
|
-│
|
|
|
-├── llm/ # LLM 相关
|
|
|
-│ ├── gemini.py
|
|
|
-│ ├── openrouter.py
|
|
|
-│ └── prompts/
|
|
|
-│ ├── loader.py
|
|
|
-│ └── wrapper.py
|
|
|
+.trace/
|
|
|
+├── {trace_id}/
|
|
|
+│ ├── meta.json # Trace 元数据(含 tools 定义)
|
|
|
+│ ├── goal.json # GoalTree(mission + goals 列表)
|
|
|
+│ └── messages/ # Messages
|
|
|
+│ ├── 0001.json
|
|
|
+│ └── ...
|
|
|
│
|
|
|
-├── skills/ # 内置 Skills(自动加载)
|
|
|
-│ └── core.md # 核心 skill,每次运行自动加载
|
|
|
-│
|
|
|
-└── subagents/ # Sub-agent
|
|
|
+└── {trace_id}@explore-{timestamp}-001/ # 子 Trace
|
|
|
+ └── ...
|
|
|
+```
|
|
|
+
|
|
|
+**meta.json 示例**:
|
|
|
+```json
|
|
|
+{
|
|
|
+ "trace_id": "0415dc38-...",
|
|
|
+ "mode": "agent",
|
|
|
+ "task": "分析代码结构",
|
|
|
+ "agent_type": "default",
|
|
|
+ "status": "running",
|
|
|
+ "model": "google/gemini-2.5-flash",
|
|
|
+ "tools": [...],
|
|
|
+ "llm_params": {"temperature": 0.3},
|
|
|
+ "context": {},
|
|
|
+ "current_goal_id": "3"
|
|
|
+}
|
|
|
```
|
|
|
|
|
|
---
|
|
|
@@ -524,78 +591,23 @@ agent/
|
|
|
|
|
|
**核心决策**:
|
|
|
|
|
|
-1. **Skills 通过工具加载**(vs 预先注入)
|
|
|
- - 按需加载,Agent 自主选择
|
|
|
- - 参考 OpenCode 和 Claude API 文档
|
|
|
+1. **所有 Agent 都是 Trace** - 主 Agent、子 Agent、人类协助统一为 Trace,通过 `parent_trace_id` 和 `spawn_tool` 区分
|
|
|
|
|
|
-2. **Skills 用文件系统**(vs 数据库)
|
|
|
- - 易于编辑(Markdown)
|
|
|
- - 版本控制(Git)
|
|
|
- - 零依赖
|
|
|
+2. **trace/ 模块统一管理执行状态** - 合并原 execution/ 和 goal/,包含计划管理和 Agent 内部控制工具
|
|
|
|
|
|
-3. **Experiences 用数据库**(vs 文件)
|
|
|
- - 需要向量检索
|
|
|
- - 需要统计分析
|
|
|
- - 数量大,动态更新
|
|
|
+3. **tools/ 专注外部交互** - 文件、命令、网络、浏览器等与外部世界的交互
|
|
|
|
|
|
-4. **Context 管理:GoalTree + Message + DAG 可视化**
|
|
|
- - GoalTree 嵌套 JSON 注入 LLM,Messages 扁平存储
|
|
|
- - DAG 可视化从 GoalTree + Messages 派生
|
|
|
- - 详见 [`docs/context-management.md`](./context-management.md)
|
|
|
+4. **Agent 预设替代 Sub-Agent 配置** - 通过 `core/presets.py` 定义不同类型 Agent 的工具权限和参数
|
|
|
|
|
|
---
|
|
|
|
|
|
-## Debug 工具
|
|
|
-
|
|
|
-开发调试时可通过 API 查看 DAG 可视化:
|
|
|
-
|
|
|
-```bash
|
|
|
-# 启动 API Server
|
|
|
-python api_server.py
|
|
|
-
|
|
|
-# 查看 DAG
|
|
|
-curl http://localhost:8000/api/traces/{trace_id}/dag
|
|
|
-```
|
|
|
-
|
|
|
-**实现**:`agent/execution/api.py`
|
|
|
-
|
|
|
----
|
|
|
-
|
|
|
-## 测试
|
|
|
-
|
|
|
-详见 [测试指南](./testing.md)
|
|
|
-
|
|
|
-**测试分层**:
|
|
|
-- **单元测试**:Agent 定义、工具系统、Trace 模型
|
|
|
-- **集成测试**:Sub-Agent、Trace 存储、多模块协作
|
|
|
-- **E2E 测试**:真实 LLM 调用(需要 API Key)
|
|
|
-
|
|
|
-**运行测试**:
|
|
|
-```bash
|
|
|
-# 单元测试
|
|
|
-pytest tests/ -v -m "not e2e"
|
|
|
-
|
|
|
-# 覆盖率
|
|
|
-pytest --cov=agent tests/ -m "not e2e"
|
|
|
-
|
|
|
-# E2E 测试(可选)
|
|
|
-GEMINI_API_KEY=xxx pytest tests/e2e/ -v -m e2e
|
|
|
-```
|
|
|
-
|
|
|
----
|
|
|
+## 相关文档
|
|
|
|
|
|
-## 核心概念速查
|
|
|
-
|
|
|
-| 概念 | 定义 | 存储 | 实现 |
|
|
|
-|------|------|------|------|
|
|
|
-| **Trace** | 一次任务执行 | 文件系统(JSON) | `execution/models.py` |
|
|
|
-| **Message** | 执行消息(对应 LLM 消息) | 文件系统(JSON) | `execution/models.py` |
|
|
|
-| **GoalTree** | 层级执行计划 | goal.json | `goal/models.py` |
|
|
|
-| **Goal** | 计划中的目标节点 | 嵌套在 GoalTree 中 | `goal/models.py` |
|
|
|
-| **Sub-Agent** | 专门化的子代理 | 独立 Trace | `tools/builtin/task.py` |
|
|
|
-| **AgentDefinition** | Agent 类型定义 | 配置文件/代码 | `subagents/` |
|
|
|
-| **Skill** | 能力描述(Markdown) | 文件系统 | `memory/skill_loader.py` |
|
|
|
-| **Experience** | 经验规则(条件+规则) | 数据库 + 向量 | `memory/stores.py` |
|
|
|
-| **Tool** | 可调用的函数 | 内存(注册表) | `tools/registry.py` |
|
|
|
-| **Agent Loop** | ReAct 循环 | - | `core/runner.py` |
|
|
|
-| **Doom Loop** | 无限循环检测 | - | `core/runner.py` |
|
|
|
+| 文档 | 内容 |
|
|
|
+|-----|------|
|
|
|
+| [Context 管理](./context-management.md) | Goals、压缩、Plan 注入策略 |
|
|
|
+| [工具系统](./tools.md) | 工具定义、注册、双层记忆 |
|
|
|
+| [Skills 指南](./skills.md) | Skill 分类、编写、加载 |
|
|
|
+| [多模态支持](./multimodal.md) | 图片、PDF 处理 |
|
|
|
+| [设计决策](./decisions.md) | 架构决策记录 |
|
|
|
+| [测试指南](./testing.md) | 测试策略和命令 |
|