Skip to content

Commit 0176b10

Browse files
authored
docs: update graph docs on subagents (#428)
1 parent 52e001f commit 0176b10

File tree

2 files changed

+66
-26
lines changed

2 files changed

+66
-26
lines changed

docs/mkdocs/en/graph.md

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,17 @@ GraphAgent implements the `agent.Agent` interface and can:
2828

2929
- **Act as Independent Agent**: Execute directly through Runner
3030
- **Act as SubAgent**: Be used as a sub-agent by other Agents (such as LLMAgent)
31-
- **No SubAgent Support**: GraphAgent itself does not support sub-agents, focusing on workflow execution
31+
- **Host SubAgents**: Register child agents via `graphagent.WithSubAgents` and invoke them through `AddAgentNode`
3232

33-
This design allows GraphAgent to flexibly integrate into complex multi-Agent systems.
33+
This design lets GraphAgent plug into other agents while orchestrating its own specialized sub-agents.
3434

3535
### Key Features
3636

3737
- **Type-safe state management**: Use Schema to define state structure, support custom Reducers
3838
- **Conditional routing**: Dynamically select execution paths based on state
3939
- **LLM node integration**: Built-in support for large language models
4040
- **Tool nodes**: Support function calls and external tool integration
41+
- **Agent nodes**: Delegate parts of the workflow to registered sub-agents
4142
- **Streaming execution**: Support real-time event streams and progress tracking
4243
- **Concurrency safety**: Thread-safe graph execution
4344
- **Checkpoint-based Time Travel**: Navigate through execution history and restore previous states
@@ -452,21 +453,40 @@ GraphAgent supports various configuration options:
452453

453454
```go
454455
// Multiple options can be used when creating GraphAgent.
455-
graphAgent, err := graphagent.New("workflow-name", compiledGraph,
456+
graphAgent, err := graphagent.New(
457+
"workflow-name",
458+
compiledGraph,
456459
graphagent.WithDescription("Workflow description"),
457460
graphagent.WithInitialState(graph.State{
458461
"initial_data": "Initial data",
459462
}),
460-
graphagent.WithChannelBufferSize(1024),
461-
graphagent.WithModelCallbacks(&model.Callbacks{
462-
// Model callback configuration.
463-
}),
464-
graphagent.WithToolCallbacks(&tool.Callbacks{
465-
// Tool callback configuration.
463+
graphagent.WithChannelBufferSize(1024), // Tune event buffer size
464+
graphagent.WithCheckpointSaver(memorySaver), // Persist checkpoints if needed
465+
graphagent.WithSubAgents([]agent.Agent{subAgent}), // Register sub-agents by name
466+
graphagent.WithAgentCallbacks(&agent.Callbacks{
467+
// Agent-level callbacks.
466468
}),
467469
)
468470
```
469471

472+
> Model/tool callbacks are configured per node, e.g. `AddLLMNode(..., graph.WithModelCallbacks(...))`
473+
> or `AddToolsNode(..., graph.WithToolCallbacks(...))`.
474+
475+
Once sub-agents are registered you can delegate within the graph via agent nodes:
476+
477+
```go
478+
// Assume subAgent.Info().Name == "assistant"
479+
stateGraph.AddAgentNode("assistant",
480+
graph.WithName("Delegate to assistant agent"),
481+
graph.WithDescription("Invoke the pre-registered assistant agent"),
482+
)
483+
484+
// During execution the GraphAgent looks up a sub-agent with the same name and runs it
485+
```
486+
487+
> The agent node uses its ID for the lookup, so keep `AddAgentNode("assistant")`
488+
> aligned with `subAgent.Info().Name == "assistant"`.
489+
470490
### 4. Conditional Routing
471491

472492
```go
@@ -1688,9 +1708,9 @@ func main() {
16881708
**Key Features**:
16891709

16901710
- GraphAgent implements the `agent.Agent` interface and can be used as a sub-agent by other Agents
1691-
- Coordinator Agents can delegate tasks to GraphAgent through the `transfer_to_agent` tool
1692-
- GraphAgent focuses on workflow execution and does not support its own sub-agents
1693-
- This design enables seamless integration of complex workflows with multi-Agent systems
1711+
- Coordinator Agents can delegate tasks to GraphAgent through the `transfer_to_agent` tool or custom logic
1712+
- GraphAgent can in turn delegate to registered sub-agents through `graphagent.WithSubAgents` + `AddAgentNode`
1713+
- This design enables seamless, bi-directional integration between complex workflows and multi-Agent systems
16941714

16951715
## Troubleshooting
16961716

@@ -1730,8 +1750,8 @@ The Graph package provides a powerful and flexible workflow orchestration system
17301750

17311751
- GraphAgent implements the `agent.Agent` interface
17321752
- Can be used as a sub-agent of other Agents
1753+
- Can also orchestrate other agents via `graphagent.WithSubAgents` and `AddAgentNode`
17331754
- Supports complex multi-Agent collaboration scenarios
1734-
- Focuses on workflow execution, does not support its own sub-agents
17351755

17361756
**Best Practices**:
17371757

docs/mkdocs/zh/graph.md

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,17 @@ GraphAgent 实现了 `agent.Agent` 接口,可以:
2828

2929
- **作为独立 Agent**:通过 Runner 直接执行
3030
- **作为 SubAgent**:被其他 Agent(如 LLMAgent)作为子 Agent 使用
31-
- **不支持 SubAgent**GraphAgent 本身不支持子 Agent,专注于工作流执行
31+
- **挂载 SubAgent**通过 `graphagent.WithSubAgents` 配置子 Agent,并在图中使用 `AddAgentNode` 委托执行
3232

33-
这种设计使得 GraphAgent 可以灵活地集成到复杂的多 Agent 系统中
33+
这种设计使得 GraphAgent 既能接入其他 Agent,也能在自身工作流中灵活调度子 Agent
3434

3535
### 主要特性
3636

3737
- **类型安全的状态管理**:使用 Schema 定义状态结构,支持自定义 Reducer
3838
- **条件路由**:基于状态动态选择执行路径
3939
- **LLM 节点集成**:内置对大型语言模型的支持
4040
- **工具节点**:支持函数调用和外部工具集成
41+
- **Agent 节点**:通过子 Agent 将其他 Agent 融入图中
4142
- **流式执行**:支持实时事件流和进度跟踪
4243
- **并发安全**:线程安全的图执行
4344
- **基于检查点的时间旅行**:浏览执行历史并恢复之前的状态
@@ -500,21 +501,40 @@ GraphAgent 支持多种配置选项:
500501

501502
```go
502503
// 创建 GraphAgent 时可以使用多种选项
503-
graphAgent, err := graphagent.New("workflow-name", compiledGraph,
504+
graphAgent, err := graphagent.New(
505+
"workflow-name",
506+
compiledGraph,
504507
graphagent.WithDescription("工作流描述"),
505508
graphagent.WithInitialState(graph.State{
506509
"initial_data": "初始数据",
507510
}),
508-
graphagent.WithChannelBufferSize(1024),
509-
graphagent.WithModelCallbacks(&model.Callbacks{
510-
// 模型回调配置
511-
}),
512-
graphagent.WithToolCallbacks(&tool.Callbacks{
513-
// 工具回调配置
511+
graphagent.WithChannelBufferSize(1024), // 调整事件通道缓冲区
512+
graphagent.WithCheckpointSaver(memorySaver), // 使用持久化检查点
513+
graphagent.WithSubAgents([]agent.Agent{subAgent}), // 配置子 Agent
514+
graphagent.WithAgentCallbacks(&agent.Callbacks{
515+
// Agent 级回调配置
514516
}),
515517
)
516518
```
517519

520+
> 模型/工具回调需要在节点级配置,例如 `AddLLMNode(..., graph.WithModelCallbacks(...))`
521+
> `AddToolsNode(..., graph.WithToolCallbacks(...))`
522+
523+
配置了子 Agent 后,可以在图中使用 Agent 节点委托执行:
524+
525+
```go
526+
// 假设 subAgent.Info().Name == "assistant"
527+
stateGraph.AddAgentNode("assistant",
528+
graph.WithName("子 Agent 调度"),
529+
graph.WithDescription("调用预先注册的 assistant Agent"),
530+
)
531+
532+
// 执行时 GraphAgent 会在自身的 SubAgents 中查找同名 Agent 并发起调用
533+
```
534+
535+
> Agent 节点会以节点 ID 作为查找键,因此需确保 `AddAgentNode("assistant")`
536+
> `subAgent.Info().Name == "assistant"` 一致。
537+
518538
### 4. 条件路由
519539

520540
```go
@@ -1742,9 +1762,9 @@ func main() {
17421762
**关键特点**
17431763

17441764
- GraphAgent 实现了 `agent.Agent` 接口,可以被其他 Agent 作为子 Agent 使用
1745-
- 协调器 Agent 可以通过 `transfer_to_agent` 工具委托任务给 GraphAgent
1746-
- GraphAgent 专注于工作流执行,不支持自己的子 Agent
1747-
- 这种设计实现了复杂工作流与多 Agent 系统的无缝集成
1765+
- 协调器 Agent 可以通过 `transfer_to_agent` 工具或自定义逻辑委托任务给 GraphAgent
1766+
- GraphAgent 自身也可以通过 `graphagent.WithSubAgents` + `AddAgentNode` 在图内调度其他 Agent
1767+
- 这种设计实现了复杂工作流与多 Agent 系统的双向集成
17481768

17491769
## 语义与边界:节点级恢复与副作用幂等
17501770

@@ -1799,8 +1819,8 @@ Graph 包提供了一个强大而灵活的工作流编排系统,特别适合
17991819

18001820
- GraphAgent 实现了 `agent.Agent` 接口
18011821
- 可以作为其他 Agent 的子 Agent 使用
1822+
- 也可以通过 `graphagent.WithSubAgents``AddAgentNode` 调度其他 Agent
18021823
- 支持复杂的多 Agent 协作场景
1803-
- 专注于工作流执行,不支持自己的子 Agent
18041824

18051825
**最佳实践**
18061826

0 commit comments

Comments
 (0)