agent

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2025 License: MIT Imports: 9 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 {

	// session
	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
}

func (*AgentRunResponse) Completion

func (a *AgentRunResponse) Completion() string

type InvokeOption

type InvokeOption func(*InvokeOptions)

func WithRetries

func WithRetries(retries int) InvokeOption

func WithStream

func WithStream(stream bool) InvokeOption

type InvokeOptions

type InvokeOptions struct {
	Retries int  `json:"retries"` // 重试次数
	Stream  bool `json:"stream"`  // 是否流式输出
}

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 Option

type Option func(any)

func WithAgenticSharedContext

func WithAgenticSharedContext(enable bool) Option

func WithDescription

func WithDescription(description string) Option

func WithID

func WithID(id string) Option

func WithInstructions

func WithInstructions(instructions ...string) Option

func WithLLM

func WithLLM(llm *llm.Instance) Option

func WithMembers

func WithMembers(members ...*Agent) 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 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