got

package
v0.3.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 28, 2025 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GoTAgent

type GoTAgent struct {
	*agentcore.BaseAgent
	// contains filtered or unexported fields
}

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

func NewGoTAgent(config GoTConfig) *GoTAgent

NewGoTAgent creates a new Graph-of-Thought agent

func (*GoTAgent) Invoke

Invoke executes the Graph-of-Thought reasoning

func (*GoTAgent) RunGenerator added in v0.2.0

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

Stream executes Graph-of-Thought with streaming

func (*GoTAgent) WithCallbacks

WithCallbacks adds callback handlers

func (*GoTAgent) WithConfig

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL