Help us shape the future of Go! Take the 2026 Go Developer Survey

core

package
v1.11.3 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrStepNotConfigured = errors.New("step dependency not configured")
	ErrStepValidation    = errors.New("step validation failed")
	ErrStepExecution     = errors.New("step execution failed")
	ErrStepTimeout       = errors.New("step execution timed out")
)

统一步骤错误。

Functions

This section is empty.

Types

type AgentExecutionMetadata added in v1.6.0

type AgentExecutionMetadata struct {
	AgentID      string        `json:"agent_id,omitempty"`
	TokensUsed   int           `json:"tokens_used,omitempty"`
	Cost         float64       `json:"cost,omitempty"`
	Duration     time.Duration `json:"duration,omitempty"`
	FinishReason string        `json:"finish_reason,omitempty"`
}

AgentExecutionMetadata carries execution metrics from an AgentStep back to the workflow layer for cost aggregation and observability.

type AgentExecutionOutput added in v1.6.0

type AgentExecutionOutput struct {
	Content      string        `json:"content"`
	TokensUsed   int           `json:"tokens_used,omitempty"`
	Cost         float64       `json:"cost,omitempty"`
	Duration     time.Duration `json:"duration,omitempty"`
	FinishReason string        `json:"finish_reason,omitempty"`
}

AgentExecutionOutput carries structured execution results from an agent step, eliminating type assertions for metadata extraction.

type AgentExecutor

type AgentExecutor interface {
	Execute(ctx context.Context, input map[string]any) (*AgentExecutionOutput, error)
}

AgentExecutor workflow 侧 agent 执行抽象。

type GatewayLike

type GatewayLike interface {
	Invoke(ctx context.Context, req *LLMRequest) (*LLMResponse, error)
	Stream(ctx context.Context, req *LLMRequest) (<-chan LLMStreamChunk, error)
}

GatewayLike 是 LLM Gateway 的抽象接口。 workflow 层通过此接口调用 LLM,不直接依赖 llm.Provider。

type HumanInputHandler

type HumanInputHandler interface {
	RequestInput(ctx context.Context, prompt string, inputType string, options []string) (*HumanInputResult, error)
}

HumanInputHandler 人工输入处理器抽象。

type HumanInputResult added in v1.6.0

type HumanInputResult struct {
	Value    string `json:"value"`
	OptionID string `json:"option_id,omitempty"`
}

HumanInputResult 人工输入的结构化返回值。

type LLMRequest

type LLMRequest struct {
	Model       string
	Prompt      string
	Temperature float64
	MaxTokens   int
	Metadata    map[string]string
}

LLMRequest 是 workflow 层面的 LLM 请求。

type LLMResponse

type LLMResponse struct {
	Content string
	Model   string
	Usage   *LLMUsage
}

LLMResponse 是 workflow 层面的 LLM 响应。

type LLMStreamChunk added in v1.11.0

type LLMStreamChunk struct {
	Delta            string
	ReasoningContent *string
	Model            string
	Usage            *LLMUsage
	Done             bool
	Err              error
}

LLMStreamChunk 是 workflow 层面的流式 LLM 响应块。

type LLMUsage

type LLMUsage struct {
	PromptTokens     int
	CompletionTokens int
	TotalTokens      int
}

LLMUsage 记录 token 用量。

type StepError

type StepError struct {
	StepID   string
	StepType StepType
	Cause    error
}

StepError 包装步骤执行错误,携带步骤 ID 和类型。

func NewStepError

func NewStepError(stepID string, stepType StepType, cause error) *StepError

NewStepError 创建步骤错误。

func (*StepError) Error

func (e *StepError) Error() string

func (*StepError) Unwrap

func (e *StepError) Unwrap() error

type StepInput

type StepInput struct {
	// Data 上游步骤输出或用户输入。
	// nil 时视为空 map,调用方应使用 len(Data) == 0 或 Data == nil 判断。
	Data map[string]any
	// Metadata trace_id、run_id、node_id 等追踪信息。
	// nil 时视为空 map,调用方应使用 len(Metadata) == 0 或 Metadata == nil 判断。
	Metadata map[string]string
}

StepInput 步骤输入。

type StepOutput

type StepOutput struct {
	Data    map[string]any    // 输出数据
	Usage   *types.TokenUsage // 可选,LLM 步骤填充
	Latency time.Duration
	Agent   *AgentExecutionMetadata // 可选,Agent 步骤填充
}

StepOutput 步骤输出。

type StepProtocol

type StepProtocol interface {
	// ID 返回步骤唯一标识。
	ID() string
	// Type 返回步骤类型。
	Type() StepType
	// Execute 执行步骤。
	Execute(ctx context.Context, input StepInput) (StepOutput, error)
	// Validate 校验步骤配置是否合法。
	Validate() error
}

StepProtocol 统一步骤协议(Command Pattern)。 所有步骤类型必须实现此接口。

type StepType

type StepType string

StepType 步骤类型枚举。

const (
	StepTypeLLM              StepType = "llm"
	StepTypeTool             StepType = "tool"
	StepTypeHuman            StepType = "human"
	StepTypeHumanInput       StepType = "human_input" // DSL 别名,与 StepTypeHuman 语义等价
	StepTypeCode             StepType = "code"
	StepTypeAgent            StepType = "agent"
	StepTypeHybridRetrieve   StepType = "hybrid_retrieve"
	StepTypeMultiHopRetrieve StepType = "multi_hop_retrieve"
	StepTypeRerank           StepType = "rerank"
	StepTypeOrchestration    StepType = "orchestration"
	StepTypeChain            StepType = "chain"
	StepTypePassthrough      StepType = "passthrough"
)

type ToolRegistry

type ToolRegistry interface {
	ExecuteTool(ctx context.Context, name string, params map[string]any) (any, error)
}

ToolRegistry 工具注册表抽象。 返回值保留 any 因为工具结果是异构的,不同工具返回不同结构。

Jump to

Keyboard shortcuts

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