agent

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2026 License: MIT Imports: 22 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 struct {
	SessionID string `json:"session_id"` // 会话ID, for 持久化信息

	// basic
	ID   string `json:"id"` // 唯一标识
	Name string `json:"name"`
	Role string `json:"role"` // 角色

	// for prompt
	Description  string   `json:"description"`
	Goals        []string `json:"goals"`
	Instructions []string `json:"instructions"`
	Outputs      []string `json:"outputs"`
	Tools        []any    `json:"tools"`

	// for team
	TeamID string `json:"team_id"` // 团队ID
	// contains filtered or unexported fields
}

func NewAgent

func NewAgent(name string, options ...Option) *Agent

func (*Agent) Copy

func (agent *Agent) Copy() *Agent

func (*Agent) Invoke

func (agent *Agent) Invoke(ctx context.Context, task string, opts ...InvokeOption) *AgentRunResponse

concurrent invoke not support

type AgentRunResponse

type AgentRunResponse struct {
	Reasoning string         `json:"reasoning"`
	Answer    string         `json:"answer"`
	ToolCalls []llm.ToolCall `json:"tool_calls"`
	Error     error

	Stream chan *llm.Chunk
	Usage  llm.Usage
}

func (*AgentRunResponse) Completion

func (a *AgentRunResponse) Completion() string

type BrowserAgent added in v0.1.3

type BrowserAgent struct {
	Agent

	BrowserSession *browser.Session
	Browser        *browser.Browser
	// contains filtered or unexported fields
}

func NewBrowserAgent added in v0.1.3

func NewBrowserAgent(name string, options ...Option) *BrowserAgent

NewBrowserAgent ...

func (*BrowserAgent) Invoke added in v0.1.3

func (agent *BrowserAgent) Invoke(ctx context.Context, task string, opts ...InvokeOption) *AgentRunResponse

Invoke concurrent invoke not support

type InvokeOption

type InvokeOption func(*InvokeOptions)

func WithMaxIterationNum added in v0.1.3

func WithMaxIterationNum(num int) InvokeOption

func WithRetries

func WithRetries(retries int) InvokeOption

func WithSessionID added in v0.0.9

func WithSessionID(sessionID string) InvokeOption

func WithStream

func WithStream(stream bool) InvokeOption

type InvokeOptions

type InvokeOptions struct {
	SessionID       string `json:"session_id"`        // 会话ID, for 持久化信息
	Retries         int    `json:"retries"`           // 重试次数
	Stream          bool   `json:"stream"`            // 是否流式输出
	MaxIterationNum int    `json:"max_iteration_num"` // 最大迭代次数
}

type Memory

type Memory struct {
	ID        string    `json:"id"`
	Content   string    `json:"content"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

type MobileAgent added in v0.1.3

type MobileAgent struct {
	Agent

	TakeScreenshotURL func(ctx context.Context, adbTool *adb.AdbTool) (string, error)
	// contains filtered or unexported fields
}

func NewMobileAgent added in v0.1.3

func NewMobileAgent(name string, deviceID string, options ...Option) *MobileAgent

NewMobileAgent ...

func (*MobileAgent) Invoke added in v0.1.3

func (agent *MobileAgent) Invoke(ctx context.Context, task string, opts ...InvokeOption) *AgentRunResponse

Invoke concurrent invoke not support

type Option

type Option func(any)

func WithAgenticSharedContext

func WithAgenticSharedContext(enable bool) Option

func WithBrowserConfig added in v0.1.3

func WithBrowserConfig(config *browser.BrowserConfig) Option

func WithDescription

func WithDescription(description string) Option

func WithID

func WithID(id string) Option

func WithInstructions

func WithInstructions(instructions ...string) Option

func WithKnowledge added in v0.0.9

func WithKnowledge(retrieval *rag.Indexer) Option

func WithLLM

func WithLLM(llm *llm.Instance) Option

func WithMembers

func WithMembers(members ...*Agent) Option

func WithMemory added in v0.0.9

func WithMemory(memory memory.Memory) Option

func WithMode

func WithMode(mode TeamMode) Option

func WithModel

func WithModel(model *llm.Instance) Option

func WithName

func WithName(name string) Option

func WithRole

func WithRole(role string) Option

func WithShareMemberInteractions

func WithShareMemberInteractions(enable bool) Option

func WithStorage added in v0.0.9

func WithStorage(storage storage.Storage) Option

func WithTools

func WithTools(tools ...any) Option

type SharedContexts

type SharedContexts struct {
	Context                string
	TeamMemberInteractions []TeamMemberInteraction
}

type Team

type Team struct {
	Agent
	// contains filtered or unexported fields
}

Team A team of agents

func NewTeam

func NewTeam(mode TeamMode, opts ...Option) *Team

func (*Team) DebugAssignTask

func (t *Team) DebugAssignTask() string

func (*Team) Invoke

func (t *Team) Invoke(ctx context.Context, query string, optfuncs ...InvokeOption) *TeamRunResponse

type TeamMemberInteraction

type TeamMemberInteraction struct {
	MemberName string
	Task       string
	Response   *AgentRunResponse
}

type TeamMemory

type TeamMemory struct {
	sync.RWMutex

	SharedContexts SharedContexts
}

func (*TeamMemory) AddTeamMemberInteractions

func (t *TeamMemory) AddTeamMemberInteractions(ctx context.Context, memberName string, task string, response *AgentRunResponse) error

func (*TeamMemory) GetSharedContext

func (t *TeamMemory) GetSharedContext(ctx context.Context) (string, error)

func (*TeamMemory) GetTeamMemberInteractions

func (t *TeamMemory) GetTeamMemberInteractions(ctx context.Context) ([]TeamMemberInteraction, error)

func (*TeamMemory) SetSharedContext

func (t *TeamMemory) SetSharedContext(ctx context.Context, text string) (string, error)

type TeamMode

type TeamMode string
const (
	TeamModeRoute       TeamMode = "route"       // 路由模式, 路由模式下,团队leader 会根据用户请求,选择合适的 agent 进行处理
	TeamModeCoordinate  TeamMode = "coordinate"  // 协调模式, 协调模式下,团队leader 会根据用户请求,拆分任务给各个 agent 进行处理,最后综合给出答案
	TeamModeCollaborate TeamMode = "collaborate" // 协作模式, 协作模式下,团队leader 会根据用户请求,
)

type TeamRunResponse

type TeamRunResponse struct {
	sync.RWMutex // for thread safe

	Reasoning       string         `json:"reasoning"`
	Answer          string         `json:"answer"`
	ToolCalls       []llm.ToolCall `json:"tool_calls"`
	Stream          chan *llm.Chunk
	MemberResponses []*AgentRunResponse

	Error error
}

func (*TeamRunResponse) AddMemberResponse

func (t *TeamRunResponse) AddMemberResponse(response *AgentRunResponse)

func (*TeamRunResponse) String

func (t *TeamRunResponse) String() string

Jump to

Keyboard shortcuts

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