Documentation
¶
Overview ¶
Package agent implements the worker pool for managing colony agents, including spawn, lifecycle, and task distribution.
Index ¶
- type Agent
- type AgentNotFoundError
- type Caste
- type DuplicateAgentError
- type Pool
- type PoolOption
- type Registry
- type SpawnEntry
- type SpawnTree
- func (st *SpawnTree) Active() []SpawnEntry
- func (st *SpawnTree) Parse() ([]SpawnEntry, error)
- func (st *SpawnTree) Persist() error
- func (st *SpawnTree) RecordSpawn(parent, caste, name, task string, depth int) error
- func (st *SpawnTree) ToJSON() ([]byte, error)
- func (st *SpawnTree) UpdateStatus(name string, status string) error
- type Trigger
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Agent ¶
type Agent interface {
// Name returns the unique identifier for this agent.
Name() string
// Caste returns the role category of this agent.
Caste() Caste
// Triggers returns the event patterns that activate this agent.
Triggers() []Trigger
// Execute runs the agent's logic for the given event.
Execute(ctx context.Context, event events.Event) error
}
Agent is the interface every colony agent must implement.
type AgentNotFoundError ¶
type AgentNotFoundError struct {
Name string
}
AgentNotFoundError is returned when looking up an agent that does not exist.
func (*AgentNotFoundError) Error ¶
func (e *AgentNotFoundError) Error() string
type Caste ¶
type Caste string
Caste represents the role category of an agent, matching the shell caste names.
const ( CasteBuilder Caste = "builder" CasteWatcher Caste = "watcher" CasteScout Caste = "scout" CasteOracle Caste = "oracle" CasteCurator Caste = "curator" CasteArchitect Caste = "architect" CasteRouteSetter Caste = "route_setter" CasteColonizer Caste = "colonizer" CasteArchaeologist Caste = "archaeologist" )
type DuplicateAgentError ¶
type DuplicateAgentError struct {
Name string
}
DuplicateAgentError is returned when registering an agent with a name that is already present in the registry.
func (*DuplicateAgentError) Error ¶
func (e *DuplicateAgentError) Error() string
type Pool ¶
type Pool struct {
// contains filtered or unexported fields
}
Pool dispatches events from the bus to matching agents with bounded concurrency. It subscribes to the event bus, matches incoming events against registered agents, and runs matching agents using an errgroup with a configurable goroutine limit.
func NewPool ¶
NewPool creates a worker pool that dispatches events to agents in the registry. The pool subscribes to all events ("*") on the bus. Returns an error if registry or bus is nil.
func (*Pool) SetConcurrency ¶
SetConcurrency updates the maximum goroutine count for subsequent event dispatches.
func (*Pool) Start ¶
Start begins consuming events from the bus and dispatching them to matching agents. It blocks until the provided context is cancelled or the event channel is closed. For each event, matching agents are found via registry.Match and run concurrently using errgroup with SetLimit to bound concurrency.
type PoolOption ¶
type PoolOption func(*Pool)
PoolOption configures a Pool during construction.
func WithMaxGoroutines ¶
func WithMaxGoroutines(n int) PoolOption
WithMaxGoroutines sets the maximum number of concurrent agent executions. Panics if n <= 0.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry manages registered agents with thread-safe access.
func (*Registry) Get ¶
Get retrieves an agent by name. Returns an error if no agent with the given name exists.
type SpawnEntry ¶
type SpawnEntry struct {
Timestamp string // Field 1: ISO 8601 UTC (2006-01-02T15:04:05Z)
ParentName string // Field 2: parent agent name
Caste string // Field 3: caste name (builder, watcher, etc.)
AgentName string // Field 4: agent name
Task string // Field 5: task description
Depth int // Field 6: spawn depth
Status string // Field 7: "spawned", "active", "completed", "failed", "blocked"
}
SpawnEntry represents a single agent spawn record, matching the shell spawn-tree.txt format with exactly 7 pipe-delimited fields.
type SpawnTree ¶
type SpawnTree struct {
// contains filtered or unexported fields
}
SpawnTree tracks running agents in the same pipe-delimited format as the shell spawn-tree.txt, enabling Go and shell to coexist.
func NewSpawnTree ¶
NewSpawnTree creates a spawn tree backed by the given store. filePath defaults to "spawn-tree.txt" if empty. Existing entries are loaded from the file on creation (graceful: empty if missing).
func (*SpawnTree) Active ¶
func (st *SpawnTree) Active() []SpawnEntry
Active returns entries with Status "spawned" or "active".
func (*SpawnTree) Parse ¶
func (st *SpawnTree) Parse() ([]SpawnEntry, error)
Parse reads the file and returns all spawn entries with statuses merged from completion lines.
func (*SpawnTree) RecordSpawn ¶
RecordSpawn creates a new spawn entry and persists it to the file.