Documentation
¶
Index ¶
- type GoTAgent
- func (g *GoTAgent) Invoke(ctx context.Context, input *agentcore.AgentInput) (*agentcore.AgentOutput, error)
- func (g *GoTAgent) RunGenerator(ctx context.Context, input *agentcore.AgentInput) agentcore.Generator[*agentcore.AgentOutput]
- func (g *GoTAgent) Stream(ctx context.Context, input *agentcore.AgentInput) (<-chan agentcore.StreamChunk[*agentcore.AgentOutput], error)
- func (g *GoTAgent) WithCallbacks(callbacks ...agentcore.Callback) agentcore.Runnable[*agentcore.AgentInput, *agentcore.AgentOutput]
- func (g *GoTAgent) WithConfig(config agentcore.RunnableConfig) agentcore.Runnable[*agentcore.AgentInput, *agentcore.AgentOutput]
- type GoTConfig
- type GraphNode
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type GoTAgent ¶
GoTAgent implements Graph-of-Thought reasoning pattern.
Graph-of-Thought (GoT) extends tree-based reasoning to a directed graph, allowing more complex dependencies and parallel exploration. This agent: - Builds a directed acyclic graph (DAG) of thoughts - Supports multiple dependency relationships - Enables parallel execution of independent nodes - Merges insights from different reasoning paths - Handles cyclic dependency detection
func NewGoTAgent ¶
NewGoTAgent creates a new Graph-of-Thought agent
func (*GoTAgent) Invoke ¶
func (g *GoTAgent) Invoke(ctx context.Context, input *agentcore.AgentInput) (*agentcore.AgentOutput, error)
Invoke executes the Graph-of-Thought reasoning
func (*GoTAgent) RunGenerator ¶ added in v0.2.0
func (g *GoTAgent) RunGenerator(ctx context.Context, input *agentcore.AgentInput) agentcore.Generator[*agentcore.AgentOutput]
RunGenerator 使用 Generator 模式执行 Graph-of-Thought(实验性功能)
相比 Stream,RunGenerator 提供零分配的流式执行,在每个主要阶段后 yield 中间结果:
- 构建思维图后 yield
- 图执行完成后 yield
- 合成最终答案后 yield
性能优势:
- 零内存分配(无 channel、goroutine 开销)
- 支持早期终止(用户可以在任意步骤 break)
- 更低延迟(无 channel 发送/接收开销)
使用示例:
for output, err := range agent.RunGenerator(ctx, input) {
if err != nil {
log.Error("step failed", err)
continue
}
stepType := output.Metadata["step_type"].(string)
if stepType == "graph_built" {
fmt.Printf("构建了 %d 个节点的图\n", output.Metadata["total_nodes"])
}
if output.Status == interfaces.StatusSuccess {
break // 完成
}
}
注意:此方法不触发 Agent 级别的回调(OnStart/OnFinish)
func (*GoTAgent) Stream ¶
func (g *GoTAgent) Stream(ctx context.Context, input *agentcore.AgentInput) (<-chan agentcore.StreamChunk[*agentcore.AgentOutput], error)
Stream executes Graph-of-Thought with streaming
func (*GoTAgent) WithCallbacks ¶
func (g *GoTAgent) WithCallbacks(callbacks ...agentcore.Callback) agentcore.Runnable[*agentcore.AgentInput, *agentcore.AgentOutput]
WithCallbacks adds callback handlers
func (*GoTAgent) WithConfig ¶
func (g *GoTAgent) WithConfig(config agentcore.RunnableConfig) agentcore.Runnable[*agentcore.AgentInput, *agentcore.AgentOutput]
WithConfig configures the agent
type GoTConfig ¶
type GoTConfig struct {
Name string // Agent name
Description string // Agent description
LLM llm.Client // LLM client
Tools []interfaces.Tool // Available tools (optional)
// Graph parameters
MaxNodes int // Maximum number of nodes in the graph
MaxEdgesPerNode int // Maximum edges from a single node
ParallelExecution bool // Enable parallel node processing
MergeStrategy string // How to merge multiple paths ("vote", "weighted", "llm")
CycleDetection bool // Enable cycle detection
PruneThreshold float64 // Threshold for pruning low-score nodes
}
GoTConfig configuration for Graph-of-Thought agent
type GraphNode ¶
type GraphNode struct {
ID string
Thought string
Score float64
Dependencies []*GraphNode // Nodes this depends on
Dependents []*GraphNode // Nodes that depend on this
State map[string]interface{} // State at this node
Status string // "pending", "processing", "completed"
Result interface{} // Result after processing
// contains filtered or unexported fields
}
GraphNode represents a node in the thought graph