|
@@ -134,7 +134,7 @@ agent/
|
|
|
|
|
|
|
|
跨 Provider 续跑时,出方向转换前检测历史中的 tool_call_id 格式,不兼容时统一重写为目标格式(保持 tool_use / tool_result 配对一致)。同格式跳过,零开销。Gemini 按 function name 匹配,无需重写。
|
|
跨 Provider 续跑时,出方向转换前检测历史中的 tool_call_id 格式,不兼容时统一重写为目标格式(保持 tool_use / tool_result 配对一致)。同格式跳过,零开销。Gemini 按 function name 匹配,无需重写。
|
|
|
|
|
|
|
|
-**实现**:`agent/llm/openrouter.py:_normalize_tool_call_ids`, `agent/llm/yescode.py:_normalize_tool_call_ids`
|
|
|
|
|
|
|
+**实现**:`cyber_agent/llm/openrouter.py:_normalize_tool_call_ids`, `cyber_agent/llm/yescode.py:_normalize_tool_call_ids`
|
|
|
|
|
|
|
|
---
|
|
---
|
|
|
|
|
|
|
@@ -183,7 +183,7 @@ class RunConfig:
|
|
|
after_sequence: Optional[int] = None # 从哪条消息后续跑(message sequence)
|
|
after_sequence: Optional[int] = None # 从哪条消息后续跑(message sequence)
|
|
|
```
|
|
```
|
|
|
|
|
|
|
|
-**实现**:`agent/core/runner.py:RunConfig`
|
|
|
|
|
|
|
+**实现**:`cyber_agent/core/runner.py:RunConfig`
|
|
|
|
|
|
|
|
### 三种运行模式
|
|
### 三种运行模式
|
|
|
|
|
|
|
@@ -233,7 +233,7 @@ async def run(messages: List[Dict], config: RunConfig = None) -> AsyncIterator[U
|
|
|
yield trace
|
|
yield trace
|
|
|
```
|
|
```
|
|
|
|
|
|
|
|
-**实现**:`agent/core/runner.py:AgentRunner`
|
|
|
|
|
|
|
+**实现**:`cyber_agent/core/runner.py:AgentRunner`
|
|
|
|
|
|
|
|
### 回溯(Rewind)
|
|
### 回溯(Rewind)
|
|
|
|
|
|
|
@@ -304,7 +304,7 @@ await runner.stop(trace_id)
|
|
|
|
|
|
|
|
agent 工具的合成结果对齐正常返回值格式(含 `sub_trace_id` 字段),主 Agent 可直接使用 `agent(task=..., continue_from=sub_trace_id)` 续跑被中断的子 Agent。合成消息持久化存储,确保幂等。
|
|
agent 工具的合成结果对齐正常返回值格式(含 `sub_trace_id` 字段),主 Agent 可直接使用 `agent(task=..., continue_from=sub_trace_id)` 续跑被中断的子 Agent。合成消息持久化存储,确保幂等。
|
|
|
|
|
|
|
|
-**实现**:`agent/core/runner.py:AgentRunner._heal_orphaned_tool_calls`
|
|
|
|
|
|
|
+**实现**:`cyber_agent/core/runner.py:AgentRunner._heal_orphaned_tool_calls`
|
|
|
|
|
|
|
|
- `run(messages, config)`:**核心方法**,流式返回 `AsyncIterator[Union[Trace, Message]]`
|
|
- `run(messages, config)`:**核心方法**,流式返回 `AsyncIterator[Union[Trace, Message]]`
|
|
|
- `run_result(messages, config, on_event=None)`:便利方法,内部消费 `run()`,返回结构化结果。`on_event` 回调可实时接收每个 Trace/Message 事件(用于调试时输出子 Agent 执行过程)。主要用于 `agent`/`evaluate` 工具内部
|
|
- `run_result(messages, config, on_event=None)`:便利方法,内部消费 `run()`,返回结构化结果。`on_event` 回调可实时接收每个 Trace/Message 事件(用于调试时输出子 Agent 执行过程)。主要用于 `agent`/`evaluate` 工具内部
|
|
@@ -321,7 +321,7 @@ agent 工具的合成结果对齐正常返回值格式(含 `sub_trace_id` 字
|
|
|
| GET | `/api/traces/running` | 列出正在运行的 Trace |
|
|
| GET | `/api/traces/running` | 列出正在运行的 Trace |
|
|
|
| WS | `/api/traces/{id}/watch` | 实时事件推送 |
|
|
| WS | `/api/traces/{id}/watch` | 实时事件推送 |
|
|
|
|
|
|
|
|
-**实现**:`agent/trace/api.py`, `agent/trace/websocket.py`
|
|
|
|
|
|
|
+**实现**:`cyber_agent/trace/api.py`, `cyber_agent/trace/websocket.py`
|
|
|
|
|
|
|
|
#### 控制端点
|
|
#### 控制端点
|
|
|
|
|
|
|
@@ -366,7 +366,7 @@ curl -X POST http://localhost:8000/api/traces/{trace_id}/compact
|
|
|
|
|
|
|
|
响应立即返回 `{"trace_id": "...", "status": "started"}`,通过 `WS /api/traces/{trace_id}/watch` 监听实时事件。
|
|
响应立即返回 `{"trace_id": "...", "status": "started"}`,通过 `WS /api/traces/{trace_id}/watch` 监听实时事件。
|
|
|
|
|
|
|
|
-**实现**:`agent/trace/run_api.py`
|
|
|
|
|
|
|
+**实现**:`cyber_agent/trace/run_api.py`
|
|
|
|
|
|
|
|
---
|
|
---
|
|
|
|
|
|
|
@@ -428,7 +428,7 @@ class Trace:
|
|
|
completed_at: Optional[datetime] = None
|
|
completed_at: Optional[datetime] = None
|
|
|
```
|
|
```
|
|
|
|
|
|
|
|
-**实现**:`agent/trace/models.py`
|
|
|
|
|
|
|
+**实现**:`cyber_agent/trace/models.py`
|
|
|
|
|
|
|
|
### Goal(目标节点)
|
|
### Goal(目标节点)
|
|
|
|
|
|
|
@@ -479,7 +479,7 @@ class Goal:
|
|
|
- `done` - 完成当前目标(附带 summary)
|
|
- `done` - 完成当前目标(附带 summary)
|
|
|
- `abandon` - 放弃当前目标(附带原因)
|
|
- `abandon` - 放弃当前目标(附带原因)
|
|
|
|
|
|
|
|
-**实现**:`agent/trace/goal_models.py`, `agent/trace/goal_tool.py`
|
|
|
|
|
|
|
+**实现**:`cyber_agent/trace/goal_models.py`, `cyber_agent/trace/goal_tool.py`
|
|
|
|
|
|
|
|
### Message(执行消息)
|
|
### Message(执行消息)
|
|
|
|
|
|
|
@@ -541,7 +541,7 @@ Message 提供格式转换方法:
|
|
|
- `branch_type`: "compression" | "reflection" | None(主路径)
|
|
- `branch_type`: "compression" | "reflection" | None(主路径)
|
|
|
- `branch_id`: 同一侧分支的消息共享 branch_id
|
|
- `branch_id`: 同一侧分支的消息共享 branch_id
|
|
|
|
|
|
|
|
-**实现**:`agent/trace/models.py`
|
|
|
|
|
|
|
+**实现**:`cyber_agent/trace/models.py`
|
|
|
|
|
|
|
|
---
|
|
---
|
|
|
|
|
|
|
@@ -588,9 +588,9 @@ AGENT_PRESETS = {
|
|
|
}
|
|
}
|
|
|
```
|
|
```
|
|
|
|
|
|
|
|
-**实现**:`agent/core/presets.py`
|
|
|
|
|
|
|
+**实现**:`cyber_agent/core/presets.py`
|
|
|
|
|
|
|
|
-**System Prompt 构建优先级**(`agent/core/runner.py:_build_system_prompt`):
|
|
|
|
|
|
|
+**System Prompt 构建优先级**(`cyber_agent/core/runner.py:_build_system_prompt`):
|
|
|
|
|
|
|
|
1. 消息中已有 system → 使用消息中的
|
|
1. 消息中已有 system → 使用消息中的
|
|
|
2. `config.system_prompt` 显式指定 → 使用 config
|
|
2. `config.system_prompt` 显式指定 → 使用 config
|
|
@@ -615,7 +615,7 @@ AGENT_PRESETS = {
|
|
|
**加载方式**:
|
|
**加载方式**:
|
|
|
|
|
|
|
|
```python
|
|
```python
|
|
|
-from agent.core.presets import load_presets_from_json
|
|
|
|
|
|
|
+from cyber_agent.core.presets import load_presets_from_json
|
|
|
|
|
|
|
|
load_presets_from_json("examples/production/presets.json")
|
|
load_presets_from_json("examples/production/presets.json")
|
|
|
```
|
|
```
|
|
@@ -660,7 +660,7 @@ result2 = agent(
|
|
|
|
|
|
|
|
**实现**:`HybridTraceStore` 自动路由到本地或远程存储,远程访问通过 HTTP API 实现。
|
|
**实现**:`HybridTraceStore` 自动路由到本地或远程存储,远程访问通过 HTTP API 实现。
|
|
|
|
|
|
|
|
-**实现位置**:`agent/trace/hybrid_store.py`(规划中)
|
|
|
|
|
|
|
+**实现位置**:`cyber_agent/trace/hybrid_store.py`(规划中)
|
|
|
|
|
|
|
|
### agent 工具
|
|
### agent 工具
|
|
|
|
|
|
|
@@ -720,7 +720,7 @@ async def evaluate(
|
|
|
|
|
|
|
|
### 消息类型别名
|
|
### 消息类型别名
|
|
|
|
|
|
|
|
-定义在 `agent/trace/models.py`,用于工具参数和 runner/LLM API 接口:
|
|
|
|
|
|
|
+定义在 `cyber_agent/trace/models.py`,用于工具参数和 runner/LLM API 接口:
|
|
|
|
|
|
|
|
```python
|
|
```python
|
|
|
ChatMessage = Dict[str, Any] # 单条 OpenAI 格式消息
|
|
ChatMessage = Dict[str, Any] # 单条 OpenAI 格式消息
|
|
@@ -728,9 +728,9 @@ Messages = List[ChatMessage] # 消息列表
|
|
|
MessageContent = Union[str, List[Dict[str, str]]] # content 字段(文本或多模态)
|
|
MessageContent = Union[str, List[Dict[str, str]]] # content 字段(文本或多模态)
|
|
|
```
|
|
```
|
|
|
|
|
|
|
|
-**实现位置**:`agent/tools/builtin/subagent.py`
|
|
|
|
|
|
|
+**实现位置**:`cyber_agent/tools/builtin/subagent.py`
|
|
|
|
|
|
|
|
-**详细文档**:[工具系统 - Agent/Evaluate 工具](../agent/docs/tools.md#agent-工具)
|
|
|
|
|
|
|
+**详细文档**:[工具系统 - Agent/Evaluate 工具](../cyber_agent/docs/tools.md#agent-工具)
|
|
|
|
|
|
|
|
### ask_human 工具
|
|
### ask_human 工具
|
|
|
|
|
|
|
@@ -787,7 +787,7 @@ MessageContent = Union[str, List[Dict[str, str]]] # content 字段(文本
|
|
|
|
|
|
|
|
**持久联系人/Agent**:通过工具按需查询(如 `feishu_get_contact_list`),不随任务注入。
|
|
**持久联系人/Agent**:通过工具按需查询(如 `feishu_get_contact_list`),不随任务注入。
|
|
|
|
|
|
|
|
-**实现**:`agent/core/runner.py:AgentRunner._build_context_injection`, `agent/tools/builtin/subagent.py`
|
|
|
|
|
|
|
+**实现**:`cyber_agent/core/runner.py:AgentRunner._build_context_injection`, `cyber_agent/tools/builtin/subagent.py`
|
|
|
|
|
|
|
|
---
|
|
---
|
|
|
|
|
|
|
@@ -856,7 +856,7 @@ runner = AgentRunner(
|
|
|
**Runner 修改**:
|
|
**Runner 修改**:
|
|
|
|
|
|
|
|
```python
|
|
```python
|
|
|
-# agent/core/runner.py
|
|
|
|
|
|
|
+# cyber_agent/core/runner.py
|
|
|
|
|
|
|
|
class AgentRunner:
|
|
class AgentRunner:
|
|
|
def __init__(
|
|
def __init__(
|
|
@@ -899,12 +899,12 @@ class AgentRunner:
|
|
|
return "\n\n".join(parts)
|
|
return "\n\n".join(parts)
|
|
|
```
|
|
```
|
|
|
|
|
|
|
|
-**实现位置**:`agent/core/runner.py:AgentRunner._build_context_injection`(待实现)
|
|
|
|
|
|
|
+**实现位置**:`cyber_agent/core/runner.py:AgentRunner._build_context_injection`(待实现)
|
|
|
|
|
|
|
|
### 示例:A2A IM Hook
|
|
### 示例:A2A IM Hook
|
|
|
|
|
|
|
|
```python
|
|
```python
|
|
|
-# agent/tools/builtin/a2a_im.py
|
|
|
|
|
|
|
+# cyber_agent/tools/builtin/a2a_im.py
|
|
|
|
|
|
|
|
class A2AMessageQueue:
|
|
class A2AMessageQueue:
|
|
|
"""A2A IM 消息队列"""
|
|
"""A2A IM 消息队列"""
|
|
@@ -980,14 +980,14 @@ async def check_messages(ctx: ToolContext) -> ToolResult:
|
|
|
)
|
|
)
|
|
|
```
|
|
```
|
|
|
|
|
|
|
|
-**实现位置**:`agent/tools/builtin/a2a_im.py`(待实现)
|
|
|
|
|
|
|
+**实现位置**:`cyber_agent/tools/builtin/a2a_im.py`(待实现)
|
|
|
|
|
|
|
|
### 配置示例
|
|
### 配置示例
|
|
|
|
|
|
|
|
```python
|
|
```python
|
|
|
# api_server.py
|
|
# api_server.py
|
|
|
|
|
|
|
|
-from agent.tools.builtin.a2a_im import (
|
|
|
|
|
|
|
+from cyber_agent.tools.builtin.a2a_im import (
|
|
|
A2AMessageQueue,
|
|
A2AMessageQueue,
|
|
|
create_a2a_context_hook,
|
|
create_a2a_context_hook,
|
|
|
check_messages
|
|
check_messages
|
|
@@ -1111,7 +1111,7 @@ def create_timer_hook(timer):
|
|
|
|
|
|
|
|
**持久联系人/Agent**:通过工具按需查询(如 `feishu_get_contact_list`),不随任务注入。
|
|
**持久联系人/Agent**:通过工具按需查询(如 `feishu_get_contact_list`),不随任务注入。
|
|
|
|
|
|
|
|
-**实现**:`agent/core/runner.py:AgentRunner._build_context_injection`, `agent/tools/builtin/subagent.py`
|
|
|
|
|
|
|
+**实现**:`cyber_agent/core/runner.py:AgentRunner._build_context_injection`, `cyber_agent/tools/builtin/subagent.py`
|
|
|
|
|
|
|
|
---
|
|
---
|
|
|
|
|
|
|
@@ -1157,7 +1157,7 @@ ToolResult(
|
|
|
)
|
|
)
|
|
|
```
|
|
```
|
|
|
|
|
|
|
|
-**详细文档**:[工具系统](../agent/docs/tools.md)
|
|
|
|
|
|
|
+**详细文档**:[工具系统](../cyber_agent/docs/tools.md)
|
|
|
|
|
|
|
|
---
|
|
---
|
|
|
|
|
|
|
@@ -1174,7 +1174,7 @@ ToolResult(
|
|
|
### 目录结构
|
|
### 目录结构
|
|
|
|
|
|
|
|
```
|
|
```
|
|
|
-agent/skill/skills/ # 内置 Skills(始终加载)
|
|
|
|
|
|
|
+cyber_agent/skill/skills/ # 内置 Skills(始终加载)
|
|
|
├── planning.md # 计划与 Goal 工具使用
|
|
├── planning.md # 计划与 Goal 工具使用
|
|
|
├── research.md # 搜索与内容研究
|
|
├── research.md # 搜索与内容研究
|
|
|
└── browser.md # 浏览器自动化
|
|
└── browser.md # 浏览器自动化
|
|
@@ -1196,9 +1196,9 @@ agent/skill/skills/ # 内置 Skills(始终加载)
|
|
|
agent(task="...", agent_type="deconstruct", skills=["planning", "deconstruct"])
|
|
agent(task="...", agent_type="deconstruct", skills=["planning", "deconstruct"])
|
|
|
```
|
|
```
|
|
|
|
|
|
|
|
-**实现**:`agent/skill/skill_loader.py`
|
|
|
|
|
|
|
+**实现**:`cyber_agent/skill/skill_loader.py`
|
|
|
|
|
|
|
|
-**详细文档**:[Skills 使用指南](../agent/docs/skills.md)
|
|
|
|
|
|
|
+**详细文档**:[Skills 使用指南](../cyber_agent/docs/skills.md)
|
|
|
|
|
|
|
|
---
|
|
---
|
|
|
|
|
|
|
@@ -1225,7 +1225,7 @@ agent(task="...", agent_type="deconstruct", skills=["planning", "deconstruct"])
|
|
|
2. **多轮推理**:LLM 可调用 `knowledge_search`、`knowledge_save`、`resource_save` 等工具
|
|
2. **多轮推理**:LLM 可调用 `knowledge_search`、`knowledge_save`、`resource_save` 等工具
|
|
|
3. **结构化保存**:通过 `knowledge_save` 工具将知识保存到 KnowHub
|
|
3. **结构化保存**:通过 `knowledge_save` 工具将知识保存到 KnowHub
|
|
|
|
|
|
|
|
-**实现**:`agent/trace/run_api.py:reflect_trace`
|
|
|
|
|
|
|
+**实现**:`cyber_agent/trace/run_api.py:reflect_trace`
|
|
|
|
|
|
|
|
### 知识工具
|
|
### 知识工具
|
|
|
|
|
|
|
@@ -1267,7 +1267,7 @@ async def resource_save(
|
|
|
“””保存资源文件到知识库”””
|
|
“””保存资源文件到知识库”””
|
|
|
```
|
|
```
|
|
|
|
|
|
|
|
-**实现**:`agent/tools/builtin/knowledge.py`
|
|
|
|
|
|
|
+**实现**:`cyber_agent/tools/builtin/knowledge.py`
|
|
|
|
|
|
|
|
---
|
|
---
|
|
|
|
|
|
|
@@ -1292,7 +1292,7 @@ Context 管理涵盖注入(向模型上下文添加信息)和压缩(在 to
|
|
|
- **Level 1**:Goal 完成压缩(确定性,零 LLM 成本)— 保留 goal 工具消息,移除执行细节
|
|
- **Level 1**:Goal 完成压缩(确定性,零 LLM 成本)— 保留 goal 工具消息,移除执行细节
|
|
|
- **Level 2**:LLM 摘要(Level 1 后仍超限时触发)— 通过侧分支生成 summary 重建 history
|
|
- **Level 2**:LLM 摘要(Level 1 后仍超限时触发)— 通过侧分支生成 summary 重建 history
|
|
|
|
|
|
|
|
-**实现**:`agent/trace/compaction.py`, `agent/core/runner.py:_manage_context_usage`
|
|
|
|
|
|
|
+**实现**:`cyber_agent/trace/compaction.py`, `cyber_agent/core/runner.py:_manage_context_usage`
|
|
|
|
|
|
|
|
**详细设计**:[Context 管理](./context-management.md)
|
|
**详细设计**:[Context 管理](./context-management.md)
|
|
|
|
|
|
|
@@ -1316,10 +1316,10 @@ class TraceStore(Protocol):
|
|
|
|
|
|
|
|
**实现**:
|
|
**实现**:
|
|
|
|
|
|
|
|
-- 协议定义:`agent/trace/protocols.py`
|
|
|
|
|
-- 本地存储:`agent/trace/store.py:FileSystemTraceStore`
|
|
|
|
|
-- 远程存储:`agent/trace/remote_store.py:RemoteTraceStore`(规划中)
|
|
|
|
|
-- 混合存储:`agent/trace/hybrid_store.py:HybridTraceStore`(规划中)
|
|
|
|
|
|
|
+- 协议定义:`cyber_agent/trace/protocols.py`
|
|
|
|
|
+- 本地存储:`cyber_agent/trace/store.py:FileSystemTraceStore`
|
|
|
|
|
+- 远程存储:`cyber_agent/trace/remote_store.py:RemoteTraceStore`(规划中)
|
|
|
|
|
+- 混合存储:`cyber_agent/trace/hybrid_store.py:HybridTraceStore`(规划中)
|
|
|
|
|
|
|
|
### 跨设备存储
|
|
### 跨设备存储
|
|
|
|
|
|
|
@@ -1338,7 +1338,7 @@ class TraceStore(Protocol):
|
|
|
|
|
|
|
|
**认证**:通过 API Key 认证,配置在 `config/agents.yaml`。
|
|
**认证**:通过 API Key 认证,配置在 `config/agents.yaml`。
|
|
|
|
|
|
|
|
-**实现位置**:`agent/trace/hybrid_store.py`, `agent/trace/remote_store.py`(规划中)
|
|
|
|
|
|
|
+**实现位置**:`cyber_agent/trace/hybrid_store.py`, `cyber_agent/trace/remote_store.py`(规划中)
|
|
|
|
|
|
|
|
### 存储结构
|
|
### 存储结构
|
|
|
|
|
|
|
@@ -1413,12 +1413,12 @@ class TraceStore(Protocol):
|
|
|
| 文档 | 内容 |
|
|
| 文档 | 内容 |
|
|
|
| --------------------------------------------------------------- | ------------------------------- |
|
|
| --------------------------------------------------------------- | ------------------------------- |
|
|
|
| [Context 管理](./context-management.md) | 注入机制、压缩策略、Skill 指定注入 |
|
|
| [Context 管理](./context-management.md) | 注入机制、压缩策略、Skill 指定注入 |
|
|
|
-| [工具系统](../agent/docs/tools.md) | 工具定义、注册、双层记忆 |
|
|
|
|
|
-| [Skills 指南](../agent/docs/skills.md) | Skill 分类、编写、加载 |
|
|
|
|
|
-| [多模态支持](../agent/docs/multimodal.md) | 图片、PDF 处理 |
|
|
|
|
|
|
|
+| [工具系统](../cyber_agent/docs/tools.md) | 工具定义、注册、双层记忆 |
|
|
|
|
|
+| [Skills 指南](../cyber_agent/docs/skills.md) | Skill 分类、编写、加载 |
|
|
|
|
|
+| [多模态支持](../cyber_agent/docs/multimodal.md) | 图片、PDF 处理 |
|
|
|
| [知识管理](./knowledge.md) | 知识结构、检索、提取机制 |
|
|
| [知识管理](./knowledge.md) | 知识结构、检索、提取机制 |
|
|
|
| [Scope 设计](./scope-design.md) | 知识可见性和权限控制 |
|
|
| [Scope 设计](./scope-design.md) | 知识可见性和权限控制 |
|
|
|
-| [Agent 设计决策](../agent/docs/decisions.md) | Agent Core 架构决策记录 |
|
|
|
|
|
|
|
+| [Agent 设计决策](../cyber_agent/docs/decisions.md) | Agent Core 架构决策记录 |
|
|
|
| [Gateway 设计决策](../gateway/docs/decisions.md) | Gateway 架构决策记录 |
|
|
| [Gateway 设计决策](../gateway/docs/decisions.md) | Gateway 架构决策记录 |
|
|
|
| [组织级概览](../gateway/docs/enterprise/overview.md) | 组织级 Agent 系统架构和规划 |
|
|
| [组织级概览](../gateway/docs/enterprise/overview.md) | 组织级 Agent 系统架构和规划 |
|
|
|
| [Enterprise 实现](../gateway/docs/enterprise/implementation.md) | 认证、审计、多租户技术实现 |
|
|
| [Enterprise 实现](../gateway/docs/enterprise/implementation.md) | 认证、审计、多租户技术实现 |
|