agent

package
v0.0.1-beta1 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CONFIG_SECTION         = "llm"
	DEFAULT_CONTEXT_TOKENS = 8192
	DEFAULT_RESERVE_TOKENS = 1024
	DEFAULT_SOFT_TOKENS    = 800
	DEFAULT_KEEP_MESSAGES  = 30
)

Variables

This section is empty.

Functions

func EventToJSON

func EventToJSON(event *storage.Event) string

EventToJSON converts an event to JSON

func ParsePriority

func ParsePriority(s string) storage.EventPriority

ParsePriority parses a priority string to EventPriority

Types

type Agent

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

func New

func New(cfg Config) *Agent

func (*Agent) AddPulseEvent

func (a *Agent) AddPulseEvent(title, content string, priority int, channel string) (int64, error)

AddPulseEvent adds a new event to the pulse system priority: 0=critical, 1=high, 2=normal, 3=low

func (*Agent) Chat

func (a *Agent) Chat(messages []Message) string

func (*Agent) GetConfig

func (a *Agent) GetConfig() (apiKey, baseURL, model string)

func (*Agent) GetPulseStatus

func (a *Agent) GetPulseStatus() (map[string]interface{}, error)

GetPulseStatus returns the current status of the pulse system

func (*Agent) MemoryStore

func (a *Agent) MemoryStore() *memory.VectorMemoryStore

func (*Agent) Pulse

func (a *Agent) Pulse() *PulseHandler

Pulse returns the pulse handler if available

func (*Agent) Registry_

func (a *Agent) Registry_() *tools.Registry

func (*Agent) Store

func (a *Agent) Store() *storage.Storage

func (*Agent) ToolSpecs

func (a *Agent) ToolSpecs() []map[string]any

Tool spec for OpenAI-compatible schema

func (*Agent) UpdateConfig

func (a *Agent) UpdateConfig(apiKey, baseURL, model string)

type ChatRequest

type ChatRequest struct {
	Model       string          `json:"model"`
	Messages    []Message       `json:"messages"`
	Temperature float64         `json:"temperature,omitempty"`
	MaxTokens   int             `json:"max_tokens,omitempty"`
	Tools       []rpcproto.Tool `json:"tools,omitempty"`
}

type ChatResponse

type ChatResponse struct {
	ID      string   `json:"id"`
	Object  string   `json:"object"`
	Created int64    `json:"created"`
	Model   string   `json:"model"`
	Choices []Choice `json:"choices"`
}

type Choice

type Choice struct {
	Index        int     `json:"index"`
	Message      Message `json:"message"`
	FinishReason string  `json:"finish_reason"`
}

type Config

type Config struct {
	APIKey         string
	BaseURL        string
	Model          string
	Storage        *storage.Storage
	MemoryStore    *memory.VectorMemoryStore
	Registry       *tools.Registry
	AutoRecall     bool
	RecallLimit    int
	RecallMinScore float64
	// Pulse/Heartbeat system configuration
	PulseEnabled bool
	PulseConfig  *PulseConfig
}

Config

type Message

type Message struct {
	Role                 string       `json:"role"`
	Content              string       `json:"content"`
	ToolCalls            []ToolCall   `json:"tool_calls,omitempty"`
	ToolCallID           string       `json:"tool_call_id,omitempty"`
	ToolExecutionResults []ToolResult `json:"tool_results,omitempty"`
}

type PulseArgs

type PulseArgs struct {
	Action   string // "add", "status", "list"
	Title    string
	Content  string
	Priority int // 0-3
	Channel  string
	Limit    int
}

PulseArgs represents arguments for pulse operations

type PulseConfig

type PulseConfig struct {
	Interval     time.Duration // Check interval (default 1 second)
	Enabled      bool          // Enable/disable pulse
	LLMEnabled   bool          // Enable LLM processing
	MaxQueueSize int           // Maximum events in queue
	CleanupHours int           // Hours after which to clear old events
}

PulseConfig holds configuration for the heartbeat system

func DefaultPulseConfig

func DefaultPulseConfig() *PulseConfig

DefaultPulseConfig returns default configuration

type PulseEvent

type PulseEvent struct {
	Event    *storage.Event
	Response string
	Errors   []string
}

PulseEvent represents an event to be processed by the heartbeat system

type PulseHandler

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

PulseHandler handles the heartbeat/pulse system

func NewPulseHandler

func NewPulseHandler(storage *storage.Storage, config *PulseConfig) *PulseHandler

NewPulseHandler creates a new pulse handler

func (*PulseHandler) AddEvent

func (p *PulseHandler) AddEvent(title, content string, priority int, channel string) (int64, error)

AddEvent adds a new event to the pulse system

func (*PulseHandler) GetStatus

func (p *PulseHandler) GetStatus() map[string]interface{}

GetStatus returns the current status of the pulse system

func (*PulseHandler) IsProcessing

func (p *PulseHandler) IsProcessing() bool

IsProcessing returns whether currently processing an event

func (*PulseHandler) IsRunning

func (p *PulseHandler) IsRunning() bool

IsRunning returns whether the pulse is running

func (*PulseHandler) SetBroadcastCallback

func (p *PulseHandler) SetBroadcastCallback(cb func(string, int) error)

SetBroadcastCallback sets the callback for broadcasting messages

func (*PulseHandler) SetEventCallback

func (p *PulseHandler) SetEventCallback(cb func(*PulseEvent))

SetEventCallback sets the callback for event processing

func (*PulseHandler) SetLLMCallback

func (p *PulseHandler) SetLLMCallback(cb func(string) (string, error))

SetLLMCallback sets the callback for LLM processing

func (*PulseHandler) Start

func (p *PulseHandler) Start()

Start starts the heartbeat system

func (*PulseHandler) Stop

func (p *PulseHandler) Stop()

Stop stops the heartbeat system

type PulseReply

type PulseReply struct {
	Result  string
	EventID int64
	Status  string
}

PulseReply represents the result of pulse operations

type RPCService

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

func NewRPCService

func NewRPCService(a *Agent) *RPCService

func (*RPCService) Chat

func (s *RPCService) Chat(args rpcproto.ChatArgs, reply *rpcproto.ChatReply) error

func (*RPCService) MemoryGet

func (s *RPCService) MemoryGet(args rpcproto.MemoryGetArgs, reply *rpcproto.ToolResultReply) error

func (*RPCService) MemorySearch

func (s *RPCService) MemorySearch(args rpcproto.MemorySearchArgs, reply *rpcproto.ToolResultReply) error

func (*RPCService) MemoryStore

func (s *RPCService) MemoryStore(args rpcproto.MemoryStoreArgs, reply *rpcproto.ToolResultReply) error

func (*RPCService) PulseAdd

func (s *RPCService) PulseAdd(args PulseArgs, reply *PulseReply) error

PulseAdd adds a new pulse event

func (*RPCService) PulseStatus

func (s *RPCService) PulseStatus(args struct{}, reply *PulseReply) error

PulseStatus returns the current pulse system status

func (*RPCService) Stats

func (s *RPCService) Stats(_ struct{}, reply *rpcproto.StatsReply) error

type Session

type Session struct {
	ID              string
	Key             string    // Unique session key (e.g., "main", "cron:job-123", "telegram:user-456")
	AgentID         string    // Agent instance ID
	Messages        []Message // Conversation history
	CreatedAt       time.Time
	UpdatedAt       time.Time
	TotalTokens     int
	CompactionCount int
	ContextTokens   int
	IsActive        bool
	Metadata        map[string]interface{}
	// contains filtered or unexported fields
}

Session represents a conversation session

type SessionInfo

type SessionInfo struct {
	Key          string    `json:"key"`
	AgentID      string    `json:"agentId"`
	MessageCount int       `json:"messageCount"`
	TotalTokens  int       `json:"totalTokens"`
	CreatedAt    time.Time `json:"createdAt"`
	UpdatedAt    time.Time `json:"updatedAt"`
	IsActive     bool      `json:"isActive"`
}

SessionInfo returns basic session info for listing

type SessionManager

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

SessionManager manages multiple sessions

func NewSessionManager

func NewSessionManager(store *storage.Storage, defaultAgentID string) *SessionManager

NewSessionManager creates a new session manager

func (*SessionManager) AddMessage

func (sm *SessionManager) AddMessage(key string, msg Message) error

AddMessage adds a message to a session

func (*SessionManager) ClearSession

func (sm *SessionManager) ClearSession(key string) error

ClearSession clears a session's messages

func (*SessionManager) CreateSession

func (sm *SessionManager) CreateSession(key, agentID string) (*Session, error)

CreateSession creates a new session

func (*SessionManager) CreateSessionForChannel

func (sm *SessionManager) CreateSessionForChannel(channelType, channelID, agentID string) (*Session, error)

CreateSessionForChannel creates a session for a specific channel

func (*SessionManager) GetMessages

func (sm *SessionManager) GetMessages(key string) ([]Message, error)

GetMessages returns all messages in a session

func (*SessionManager) GetOrCreateChannelSession

func (sm *SessionManager) GetOrCreateChannelSession(channelType, channelID, agentID string) (*Session, error)

GetOrCreateChannelSession gets or creates a session for a channel

func (*SessionManager) GetOrCreateSession

func (sm *SessionManager) GetOrCreateSession(key, agentID string) (*Session, error)

GetOrCreateSession returns existing session or creates new one

func (*SessionManager) GetSession

func (sm *SessionManager) GetSession(key string) (*Session, bool)

GetSession returns a session by key

func (*SessionManager) GetSessionInfo

func (sm *SessionManager) GetSessionInfo(key string) (*SessionInfo, error)

GetSessionInfo returns session info

func (*SessionManager) ListSessionInfos

func (sm *SessionManager) ListSessionInfos() []SessionInfo

ListSessionInfos returns all session infos

func (*SessionManager) ListSessions

func (sm *SessionManager) ListSessions() []*Session

ListSessions returns all active sessions

func (*SessionManager) LoadSessions

func (sm *SessionManager) LoadSessions() error

LoadSessions loads sessions from database

func (*SessionManager) RemoveSession

func (sm *SessionManager) RemoveSession(key string) error

RemoveSession removes a session

type SessionManagerWithRPC

type SessionManagerWithRPC struct {
	*SessionManager
	// contains filtered or unexported fields
}

SessionManagerWithRPC extends SessionManager with RPC capabilities

func NewSessionManagerWithRPC

func NewSessionManagerWithRPC(store *storage.Storage, defaultAgentID string) *SessionManagerWithRPC

NewSessionManagerWithRPC creates a new session manager with RPC

func (*SessionManagerWithRPC) ForwardToAgent

func (sm *SessionManagerWithRPC) ForwardToAgent(targetAgentID string, messages []Message) (string, error)

ForwardToAgent forwards a message to another agent via RPC

func (*SessionManagerWithRPC) GetAgentRPC

func (sm *SessionManagerWithRPC) GetAgentRPC(agentID string) (*SessionRPCClient, bool)

GetAgentRPC returns an RPC client for an agent

func (*SessionManagerWithRPC) RegisterAgentRPC

func (sm *SessionManagerWithRPC) RegisterAgentRPC(agentID, address string)

RegisterAgentRPC registers an RPC client for an agent

type SessionRPCClient

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

SessionRPCClient represents a client for making RPC calls to other agents

func NewSessionRPCClient

func NewSessionRPCClient(agentID, address string) *SessionRPCClient

NewSessionRPCClient creates a new session RPC client

func (*SessionRPCClient) Connect

func (c *SessionRPCClient) Connect() error

Connect connects to the agent

func (*SessionRPCClient) IsConnected

func (c *SessionRPCClient) IsConnected() bool

IsConnected returns connection status

type ToolCall

type ToolCall struct {
	ID       string `json:"id"`
	Type     string `json:"type"`
	Function struct {
		Name      string `json:"name"`
		Arguments string `json:"arguments"`
	} `json:"function"`
}

type ToolResponse

type ToolResponse struct {
	ToolResults []ToolResult `json:"tool_results"`
}

type ToolResult

type ToolResult struct {
	ID     string `json:"id"`
	Type   string `json:"type"`
	Result any    `json:"result"`
}

Jump to

Keyboard shortcuts

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