Documentation
¶
Index ¶
- Constants
- func FormatAgentID(name, teamName string) string
- func GetAgentName(ctx context.Context) string
- func IsShutdownRequest(text string) bool
- func IsTeammate(ctx context.Context) bool
- func WithTeammateContext(ctx context.Context, identity TeammateIdentity) context.Context
- type AgentProgress
- type Mailbox
- func (mb *Mailbox) Clear(agentName string) error
- func (mb *Mailbox) ConsumeFirst(agentName string) (*TeammateMessage, error)
- func (mb *Mailbox) MarkRead(agentName string, index int) error
- func (mb *Mailbox) ReadAll(agentName string) ([]TeammateMessage, error)
- func (mb *Mailbox) ReadUnread(agentName string) ([]TeammateMessage, error)
- func (mb *Mailbox) WriteMessage(recipientName string, msg TeammateMessage) error
- type Manager
- func (m *Manager) BroadcastMessage(from, message, summary string) (int, error)
- func (m *Manager) CreateTeam(name, description string) error
- func (m *Manager) DissolveTeam(ctx context.Context) error
- func (m *Manager) EnqueueUserMessage(agentID, message string)
- func (m *Manager) GetTeammateState(agentID string) *TeammateState
- func (m *Manager) HasTeam() bool
- func (m *Manager) KillTeammate(name string) error
- func (m *Manager) LeadAgentID() string
- func (m *Manager) ListTeammates() []*TeammateState
- func (m *Manager) SendMessage(to, from, message, summary string) error
- func (m *Manager) SetHandlersFactory(f func(workerName, workerColor string) []adk.ChatModelAgentMiddleware)
- func (m *Manager) SetTuiProgram(p *tea.Program)
- func (m *Manager) ShutdownTeammate(name, reason string) error
- func (m *Manager) SpawnTeammate(ctx context.Context, cfg SpawnConfig) (string, error)
- func (m *Manager) TeamName() string
- type ManagerDeps
- type SetTeamManagerMsg
- type SpawnConfig
- type TeamFile
- type TeamMember
- type TeammateIdentity
- type TeammateMessage
- type TeammateMessageMsg
- type TeammateProgressMsg
- type TeammateSpawnedMsg
- type TeammateState
- type TeammateStatus
- type TeammateStatusMsg
- type TeammateTokenUpdateMsg
Constants ¶
const TeamLeadName = "team-lead"
TeamLeadName is the canonical name for the team leader.
Variables ¶
This section is empty.
Functions ¶
func FormatAgentID ¶
FormatAgentID returns the canonical agent ID: "name@team".
func GetAgentName ¶
GetAgentName returns the agent name from the context, or TeamLeadName if not a teammate.
func IsShutdownRequest ¶
IsShutdownRequest checks if a message text is a shutdown request.
func IsTeammate ¶
IsTeammate returns true if the context belongs to a teammate (not the leader).
func WithTeammateContext ¶
func WithTeammateContext(ctx context.Context, identity TeammateIdentity) context.Context
WithTeammateContext injects teammate identity into the context.
Types ¶
type AgentProgress ¶
type AgentProgress struct {
ToolCallCount int
TokensUsed int64
LastToolName string
LastToolTime time.Time
}
AgentProgress tracks a teammate's execution progress for UI display.
type Mailbox ¶
type Mailbox struct {
// contains filtered or unexported fields
}
Mailbox provides file-based message passing between teammates. Each teammate has an inbox file: ~/.jcode/teams/{team}/inboxes/{sessionID}/{agent}.json
func NewMailbox ¶
NewMailbox creates a new mailbox scoped to a specific session. Path: ~/.jcode/teams/{team}/inboxes/{sessionID}/
func (*Mailbox) ConsumeFirst ¶
func (mb *Mailbox) ConsumeFirst(agentName string) (*TeammateMessage, error)
ConsumeFirst reads the first unread message and marks it as read atomically. Returns nil if no unread messages are available.
func (*Mailbox) ReadAll ¶
func (mb *Mailbox) ReadAll(agentName string) ([]TeammateMessage, error)
ReadAll returns all messages (read and unread) for the given agent.
func (*Mailbox) ReadUnread ¶
func (mb *Mailbox) ReadUnread(agentName string) ([]TeammateMessage, error)
ReadUnread returns only unread messages for the given agent.
func (*Mailbox) WriteMessage ¶
func (mb *Mailbox) WriteMessage(recipientName string, msg TeammateMessage) error
WriteMessage appends a message to the recipient's inbox with file-level locking.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager coordinates a team of agents.
func NewManager ¶
func NewManager(deps *ManagerDeps) *Manager
NewManager creates a team manager (without creating a team yet).
func (*Manager) BroadcastMessage ¶
BroadcastMessage sends a message to all teammates except the sender.
func (*Manager) CreateTeam ¶
CreateTeam initializes a new team with the caller as leader.
func (*Manager) DissolveTeam ¶
DissolveTeam shuts down all teammates and cleans up the team.
func (*Manager) EnqueueUserMessage ¶
EnqueueUserMessage adds a user message to a teammate's pending queue (for input from TUI when viewing that teammate).
func (*Manager) GetTeammateState ¶
func (m *Manager) GetTeammateState(agentID string) *TeammateState
GetTeammateState returns a snapshot of a teammate's state.
func (*Manager) KillTeammate ¶
KillTeammate forcefully terminates a teammate.
func (*Manager) LeadAgentID ¶
LeadAgentID returns the lead agent's ID.
func (*Manager) ListTeammates ¶
func (m *Manager) ListTeammates() []*TeammateState
ListTeammates returns all non-leader teammates sorted alphabetically by agent name.
func (*Manager) SendMessage ¶
SendMessage sends a message to a specific teammate's mailbox.
func (*Manager) SetHandlersFactory ¶
func (m *Manager) SetHandlersFactory(f func(workerName, workerColor string) []adk.ChatModelAgentMiddleware)
SetHandlersFactory sets the factory that creates agent middleware handlers for teammates.
func (*Manager) SetTuiProgram ¶
SetTuiProgram sets the TUI program reference on the manager (called after RunTUI).
func (*Manager) ShutdownTeammate ¶
ShutdownTeammate sends a shutdown request to a teammate.
func (*Manager) SpawnTeammate ¶
SpawnTeammate starts a new teammate goroutine.
type ManagerDeps ¶
type ManagerDeps struct {
TuiProgram *tea.Program
// EnvFactory creates an isolated Env (any = *tools.Env) given a working directory.
EnvFactory func(cwd string) any
// ToolBuilder returns tools for a given Env and agent type.
ToolBuilder func(env any, agentType string) []tool.BaseTool
// ModelFactory returns a chat model for the given model name, or nil for default.
ModelFactory func(ctx context.Context, modelName string) (any, error)
// DefaultModel is the default chat model to use.
DefaultModel any // model.ToolCallingChatModel
PromptBuilder func(agentType, pwd, platform string) string
ApprovalFunc func(ctx context.Context, toolName, toolArgs string) (bool, error)
// HandlersFactory returns agent middleware handlers (including approval) for a teammate.
// The workerName and workerColor are used to tag approval prompts.
HandlersFactory func(workerName, workerColor string) []adk.ChatModelAgentMiddleware
// LeaderSessionUUID is used to store teammate transcripts under the leader's session.
LeaderSessionUUID string
// Tracer is the optional Langfuse tracer for recording teammate agent spans.
Tracer *telemetry.LangfuseTracer
}
ManagerDeps holds dependencies injected into the TeamManager. The EnvFactory and ToolBuilder use any for Env to avoid import cycles with tools package.
type SetTeamManagerMsg ¶
type SetTeamManagerMsg struct {
Manager *Manager
}
SetTeamManagerMsg is sent to the TUI to wire the team manager after program start.
type SpawnConfig ¶
type SpawnConfig struct {
Name string
Prompt string
AgentType string // "explore", "coder", "general"
Model string // optional model override
Cwd string // optional working directory
Permission string // "normal", "plan", "auto"
}
SpawnConfig holds configuration for spawning a new teammate.
type TeamFile ¶
type TeamFile struct {
Name string `json:"name"`
Description string `json:"description,omitempty"`
CreatedAt time.Time `json:"created_at"`
LeadAgentID string `json:"lead_agent_id"`
Members []TeamMember `json:"members"`
}
TeamFile is the persistent team state, stored at ~/.jcode/teams/{name}/team.json.
type TeamMember ¶
type TeamMember struct {
AgentID string `json:"agent_id"` // "{name}@{team}"
Name string `json:"name"` // display name
AgentType string `json:"agent_type,omitempty"` // "explorer", "coder", etc.
Model string `json:"model,omitempty"` // model override
Prompt string `json:"prompt,omitempty"` // initial task prompt
Color string `json:"color,omitempty"` // TUI color
Cwd string `json:"cwd"` // working directory
JoinedAt time.Time `json:"joined_at"` // when the agent joined
IsActive bool `json:"is_active"` // currently active?
Permission string `json:"permission,omitempty"` // "normal", "plan", "auto"
}
TeamMember represents a single agent in the team.
type TeammateIdentity ¶
TeammateIdentity holds the identity info for a running teammate.
func GetTeammateIdentity ¶
func GetTeammateIdentity(ctx context.Context) (TeammateIdentity, bool)
GetTeammateIdentity retrieves the teammate identity from the context.
type TeammateMessage ¶
type TeammateMessage struct {
From string `json:"from"`
Text string `json:"text"`
Summary string `json:"summary,omitempty"`
Timestamp time.Time `json:"timestamp"`
Read bool `json:"read"`
Color string `json:"color,omitempty"`
}
TeammateMessage is a single message stored in a teammate's mailbox file.
type TeammateMessageMsg ¶
type TeammateMessageMsg struct {
AgentID string
Role string // "assistant", "tool_call", "tool_result", "user"
Content string
From string // set when Role == "user" — who sent the message
ToolName string // set when Role == "tool_call" or "tool_result"
ToolArgs string // set when Role == "tool_call"
ToolErr string // set when Role == "tool_result" and there was an error
}
TeammateMessageMsg notifies the TUI of a new message from a teammate.
type TeammateProgressMsg ¶
TeammateProgressMsg notifies the TUI of teammate progress.
type TeammateSpawnedMsg ¶
TeammateSpawnedMsg notifies the TUI that a new teammate has started.
type TeammateState ¶
type TeammateState struct {
Identity TeammateIdentity
TaskID string
Status TeammateStatus
Env any // *tools.Env, kept as any to avoid import cycle
Cancel context.CancelFunc
WorkCancel context.CancelFunc
History []adk.Message // full conversation history across turns (analogous to Claude Code's allMessages)
Messages []*schema.Message // capped at maxTeammateMessages for UI display only
Pending []string // pending user messages from TUI input
Progress *AgentProgress
Recorder *session.Recorder // per-teammate session recorder (JSONL)
IsIdle bool
ShutdownReq bool
Error string
StartedAt time.Time
EvictAfter *time.Time
Prompt string
Model string
AgentType string
Permission string
TokenUsage *internalmodel.TokenUsage
}
TeammateState holds the runtime state of a running teammate.
type TeammateStatus ¶
type TeammateStatus string
TeammateStatus represents the lifecycle state of a running teammate.
const ( StatusPending TeammateStatus = "pending" StatusRunning TeammateStatus = "running" StatusIdle TeammateStatus = "idle" StatusCompleted TeammateStatus = "completed" StatusFailed TeammateStatus = "failed" StatusKilled TeammateStatus = "killed" )
func (TeammateStatus) IsTerminal ¶
func (s TeammateStatus) IsTerminal() bool
IsTerminal returns true for states that represent a finished agent.
type TeammateStatusMsg ¶
type TeammateStatusMsg struct {
AgentID string
Status TeammateStatus
Error string
}
TeammateStatusMsg notifies the TUI of a teammate status change.
type TeammateTokenUpdateMsg ¶
TeammateTokenUpdateMsg notifies the TUI of a teammate's token usage update.