agent

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2026 License: MIT Imports: 11 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package agent implements the worker pool for managing colony agents, including spawn, lifecycle, and task distribution.

Index

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

func NewPool(registry *Registry, bus *events.Bus, opts ...PoolOption) (*Pool, error)

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

func (p *Pool) SetConcurrency(n int)

SetConcurrency updates the maximum goroutine count for subsequent event dispatches.

func (*Pool) Start

func (p *Pool) Start(ctx context.Context) error

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.

func (*Pool) Stop

func (p *Pool) Stop()

Stop cancels the pool's context and unsubscribes from the event bus.

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 NewRegistry

func NewRegistry() *Registry

NewRegistry creates an empty agent registry.

func (*Registry) Get

func (r *Registry) Get(name string) (Agent, error)

Get retrieves an agent by name. Returns an error if no agent with the given name exists.

func (*Registry) List

func (r *Registry) List() []Agent

List returns all registered agents sorted by name.

func (*Registry) Match

func (r *Registry) Match(topic string) []Agent

Match returns agents whose Triggers match the given topic using events.TopicMatch.

func (*Registry) Register

func (r *Registry) Register(a Agent) error

Register adds an agent to the registry. Returns an error if an agent with the same name is already registered.

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

func NewSpawnTree(store *storage.Store, filePath string) *SpawnTree

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

func (st *SpawnTree) Persist() error

Persist writes all entries to the file via store.AtomicWrite.

func (*SpawnTree) RecordSpawn

func (st *SpawnTree) RecordSpawn(parent, caste, name, task string, depth int) error

RecordSpawn creates a new spawn entry and persists it to the file.

func (*SpawnTree) ToJSON

func (st *SpawnTree) ToJSON() ([]byte, error)

ToJSON returns JSON matching the shell parse_spawn_tree output format.

func (*SpawnTree) UpdateStatus

func (st *SpawnTree) UpdateStatus(name string, status string) error

UpdateStatus finds an entry by agent name and updates its status. It adds a completion line to the file matching the shell's second awk rule.

type Trigger

type Trigger struct {
	// Topic is an event bus topic pattern, e.g. "learning.*".
	Topic string
	// Filter is an optional payload filter (may be nil).
	Filter map[string]any
}

Trigger defines when an agent should be activated.

Directories

Path Synopsis
Package curation implements the memory maintenance system for colony data.
Package curation implements the memory maintenance system for colony data.

Jump to

Keyboard shortcuts

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