Documentation
¶
Index ¶
- Variables
- func ContextWithRuntime(ctx context.Context, rt Runtime) context.Context
- func Register(role string, factory FactoryFunc)
- type Agent
- type AgentDef
- type DefaultRegistry
- type Duration
- type FactoryFunc
- type Input
- type Message
- type MockRuntime
- func (m *MockRuntime) Close()
- func (m *MockRuntime) GetRecvCalls() []string
- func (m *MockRuntime) GetSendCalls() []SendCall
- func (m *MockRuntime) Recv(source string) (<-chan *Message, error)
- func (m *MockRuntime) Send(target string, msg *Message) error
- func (m *MockRuntime) SendMessage(source string, msg *Message)
- func (m *MockRuntime) SetRecvError(err error)
- func (m *MockRuntime) SetSendError(err error)
- type NotImplementedError
- type Output
- type Registry
- type Runtime
- type RuntimeKey
- type SendCall
- type Tool
Constants ¶
This section is empty.
Variables ¶
var ErrAgentNotFound = errors.New("agent not found")
ErrAgentNotFound is returned when an agent is not found in the runtime
var ErrRuntimeNotFound = errors.New("runtime not found in context")
ErrRuntimeNotFound is returned when runtime is not found in context
Functions ¶
func ContextWithRuntime ¶
ContextWithRuntime creates a context with the given runtime
func Register ¶
func Register(role string, factory FactoryFunc)
Register registers a factory with the default registry
Types ¶
type Agent ¶
type Agent interface {
// Name returns the unique identifier for this agent instance
Name() string
// Role returns the agent type/role (e.g., "react", "classifier", "planner")
Role() string
// Start runs the agent asynchronously (e.g., listening on inputs)
// Returns when context is canceled or agent encounters fatal error
Start(ctx context.Context) error
// Execute performs synchronous request-response execution
// Used by orchestration patterns for direct invocation
Execute(ctx context.Context, input *Message) (*Message, error)
// Stop gracefully shuts down the agent
Stop(ctx context.Context) error
// Ready returns true if the agent is ready to accept requests
Ready() bool
}
Agent interface supports both synchronous (Execute) and asynchronous (Start) execution. Agents can implement one or both methods depending on their use case.
func CreateAgent ¶
CreateAgent creates an agent using the default registry
type AgentDef ¶
type AgentDef struct {
Name string `yaml:"name"`
Role string `yaml:"role"`
Interval Duration `yaml:"interval,omitempty"`
Listen string `yaml:"listen,omitempty"`
Inputs []Input `yaml:"inputs,omitempty"`
Outputs []Output `yaml:"outputs,omitempty"`
Model string `yaml:"model,omitempty"`
Prompt string `yaml:"prompt,omitempty"`
Tools []Tool `yaml:"tools,omitempty"` // Deprecated: use MCPServers
MCPServers []string `yaml:"mcp_servers,omitempty"` // MCP server names
Extra map[string]any `yaml:",inline"`
}
func TestAgentDef ¶
TestAgentDef creates a test AgentDef with sensible defaults
type DefaultRegistry ¶
type DefaultRegistry struct {
// contains filtered or unexported fields
}
DefaultRegistry is the global registry implementation
func NewRegistry ¶
func NewRegistry() *DefaultRegistry
NewRegistry creates a new registry instance (useful for testing)
func (*DefaultRegistry) GetFactory ¶
func (r *DefaultRegistry) GetFactory(role string) (FactoryFunc, bool)
func (*DefaultRegistry) Register ¶
func (r *DefaultRegistry) Register(role string, factory FactoryFunc)
type Duration ¶
func (*Duration) UnmarshalText ¶
type FactoryFunc ¶
Registry for agent factory functions
func GetFactory ¶
func GetFactory(role string) (FactoryFunc, bool)
GetFactory retrieves a factory from the default registry
type MockRuntime ¶
type MockRuntime struct {
// contains filtered or unexported fields
}
MockRuntime is a mock implementation of the Runtime interface for testing
func (*MockRuntime) GetRecvCalls ¶
func (m *MockRuntime) GetRecvCalls() []string
GetRecvCalls returns all recorded Recv calls
func (*MockRuntime) GetSendCalls ¶
func (m *MockRuntime) GetSendCalls() []SendCall
GetSendCalls returns all recorded Send calls
func (*MockRuntime) Recv ¶
func (m *MockRuntime) Recv(source string) (<-chan *Message, error)
Recv implements Runtime.Recv
func (*MockRuntime) Send ¶
func (m *MockRuntime) Send(target string, msg *Message) error
Send implements Runtime.Send
func (*MockRuntime) SendMessage ¶
func (m *MockRuntime) SendMessage(source string, msg *Message)
SendMessage sends a message to a channel (for testing)
func (*MockRuntime) SetRecvError ¶
func (m *MockRuntime) SetRecvError(err error)
SetRecvError sets an error to return from Recv
func (*MockRuntime) SetSendError ¶
func (m *MockRuntime) SetSendError(err error)
SetSendError sets an error to return from Send
type NotImplementedError ¶
NotImplementedError is returned when a method is not implemented by an agent
func (*NotImplementedError) Error ¶
func (e *NotImplementedError) Error() string
type Registry ¶
type Registry interface {
Register(role string, factory FactoryFunc)
GetFactory(role string) (FactoryFunc, bool)
}
Registry interface allows for testable registry implementations
type Runtime ¶
type Runtime interface {
// Send sends a message to a target agent asynchronously
Send(target string, msg *Message) error
// Recv returns a channel to receive messages from a source agent
Recv(source string) (<-chan *Message, error)
// Call invokes an agent synchronously and waits for response
// Used by orchestration patterns for request-response execution
Call(ctx context.Context, target string, input *Message) (*Message, error)
// CallParallel invokes multiple agents concurrently and returns all results
// Execution continues even if some agents fail (partial results returned)
CallParallel(ctx context.Context, targets []string, input *Message) (map[string]*Message, map[string]error)
// Broadcast sends a message to all registered agents asynchronously
Broadcast(msg *Message) error
// Register registers an agent instance with the runtime
Register(agent Agent) error
// Unregister removes an agent from the runtime
Unregister(name string) error
// Get retrieves a registered agent by name
Get(name string) (Agent, error)
// List returns all registered agent names
List() []string
// Start starts the runtime (e.g., gRPC server for distributed mode)
Start(ctx context.Context) error
// Stop gracefully shuts down the runtime
Stop(ctx context.Context) error
}
Runtime interface provides agent execution and message passing capabilities. Supports both local (single binary) and distributed (gRPC) deployment modes.
func MustRuntimeFromContext ¶
MustRuntimeFromContext extracts the Runtime from context and panics if not found. Deprecated: Use RuntimeFromContext instead and handle the error appropriately. This function is maintained for backward compatibility but should be avoided in new code as panics can cause unexpected application crashes.
type RuntimeKey ¶
type RuntimeKey struct{}