team

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2025 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoTeam = errors.New("no team in context")

ErrNoTeam indicates the context is missing a team value.

View Source
var ErrUnknownAgent = errors.New("unknown agent")

ErrUnknownAgent is returned when the named agent does not exist.

Functions

func GetAgentToolSpec

func GetAgentToolSpec() tool.Tool

GetAgentToolSpec returns the tool specification for the agent tool This can be used to register the tool without creating a team instance

func LoadRolesFromIncludePaths

func LoadRolesFromIncludePaths(includePaths []string, configDir string) (map[string]*RoleConfig, error)

LoadRolesFromIncludePaths loads roles from the include paths in the config

func WithContext

func WithContext(ctx context.Context, t Caller) context.Context

WithContext returns a new context carrying t.

Types

type Agent

type Agent struct {
	ID        string            `json:"id"`
	Name      string            `json:"name"`
	Role      string            `json:"role,omitempty"`
	Agent     *core.Agent       `json:"-"`
	Port      int               `json:"port,omitempty"`
	Status    string            `json:"status"`
	StartedAt time.Time         `json:"started_at"`
	LastSeen  time.Time         `json:"last_seen"`
	Metadata  map[string]string `json:"metadata"`
	// contains filtered or unexported fields
}

Agent represents a team agent with metadata

func (*Agent) GetStatus

func (a *Agent) GetStatus() string

GetStatus returns the current agent status

func (*Agent) SetStatus

func (a *Agent) SetStatus(status string)

SetStatus updates the agent's status

type Caller

type Caller interface {
	Call(ctx context.Context, agent, input string) (string, error)
}

Caller represents a team capable of handling delegated calls.

func FromContext

func FromContext(ctx context.Context) (Caller, bool)

FromContext retrieves the team stored in ctx.

type CoordinationEvent

type CoordinationEvent struct {
	ID        string                 `json:"id"`
	Type      string                 `json:"type"` // "delegation", "message", "task_assign", "status_update"
	From      string                 `json:"from"`
	To        string                 `json:"to"`
	Content   string                 `json:"content"`
	Timestamp time.Time              `json:"timestamp"`
	Metadata  map[string]interface{} `json:"metadata,omitempty"`
}

CoordinationEvent represents an event in agent coordination

type Message

type Message struct {
	ID        string            `json:"id"`
	From      string            `json:"from"`
	To        string            `json:"to"`
	Content   string            `json:"content"`
	Type      string            `json:"type"`
	Timestamp time.Time         `json:"timestamp"`
	Read      bool              `json:"read"`
	Metadata  map[string]string `json:"metadata,omitempty"`
}

Message represents a message between agents

type PortRange

type PortRange struct {
	Start int `json:"start"`
	End   int `json:"end"`
}

PortRange defines a range of ports for agent communication

type RoleConfig

type RoleConfig struct {
	Name            string                `json:"name" yaml:"name"`
	Model           *config.ModelManifest `json:"model,omitempty" yaml:"model,omitempty"`
	Prompt          string                `json:"prompt" yaml:"prompt"`
	Tools           []string              `json:"tools,omitempty" yaml:"tools,omitempty"`
	RestrictedTools []string              `json:"restricted_tools,omitempty" yaml:"restricted_tools,omitempty"`
	Capabilities    []string              `json:"capabilities,omitempty" yaml:"capabilities,omitempty"`
	Metadata        map[string]string     `json:"metadata,omitempty" yaml:"metadata,omitempty"`
}

RoleConfig represents configuration for an agent role

func LoadRoleFromFile

func LoadRoleFromFile(path string) (*RoleConfig, error)

LoadRoleFromFile loads a role configuration from a YAML file

type Task

type Task struct {
	ID        string            `json:"id"`
	Type      string            `json:"type"`
	AgentID   string            `json:"agent_id"`
	Input     string            `json:"input"`
	Result    string            `json:"result,omitempty"`
	Status    string            `json:"status"`
	CreatedAt time.Time         `json:"created_at"`
	UpdatedAt time.Time         `json:"updated_at"`
	Metadata  map[string]string `json:"metadata,omitempty"`
}

Task represents a task assigned to an agent

type Team

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

Team manages a multi-agent conversation step by step. This is a simplified version that consolidates the functionality from converse.Team and maintains compatibility.

func NewTeam

func NewTeam(parent *core.Agent, maxTurns int, name string) (*Team, error)

NewTeam creates a new team with the given parent agent.

func NewTeamWithRoles

func NewTeamWithRoles(parent *core.Agent, maxTurns int, name string, includePaths []string, configDir string) (*Team, error)

NewTeamWithRoles creates a new team with the given parent agent and loads role configurations.

func TeamFromContext

func TeamFromContext(ctx context.Context) *Team

TeamFromContext extracts a Team pointer if present. This provides compatibility with legacy converse.TeamFromContext usage.

func (*Team) Add

func (t *Team) Add(name string, ag *core.Agent)

Add registers ag under name so it can be addressed via Call.

func (*Team) AddAgent

func (t *Team) AddAgent(name string) (*core.Agent, string)

AddAgent creates a new agent and adds it to the team. Returns the core agent and its assigned name.

func (*Team) AddExistingAgent

func (t *Team) AddExistingAgent(name string, agent *core.Agent) error

AddExistingAgent adds an existing agent to the team

func (*Team) AddRole

func (t *Team) AddRole(role *RoleConfig)

AddRole adds a role configuration to the team

func (*Team) AssignTask

func (t *Team) AssignTask(ctx context.Context, agentID, taskType, input string) (*Task, error)

AssignTask assigns a task to a specific agent

func (*Team) AvailableRoleNames

func (t *Team) AvailableRoleNames() []string

AvailableRoleNames returns role names from configuration files

func (*Team) BroadcastToAllAgents

func (t *Team) BroadcastToAllAgents(ctx context.Context, fromAgentID, message string) error

BroadcastToAllAgents sends a message to all agents

func (*Team) Call

func (t *Team) Call(ctx context.Context, agentID, input string) (string, error)

Call delegates work to the named agent with enhanced communication logging.

func (*Team) CallParallel

func (t *Team) CallParallel(ctx context.Context, tasks []interface{}) (string, error)

CallParallel executes multiple agent tasks in parallel for improved efficiency

func (*Team) CoordinateTask

func (t *Team) CoordinateTask(ctx context.Context, description string) (*Task, error)

CoordinateTask coordinates a complex task across multiple agents

func (*Team) CoordinationHistoryStrings

func (t *Team) CoordinationHistoryStrings(limit int) []string

CoordinationHistoryStrings returns formatted lines of coordination events. If limit <= 0, returns all events; otherwise returns the last 'limit' events.

func (*Team) DelegateTask

func (t *Team) DelegateTask(ctx context.Context, role, task string) (string, error)

DelegateTask delegates a task to a role (spawning if needed)

func (*Team) GetAgent

func (t *Team) GetAgent(id string) *Agent

GetAgent returns an agent by ID or name

func (*Team) GetAgentInbox

func (t *Team) GetAgentInbox(agentID string) []map[string]interface{}

GetAgentInbox returns unread messages for an agent (as generic maps for tool consumption)

func (*Team) GetAgents

func (t *Team) GetAgents() []string

GetAgents returns a list of all agent names in the team.

func (*Team) GetAllSharedData

func (t *Team) GetAllSharedData() map[string]interface{}

GetAllSharedData returns all shared memory data

func (*Team) GetCoordinationHistory

func (t *Team) GetCoordinationHistory(limit int) []string

GetCoordinationHistory returns coordination event history

func (*Team) GetCoordinationSummary

func (t *Team) GetCoordinationSummary() string

GetCoordinationSummary returns a summary of recent coordination events

func (*Team) GetInbox

func (t *Team) GetInbox(agentID string) []map[string]interface{}

GetInbox returns an agent's inbox messages

func (*Team) GetMaxTurns

func (t *Team) GetMaxTurns() int

GetMaxTurns returns the maximum number of turns

func (*Team) GetMessages

func (t *Team) GetMessages(agentID string) []Message

GetMessages returns messages with optional filtering

func (*Team) GetName

func (t *Team) GetName() string

GetName returns the team name

func (*Team) GetParent

func (t *Team) GetParent() interface{}

GetParent returns the parent agent

func (*Team) GetRole

func (t *Team) GetRole(name string) *RoleConfig

GetRole returns a role configuration by name

func (*Team) GetRoles

func (t *Team) GetRoles() map[string]*RoleConfig

GetRoles returns the loaded role configurations by name.

func (*Team) GetSharedData

func (t *Team) GetSharedData(key string) (interface{}, bool)

GetSharedData retrieves data from shared memory

func (*Team) GetTask

func (t *Team) GetTask(taskID string) *Task

GetTask returns a task by ID

func (*Team) GetTeamAgents

func (t *Team) GetTeamAgents() []*Agent

GetTeamAgents returns a list of all team agents with role information.

func (*Team) GetWorkspaceEvents

func (t *Team) GetWorkspaceEvents(limit int) []WorkspaceEvent

GetWorkspaceEvents returns recent workspace events

func (*Team) ListAgents

func (t *Team) ListAgents() []*Agent

ListAgents returns all agents in the team

func (*Team) ListRoleNames

func (t *Team) ListRoleNames() []string

ListRoleNames returns all available role names

func (*Team) ListRoles

func (t *Team) ListRoles() []*RoleConfig

ListRoles returns all available roles

func (*Team) ListTasks

func (t *Team) ListTasks() []*Task

ListTasks returns all tasks

func (*Team) LogCoordinationEvent

func (t *Team) LogCoordinationEvent(eventType, from, to, content string, metadata map[string]interface{})

LogCoordinationEvent adds a coordination event to the log and persists it.

func (*Team) MarkInboxRead

func (t *Team) MarkInboxRead(agentID string)

MarkInboxRead marks an agent's messages as read

func (*Team) MarkMessagesAsRead

func (t *Team) MarkMessagesAsRead(agentID string)

MarkMessagesAsRead marks messages in an agent's inbox as read

func (*Team) Names

func (t *Team) Names() []string

Names returns a list of all agent names in the team.

func (*Team) ProposeCollaboration

func (t *Team) ProposeCollaboration(ctx context.Context, proposerID, targetAgentID, proposal string) error

ProposeCollaboration allows agents to propose working together

func (*Team) PublishWorkspaceEvent

func (t *Team) PublishWorkspaceEvent(agentID, eventType, description string, data map[string]interface{})

PublishWorkspaceEvent publishes an event that all agents can see

func (*Team) RegisterAgentTool

func (t *Team) RegisterAgentTool(registry tool.Registry)

RegisterAgentTool registers the "agent" tool with the given tool registry. This must be called after creating the team to avoid import cycles.

func (*Team) RequestHelp

func (t *Team) RequestHelp(ctx context.Context, agentID, helpDescription string, preferredHelper string) error

RequestHelp allows an agent to request help from other agents

func (*Team) SendMessage

func (t *Team) SendMessage(ctx context.Context, from, to, content string) error

SendMessage sends a message from one agent to another

func (*Team) SendMessageToAgent

func (t *Team) SendMessageToAgent(ctx context.Context, fromAgentID, toAgentID, message string) error

SendMessageToAgent enables direct communication between agents

func (*Team) SetMaxTurns

func (t *Team) SetMaxTurns(maxTurns int)

SetMaxTurns sets the maximum number of turns for conversations

func (*Team) SetSharedData

func (t *Team) SetSharedData(key string, value interface{})

SetSharedData stores data in shared memory accessible to all agents

func (*Team) SpawnAgent

func (t *Team) SpawnAgent(ctx context.Context, name, role string) (*Agent, error)

SpawnAgent creates a new agent with the given configuration

func (*Team) SpawnedAgentNames

func (t *Team) SpawnedAgentNames() []string

SpawnedAgentNames returns currently running agent instances

func (*Team) StopAgent

func (t *Team) StopAgent(ctx context.Context, agentID string) error

StopAgent stops and removes an agent from the team

func (*Team) WaitForTask

func (t *Team) WaitForTask(ctx context.Context, taskID string, timeout time.Duration) (*Task, error)

WaitForTask waits for a task to complete with timeout

type Timer

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

Timer utility for performance debugging

func StartTimer

func StartTimer(name string) *Timer

func (*Timer) Checkpoint

func (t *Timer) Checkpoint(checkpoint string) time.Duration

func (*Timer) Stop

func (t *Timer) Stop() time.Duration

type WorkspaceEvent

type WorkspaceEvent struct {
	ID          string                 `json:"id"`
	Type        string                 `json:"type"` // "file_created", "task_started", "task_completed", "question", "help_request"
	AgentID     string                 `json:"agent_id"`
	Description string                 `json:"description"`
	Timestamp   time.Time              `json:"timestamp"`
	Data        map[string]interface{} `json:"data"`
}

WorkspaceEvent represents an event in the shared workspace

Jump to

Keyboard shortcuts

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