team

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const TeamLeadName = "team-lead"

TeamLeadName is the canonical name for the team leader.

Variables

This section is empty.

Functions

func FormatAgentID

func FormatAgentID(name, teamName string) string

FormatAgentID returns the canonical agent ID: "name@team".

func GetAgentName

func GetAgentName(ctx context.Context) string

GetAgentName returns the agent name from the context, or TeamLeadName if not a teammate.

func IsShutdownRequest

func IsShutdownRequest(text string) bool

IsShutdownRequest checks if a message text is a shutdown request.

func IsTeammate

func IsTeammate(ctx context.Context) bool

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

func NewMailbox(teamName, sessionID string) *Mailbox

NewMailbox creates a new mailbox scoped to a specific session. Path: ~/.jcode/teams/{team}/inboxes/{sessionID}/

func (*Mailbox) Clear

func (mb *Mailbox) Clear(agentName string) error

Clear removes all messages from an agent's inbox.

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) MarkRead

func (mb *Mailbox) MarkRead(agentName string, index int) error

MarkRead marks a specific message as read by index.

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

func (m *Manager) BroadcastMessage(from, message, summary string) (int, error)

BroadcastMessage sends a message to all teammates except the sender.

func (*Manager) CreateTeam

func (m *Manager) CreateTeam(name, description string) error

CreateTeam initializes a new team with the caller as leader.

func (*Manager) DissolveTeam

func (m *Manager) DissolveTeam(ctx context.Context) error

DissolveTeam shuts down all teammates and cleans up the team.

func (*Manager) EnqueueUserMessage

func (m *Manager) EnqueueUserMessage(agentID, message string)

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) HasTeam

func (m *Manager) HasTeam() bool

HasTeam returns true if a team is currently active.

func (*Manager) KillTeammate

func (m *Manager) KillTeammate(name string) error

KillTeammate forcefully terminates a teammate.

func (*Manager) LeadAgentID

func (m *Manager) LeadAgentID() string

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

func (m *Manager) SendMessage(to, from, message, summary string) error

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

func (m *Manager) SetTuiProgram(p *tea.Program)

SetTuiProgram sets the TUI program reference on the manager (called after RunTUI).

func (*Manager) ShutdownTeammate

func (m *Manager) ShutdownTeammate(name, reason string) error

ShutdownTeammate sends a shutdown request to a teammate.

func (*Manager) SpawnTeammate

func (m *Manager) SpawnTeammate(ctx context.Context, cfg SpawnConfig) (string, error)

SpawnTeammate starts a new teammate goroutine.

func (*Manager) TeamName

func (m *Manager) TeamName() string

TeamName returns the current team name.

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

type TeammateIdentity struct {
	AgentID   string
	AgentName string
	TeamName  string
	Color     string
}

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

type TeammateProgressMsg struct {
	AgentID   string
	ToolName  string
	ToolCount int
}

TeammateProgressMsg notifies the TUI of teammate progress.

type TeammateSpawnedMsg

type TeammateSpawnedMsg struct {
	AgentID string
	Name    string
	Color   string
	Prompt  string
}

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

type TeammateTokenUpdateMsg struct {
	AgentID     string
	TotalTokens int64
}

TeammateTokenUpdateMsg notifies the TUI of a teammate's token usage update.

Jump to

Keyboard shortcuts

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