agent

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package agent defines the core agent interface and types

Package agent contains mock implementations for testing

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Agent

type Agent interface {
	// Identity
	ID() string
	Name() string
	Type() string // "opencode", "claude", etc.

	// Location
	Directory() string
	ProjectID() string

	// Hierarchy
	ParentID() string
	IsBackground() bool

	// Status
	Status() Status
	StartTime() time.Time
	LastActivity() time.Time

	// Session data
	Output() io.Reader   // Stream of output
	CurrentTask() string // What the agent is working on
	Metrics() Metrics    // Performance metrics
	LastError() error    // Last error if any

	// Control
	SendInput(input string) error
	Terminate() error
	Pause() error
	Resume() error
}

Agent represents a single AI agent instance

type Event

type Event struct {
	Type      EventType
	AgentID   string
	Agent     Agent
	Timestamp time.Time
	Data      interface{}
	Error     error
}

Event represents an agent lifecycle event

type EventType

type EventType int

EventType represents the type of agent event

const (
	EventAgentDiscovered EventType = iota
	EventAgentUpdated
	EventAgentStarted
	EventAgentCompleted
	EventAgentErrored
	EventAgentContextLimit
	EventAgentTerminated
	EventAgentPaused
	EventAgentResumed
	EventAgentInput
	EventAgentOutput
)

func (EventType) String

func (e EventType) String() string

type Metrics

type Metrics struct {
	TokensIn           int64         `json:"tokens_in"`
	TokensOut          int64         `json:"tokens_out"`
	EstimatedCost      float64       `json:"estimated_cost"`
	Duration           time.Duration `json:"duration"`
	ActiveTime         time.Duration `json:"active_time"`
	IdleTime           time.Duration `json:"idle_time"`
	ToolCalls          int           `json:"tool_calls"`
	ErrorCount         int           `json:"error_count"`
	TasksCompleted     int           `json:"tasks_completed"`
	TasksFailed        int           `json:"tasks_failed"`
	ContextUtilization float64       `json:"context_utilization"` // 0.0 - 1.0
}

Metrics holds agent performance metrics

type MockAgent

type MockAgent struct {
	MockID           string
	MockName         string
	MockType         string
	MockStatus       Status
	MockDirectory    string
	MockProjectID    string
	MockParentID     string
	MockCurrentTask  string
	MockStartTime    time.Time
	MockLastActivity time.Time
	MockMetrics      Metrics
	MockLastError    error
	MockOutput       []byte

	TerminateCalled bool
	SendInputCalled bool
	LastInput       string
}

MockAgent implements Agent interface for testing

func NewMockAgent

func NewMockAgent(id, name string) *MockAgent

NewMockAgent creates a new mock agent with default values

func (*MockAgent) CurrentTask

func (m *MockAgent) CurrentTask() string

func (*MockAgent) Directory

func (m *MockAgent) Directory() string

func (*MockAgent) ID

func (m *MockAgent) ID() string

Interface implementation

func (*MockAgent) IsBackground

func (m *MockAgent) IsBackground() bool

func (*MockAgent) LastActivity

func (m *MockAgent) LastActivity() time.Time

func (*MockAgent) LastError

func (m *MockAgent) LastError() error

func (*MockAgent) Metrics

func (m *MockAgent) Metrics() Metrics

func (*MockAgent) Name

func (m *MockAgent) Name() string

func (*MockAgent) Output

func (m *MockAgent) Output() io.Reader

func (*MockAgent) ParentID

func (m *MockAgent) ParentID() string

func (*MockAgent) Pause

func (m *MockAgent) Pause() error

func (*MockAgent) ProjectID

func (m *MockAgent) ProjectID() string

func (*MockAgent) Refresh

func (m *MockAgent) Refresh() error

func (*MockAgent) Resume

func (m *MockAgent) Resume() error

func (*MockAgent) SendInput

func (m *MockAgent) SendInput(input string) error

func (*MockAgent) StartTime

func (m *MockAgent) StartTime() time.Time

func (*MockAgent) Status

func (m *MockAgent) Status() Status

func (*MockAgent) Terminate

func (m *MockAgent) Terminate() error

func (*MockAgent) Type

func (m *MockAgent) Type() string

type MockProvider

type MockProvider struct {
	MockAgents   []Agent
	MockEvents   chan Event
	SpawnedAgent *MockAgent
}

MockProvider implements Provider interface for testing

func NewMockProvider

func NewMockProvider() *MockProvider

NewMockProvider creates a new mock provider

func (*MockProvider) AddAgent

func (p *MockProvider) AddAgent(agent Agent)

AddAgent adds an agent to the mock provider

func (*MockProvider) Close

func (p *MockProvider) Close()

Close closes the event channel

func (*MockProvider) Discover

func (p *MockProvider) Discover(ctx context.Context) ([]Agent, error)

func (*MockProvider) SendEvent

func (p *MockProvider) SendEvent(event Event)

SendEvent sends a mock event

func (*MockProvider) Spawn

func (p *MockProvider) Spawn(ctx context.Context, config SpawnConfig) (Agent, error)

func (*MockProvider) Type

func (p *MockProvider) Type() string

func (*MockProvider) Watch

func (p *MockProvider) Watch(ctx context.Context) (<-chan Event, error)

type Provider

type Provider interface {
	// Identity
	Name() string
	Type() string

	// Discovery
	Discover(ctx context.Context) ([]Agent, error)
	Watch(ctx context.Context) (<-chan Event, error)

	// Control
	Spawn(ctx context.Context, config SpawnConfig) (Agent, error)
	Get(id string) (Agent, error)
	List() []Agent
	Terminate(id string) error
	SendInput(id string, input string) error
}

Provider discovers and manages agents of a specific type

type Registry

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

Registry manages multiple agent providers

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates a new provider registry

func (*Registry) DiscoverAll

func (r *Registry) DiscoverAll(ctx context.Context) ([]Agent, error)

DiscoverAll discovers agents from all providers

func (*Registry) Get

func (r *Registry) Get(providerType string) (Provider, bool)

Get returns a provider by type

func (*Registry) List

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

List returns all registered providers

func (*Registry) Register

func (r *Registry) Register(provider Provider)

Register adds a provider to the registry

func (*Registry) WatchAll

func (r *Registry) WatchAll(ctx context.Context) (<-chan Event, error)

WatchAll watches for events from all providers

type SpawnConfig

type SpawnConfig struct {
	Type      string            `json:"type"`
	Name      string            `json:"name"`
	Directory string            `json:"directory"`
	Prompt    string            `json:"prompt"`
	Env       map[string]string `json:"env"`
}

SpawnConfig holds configuration for spawning a new agent

type Status

type Status int

Status represents the current state of an agent

const (
	StatusPending Status = iota
	StatusRunning
	StatusIdle
	StatusCompleted
	StatusErrored
	StatusContextLimit
	StatusCancelled
)

func (Status) Icon

func (s Status) Icon() string

StatusIcon returns the icon for the status

func (Status) String

func (s Status) String() string

Directories

Path Synopsis
providers
opencode
Package opencode provides an agent provider for opencode sessions
Package opencode provides an agent provider for opencode sessions

Jump to

Keyboard shortcuts

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