agent

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package agent provides the core interfaces and types for AI agent communication. It defines the Agent interface that all agent implementations must satisfy, along with message types and configuration structures.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClearAgents

func ClearAgents()

func RegisterFactory

func RegisterFactory(agentType string, factory Factory)

Types

type Agent

type Agent interface {
	// GetID returns the unique identifier of the agent
	GetID() string
	// GetName returns the display name of the agent
	GetName() string
	// GetType returns the agent type (e.g., "claude", "gemini")
	GetType() string
	// GetModel returns the specific model being used
	GetModel() string
	// GetRateLimit returns the rate limit in requests per second (0 = unlimited)
	GetRateLimit() float64
	// GetRateLimitBurst returns the burst size for rate limiting
	GetRateLimitBurst() int
	// Initialize configures the agent with the provided configuration
	Initialize(config AgentConfig) error
	// SendMessage sends a message to the agent and returns the response
	SendMessage(ctx context.Context, messages []Message) (string, error)
	// StreamMessage sends a message and streams the response to the writer
	StreamMessage(ctx context.Context, messages []Message, writer io.Writer) error
	// Announce returns the agent's join announcement message
	Announce() string
	// IsAvailable checks if the agent's CLI tool is available
	IsAvailable() bool
	// HealthCheck performs a comprehensive health check of the agent
	HealthCheck(ctx context.Context) error
	// GetCLIVersion returns the version of the agent's CLI tool
	GetCLIVersion() string
}

Agent is the core interface that all agent implementations must satisfy. It provides methods for communication, health checking, and metadata access.

func CreateAgent

func CreateAgent(config AgentConfig) (Agent, error)

func GetAgent

func GetAgent(id string) (Agent, bool)

func ListAgents

func ListAgents() []Agent

type AgentConfig

type AgentConfig struct {
	// ID is the unique identifier for this agent instance
	ID string `yaml:"id"`
	// Type is the agent type (e.g., "claude", "gemini", "copilot")
	Type string `yaml:"type"`
	// Name is the display name for the agent
	Name string `yaml:"name"`
	// Prompt is the system prompt that defines the agent's behavior
	Prompt string `yaml:"prompt"`
	// Announcement is the message shown when the agent joins
	Announcement string `yaml:"announcement"`
	// Model is the specific model to use (e.g., "claude-sonnet-4.5")
	Model string `yaml:"model"`
	// Temperature controls randomness in responses (0.0 to 1.0)
	Temperature float64 `yaml:"temperature"`
	// MaxTokens limits the length of generated responses
	MaxTokens int `yaml:"max_tokens"`
	// RateLimit is the maximum requests per second for this agent (0 = unlimited)
	RateLimit float64 `yaml:"rate_limit"`
	// RateLimitBurst is the maximum burst size for rate limiting (default: 1)
	RateLimitBurst int `yaml:"rate_limit_burst"`
	// CustomSettings allows agent-specific configuration options
	CustomSettings map[string]interface{} `yaml:"custom_settings"`
}

AgentConfig defines the configuration for creating and initializing an agent. It supports both standard fields and custom settings for extensibility.

type BaseAgent

type BaseAgent struct {
	// ID is the unique identifier for this agent instance
	ID string
	// Name is the display name
	Name string
	// Type is the agent type
	Type string
	// Config stores the full agent configuration
	Config AgentConfig
	// Announcement is the custom join message
	Announcement string
}

BaseAgent provides a default implementation of common Agent interface methods. Agent implementations can embed BaseAgent to avoid reimplementing basic functionality.

func (*BaseAgent) Announce

func (b *BaseAgent) Announce() string

Announce returns the agent's announcement message. If a custom announcement is set, it is returned; otherwise, a default message is generated using the agent's name.

func (*BaseAgent) GetID

func (b *BaseAgent) GetID() string

GetID returns the unique identifier of the agent.

func (*BaseAgent) GetModel added in v0.0.15

func (b *BaseAgent) GetModel() string

GetModel returns the specific model being used by the agent. If no model is configured, it falls back to the agent type.

func (*BaseAgent) GetName

func (b *BaseAgent) GetName() string

GetName returns the display name of the agent.

func (*BaseAgent) GetRateLimit added in v0.0.16

func (b *BaseAgent) GetRateLimit() float64

GetRateLimit returns the rate limit in requests per second for this agent. A value of 0 means unlimited (no rate limiting).

func (*BaseAgent) GetRateLimitBurst added in v0.0.16

func (b *BaseAgent) GetRateLimitBurst() int

GetRateLimitBurst returns the burst size for rate limiting. This is the maximum number of requests that can be made in a burst.

func (*BaseAgent) GetType

func (b *BaseAgent) GetType() string

GetType returns the agent type (e.g., "claude", "gemini", "copilot").

func (*BaseAgent) Initialize

func (b *BaseAgent) Initialize(config AgentConfig) error

Initialize configures the BaseAgent with the provided configuration. This sets up the basic fields that all agents need.

type Factory

type Factory func() Agent

type Message

type Message struct {
	// AgentID is the unique identifier of the agent or entity that sent the message
	AgentID string
	// AgentName is the display name of the agent
	AgentName string
	// AgentType is the type of agent (e.g., "claude", "gemini", "qoder")
	AgentType string
	// Content is the actual message text
	Content string
	// Timestamp is the Unix timestamp when the message was created
	Timestamp int64
	// Role indicates the message type: "agent", "user", or "system"
	Role string
	// Metrics contains optional performance and cost metrics for agent responses
	Metrics *ResponseMetrics
}

Message represents a single message in an agent conversation. Messages can be sent by agents, users, or the system.

type Registry

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

type ResponseMetrics

type ResponseMetrics struct {
	// Duration is how long the agent took to generate the response
	Duration time.Duration
	// InputTokens is the number of tokens in the input (prompt + conversation history)
	InputTokens int
	// OutputTokens is the number of tokens in the agent's response
	OutputTokens int
	// TotalTokens is InputTokens + OutputTokens
	TotalTokens int
	// Model is the specific model used by the agent
	Model string
	// Cost is the estimated monetary cost of the API call in USD
	Cost float64
}

ResponseMetrics captures performance and cost information for an agent response. This is used for monitoring, billing, and optimization purposes.

Jump to

Keyboard shortcuts

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