workflow

package
v0.35.0 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Agent

type Agent interface {
	Name() string
	Execute(ctx context.Context, message string) *stream.Reader[*session.Event]
}

Agent 接口定义 简化版本,实际应该从主 Agent 包导入

type LoopAgent

type LoopAgent struct {
	// contains filtered or unexported fields
}

LoopAgent 循环执行子 Agent 直到满足终止条件 参考 Google ADK-Go 的 LoopAgent 设计

使用场景: - 代码迭代优化直到满足质量要求 - 多轮对话直到用户满意 - 任务重试直到成功或达到最大次数

func NewLoopAgent

func NewLoopAgent(cfg LoopConfig) (*LoopAgent, error)

NewLoopAgent 创建循环 Agent

func (*LoopAgent) Execute

func (a *LoopAgent) Execute(ctx context.Context, message string) *stream.Reader[*session.Event]

Execute 循环执行子 Agent

func (*LoopAgent) MaxIterations

func (a *LoopAgent) MaxIterations() uint

CurrentIteration 返回当前迭代次数(仅用于监控)

func (*LoopAgent) Name

func (a *LoopAgent) Name() string

Name 返回 Agent 名称

func (*LoopAgent) SubAgents

func (a *LoopAgent) SubAgents() []Agent

SubAgents 返回所有子 Agent

type LoopConfig

type LoopConfig struct {
	// Name Agent 名称
	Name string

	// SubAgents 子 Agent 列表(按顺序执行)
	SubAgents []Agent

	// MaxIterations 最大迭代次数(0 表示无限制,需要依赖 StopCondition)
	MaxIterations uint

	// StopCondition 自定义停止条件(可选)
	// 如果未提供,默认检查 event.Actions.Escalate
	StopCondition StopCondition
}

LoopConfig LoopAgent 配置

type ParallelAgent

type ParallelAgent struct {
	// contains filtered or unexported fields
}

ParallelAgent 并行执行多个子 Agent 参考 Google ADK-Go 的 ParallelAgent 设计

使用场景: - 同时运行不同算法进行比较 - 生成多个候选响应供后续评估 - 并行处理独立的任务

func NewParallelAgent

func NewParallelAgent(cfg ParallelConfig) (*ParallelAgent, error)

NewParallelAgent 创建并行 Agent

func (*ParallelAgent) AddSubAgent

func (a *ParallelAgent) AddSubAgent(agent Agent)

AddSubAgent 动态添加子 Agent

func (*ParallelAgent) Execute

func (a *ParallelAgent) Execute(ctx context.Context, message string) *stream.Reader[*session.Event]

Execute 并行执行所有子 Agent

func (*ParallelAgent) Name

func (a *ParallelAgent) Name() string

Name 返回 Agent 名称

func (*ParallelAgent) SubAgents

func (a *ParallelAgent) SubAgents() []Agent

SubAgents 返回所有子 Agent

type ParallelConfig

type ParallelConfig struct {
	// Name Agent 名称
	Name string

	// SubAgents 子 Agent 列表
	SubAgents []Agent

	// MaxConcurrent 最大并发数(0 表示无限制)
	MaxConcurrent int
}

ParallelConfig ParallelAgent 配置

type SequentialAgent

type SequentialAgent struct {
	*LoopAgent
}

SequentialAgent 顺序执行子 Agent 参考 Google ADK-Go 的 SequentialAgent 设计

实际上是 LoopAgent 的特例(MaxIterations=1)

使用场景: - 多步骤工作流(分析 -> 规划 -> 执行) - 流水线处理(预处理 -> 处理 -> 后处理) - 阶段性任务(收集信息 -> 分析 -> 决策)

func NewSequentialAgent

func NewSequentialAgent(cfg SequentialConfig) (*SequentialAgent, error)

NewSequentialAgent 创建顺序 Agent

func (*SequentialAgent) Execute

func (a *SequentialAgent) Execute(ctx context.Context, message string) *stream.Reader[*session.Event]

Execute 顺序执行所有子 Agent(仅一次)

type SequentialConfig

type SequentialConfig struct {
	// Name Agent 名称
	Name string

	// SubAgents 子 Agent 列表(严格按顺序执行一次)
	SubAgents []Agent

	// StopOnError 遇到错误时是否停止(默认 true)
	StopOnError bool
}

SequentialConfig SequentialAgent 配置

type StopCondition

type StopCondition func(event *session.Event) bool

StopCondition 停止条件函数 返回 true 表示应该停止循环

Jump to

Keyboard shortcuts

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