run

package
v0.12.1 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AgentEvent

type AgentEvent struct {
	BaseEvent
	AgentID string                 `json:"agent_id,omitempty"`
	Content string                 `json:"content,omitempty"`
	Delta   string                 `json:"delta,omitempty"`
	Metrics map[string]interface{} `json:"metrics,omitempty"`
}

AgentEvent Agent 事件

type BaseEvent

type BaseEvent struct {
	Type      EventType              `json:"type"`
	ID        string                 `json:"run_id"`
	Time      time.Time              `json:"timestamp"`
	SessionID string                 `json:"session_id,omitempty"`
	Data      map[string]interface{} `json:"data,omitempty"`
}

BaseEvent 基础事件

func NewBaseEvent

func NewBaseEvent(eventType EventType, runID string) *BaseEvent

NewBaseEvent 创建基础事件

func (*BaseEvent) EventType

func (e *BaseEvent) EventType() EventType

EventType 实现 Event 接口

func (*BaseEvent) RunID

func (e *BaseEvent) RunID() string

RunID 实现 Event 接口

func (*BaseEvent) Timestamp

func (e *BaseEvent) Timestamp() time.Time

Timestamp 实现 Event 接口

func (*BaseEvent) ToJSON

func (e *BaseEvent) ToJSON() ([]byte, error)

ToJSON 实现 Event 接口

func (*BaseEvent) ToMap

func (e *BaseEvent) ToMap() map[string]interface{}

ToMap 实现 Event 接口

type Context

type Context struct {
	// RunID 运行 ID
	RunID string

	// SessionID 会话 ID
	SessionID string

	// UserID 用户 ID
	UserID string

	// AgentID Agent ID
	AgentID string

	// WorkflowID Workflow ID (如果是 Workflow 运行)
	WorkflowID string

	// TeamID Team ID (如果是 Team 运行)
	TeamID string

	// StartTime 开始时间
	StartTime time.Time

	// Metadata 元数据
	Metadata map[string]interface{}

	// SessionState 会话状态
	SessionState map[string]interface{}

	// KnowledgeFilters 知识过滤器
	KnowledgeFilters map[string]interface{}

	// Dependencies 依赖项
	Dependencies map[string]interface{}
	// contains filtered or unexported fields
}

Context 运行上下文 - 统一的运行时上下文管理

func NewContext

func NewContext(runID, sessionID string) *Context

NewContext 创建运行上下文

func NewContextWithContext

func NewContextWithContext(ctx context.Context, runID, sessionID string) *Context

NewContextWithContext 使用 Go context 创建运行上下文

func (*Context) Clone

func (c *Context) Clone() *Context

Clone 克隆上下文

func (*Context) Context

func (c *Context) Context() context.Context

Context 获取 Go context

func (*Context) Elapsed

func (c *Context) Elapsed() time.Duration

Elapsed 返回运行时长

func (*Context) WithAgentID

func (c *Context) WithAgentID(agentID string) *Context

WithAgentID 设置 Agent ID

func (*Context) WithMetadata

func (c *Context) WithMetadata(key string, value interface{}) *Context

WithMetadata 设置元数据

func (*Context) WithSessionState

func (c *Context) WithSessionState(state map[string]interface{}) *Context

WithSessionState 设置会话状态

func (*Context) WithTeamID

func (c *Context) WithTeamID(teamID string) *Context

WithTeamID 设置 Team ID

func (*Context) WithUserID

func (c *Context) WithUserID(userID string) *Context

WithUserID 设置用户 ID

func (*Context) WithWorkflowID

func (c *Context) WithWorkflowID(workflowID string) *Context

WithWorkflowID 设置 Workflow ID

type Event

type Event interface {
	// EventType 返回事件类型
	EventType() EventType

	// RunID 返回运行 ID
	RunID() string

	// Timestamp 返回时间戳
	Timestamp() time.Time

	// ToMap 转换为 map
	ToMap() map[string]interface{}

	// ToJSON 转换为 JSON
	ToJSON() ([]byte, error)
}

Event 统一的运行事件接口

type EventType

type EventType string

EventType 事件类型

const (
	// Agent 相关事件
	EventAgentStart      EventType = "agent.start"
	EventAgentProgress   EventType = "agent.progress"
	EventAgentToolCall   EventType = "agent.tool_call"
	EventAgentToolResult EventType = "agent.tool_result"
	EventAgentComplete   EventType = "agent.complete"
	EventAgentError      EventType = "agent.error"

	// Workflow 相关事件
	EventWorkflowStart    EventType = "workflow.start"
	EventWorkflowStep     EventType = "workflow.step"
	EventWorkflowComplete EventType = "workflow.complete"
	EventWorkflowError    EventType = "workflow.error"

	// Team 相关事件
	EventTeamStart        EventType = "team.start"
	EventTeamMemberStart  EventType = "team.member_start"
	EventTeamMemberResult EventType = "team.member_result"
	EventTeamComplete     EventType = "team.complete"
	EventTeamError        EventType = "team.error"

	// 通用事件
	EventProgress     EventType = "progress"
	EventStatusChange EventType = "status_change"
	EventMetrics      EventType = "metrics"
)

type Input

type Input struct {
	// Content 输入内容
	Content interface{}

	// Images 图片列表
	Images []string

	// Videos 视频列表
	Videos []string

	// Audio 音频列表
	Audio []string

	// Files 文件列表
	Files []string

	// Metadata 元数据
	Metadata map[string]interface{}

	// AdditionalMessages 额外消息
	AdditionalMessages []interface{}
}

Input 统一的运行输入

func NewInput

func NewInput(content interface{}) *Input

NewInput 创建输入

func (*Input) ContentString

func (i *Input) ContentString() string

ContentString 获取字符串形式的内容

func (*Input) WithAudio

func (i *Input) WithAudio(audio ...string) *Input

WithAudio 添加音频

func (*Input) WithFiles

func (i *Input) WithFiles(files ...string) *Input

WithFiles 添加文件

func (*Input) WithImages

func (i *Input) WithImages(images ...string) *Input

WithImages 添加图片

func (*Input) WithMetadata

func (i *Input) WithMetadata(key string, value interface{}) *Input

WithMetadata 添加元数据

func (*Input) WithVideos

func (i *Input) WithVideos(videos ...string) *Input

WithVideos 添加视频

type MetricsEvent

type MetricsEvent struct {
	BaseEvent
	TokensUsed    int     `json:"tokens_used,omitempty"`
	TokensInput   int     `json:"tokens_input,omitempty"`
	TokensOutput  int     `json:"tokens_output,omitempty"`
	ExecutionTime float64 `json:"execution_time,omitempty"`
	ModelCalls    int     `json:"model_calls,omitempty"`
	ToolCalls     int     `json:"tool_calls,omitempty"`
}

MetricsEvent 指标事件

type Status

type Status string

Status 运行状态

const (
	// StatusPending 待运行
	StatusPending Status = "PENDING"

	// StatusRunning 运行中
	StatusRunning Status = "RUNNING"

	// StatusCompleted 完成
	StatusCompleted Status = "COMPLETED"

	// StatusPaused 暂停
	StatusPaused Status = "PAUSED"

	// StatusCancelled 取消
	StatusCancelled Status = "CANCELLED"

	// StatusError 错误
	StatusError Status = "ERROR"

	// StatusTimeout 超时
	StatusTimeout Status = "TIMEOUT"
)

func (Status) IsActive

func (s Status) IsActive() bool

IsActive 判断是否为活跃状态

func (Status) IsTerminal

func (s Status) IsTerminal() bool

IsTerminal 判断是否为终止状态

func (Status) String

func (s Status) String() string

String 返回字符串表示

type StatusChangeEvent

type StatusChangeEvent struct {
	BaseEvent
	OldStatus Status `json:"old_status"`
	NewStatus Status `json:"new_status"`
	Reason    string `json:"reason,omitempty"`
}

StatusChangeEvent 状态变更事件

type TeamEvent

type TeamEvent struct {
	BaseEvent
	TeamID   string                 `json:"team_id,omitempty"`
	MemberID string                 `json:"member_id,omitempty"`
	Role     string                 `json:"role,omitempty"`
	Metrics  map[string]interface{} `json:"metrics,omitempty"`
}

TeamEvent Team 事件

type WorkflowEvent

type WorkflowEvent struct {
	BaseEvent
	WorkflowID string                 `json:"workflow_id,omitempty"`
	StepID     string                 `json:"step_id,omitempty"`
	StepName   string                 `json:"step_name,omitempty"`
	StepType   string                 `json:"step_type,omitempty"`
	Progress   float64                `json:"progress,omitempty"`
	Metrics    map[string]interface{} `json:"metrics,omitempty"`
}

WorkflowEvent Workflow 事件

Jump to

Keyboard shortcuts

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