agent

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EstimateMessageTokens

func EstimateMessageTokens(msg provider.Message) int

func EstimateMessagesTokens

func EstimateMessagesTokens(messages []provider.Message) int

func EstimateSystemPromptTokens

func EstimateSystemPromptTokens(prompt string) int

func EstimateTokens

func EstimateTokens(text string) int

func GetContextWindow

func GetContextWindow(models []provider.ModelInfo, modelID string) int

func IsApproachingLimit

func IsApproachingLimit(usedTokens, contextWindow int, threshold float64) bool

Types

type Agent

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

Agent is the core AI coding agent that runs the conversation loop.

func New

func New(
	client *llm.Client,
	store session.SessionStore,
	registry tool.ToolRegistry,
	perm *permission.Service,
	bus event.EventBus,
) *Agent

New creates a new Agent.

func (*Agent) Run

func (a *Agent) Run(ctx context.Context, sessionID string, userPrompt string, config Config) error

Run executes the agent loop for a user prompt. It creates/reuses a session, runs the LLM, executes tools, and repeats until the LLM stops requesting tool calls.

func (*Agent) WithSkills

func (a *Agent) WithSkills(registry skill.SkillRegistry)

type Config

type Config struct {
	Model         string
	MaxTokens     int
	SystemPrompt  string
	MaxIterations int
	ToolsEnabled  bool
}

Config holds agent configuration.

type ContextManager

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

func NewContextManager

func NewContextManager(store session.SessionStore, bus event.EventBus, client *llm.Client) *ContextManager

func (*ContextManager) CheckAndCompress

func (cm *ContextManager) CheckAndCompress(ctx context.Context, sessionID string, model string, messages []provider.Message, systemPrompt string) ([]provider.Message, error)

func (*ContextManager) EstimateCurrentUsage

func (cm *ContextManager) EstimateCurrentUsage(messages []provider.Message, systemPrompt string) int

func (*ContextManager) GetTokenUsage

func (cm *ContextManager) GetTokenUsage(sessionID string) TokenUsageData

func (*ContextManager) TrackUsage

func (cm *ContextManager) TrackUsage(sessionID string, usage provider.Usage)

type ForwardingEventBus

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

func NewForwardingEventBus

func NewForwardingEventBus(parent event.EventBus, prefix string) *ForwardingEventBus

func (*ForwardingEventBus) Close

func (f *ForwardingEventBus) Close()

func (*ForwardingEventBus) Publish

func (f *ForwardingEventBus) Publish(evt event.Event)

func (*ForwardingEventBus) Subscribe

func (f *ForwardingEventBus) Subscribe(event.EventHandler) func()

type SilentEventBus

type SilentEventBus struct{}

func (*SilentEventBus) Close

func (s *SilentEventBus) Close()

func (*SilentEventBus) Publish

func (s *SilentEventBus) Publish(event.Event)

func (*SilentEventBus) Subscribe

func (s *SilentEventBus) Subscribe(event.EventHandler) func()

type SubAgent

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

func NewSubAgent

func NewSubAgent(
	prov provider.Provider,
	store session.SessionStore,
	config SubAgentConfig,
	allTools []tool.Tool,
) *SubAgent

func (*SubAgent) HasTool

func (sa *SubAgent) HasTool(name string) bool

func (*SubAgent) Run

func (sa *SubAgent) Run(ctx context.Context, task string) (string, error)

func (*SubAgent) SetParentBus

func (sa *SubAgent) SetParentBus(bus event.EventBus)

func (*SubAgent) ToolCount

func (sa *SubAgent) ToolCount() int

type SubAgentConfig

type SubAgentConfig struct {
	Name          string
	Description   string
	SystemPrompt  string
	AllowedTools  []string
	MaxIterations int
	Model         string
	MaxTokens     int
}

type SummarizeData

type SummarizeData struct {
	OriginalMessages int `json:"original_messages"`
	SummaryTokens    int `json:"summary_tokens"`
}

type Summarizer

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

func NewSummarizer

func NewSummarizer(client chatCaller, bus event.EventBus) *Summarizer

func (*Summarizer) Summarize

func (s *Summarizer) Summarize(ctx context.Context, sessionID string, model string, messages []provider.Message) (string, error)

type TokenUsageData

type TokenUsageData struct {
	InputTokens  int `json:"input_tokens"`
	OutputTokens int `json:"output_tokens"`
	TotalTokens  int `json:"total_tokens"`
	CachedTokens int `json:"cached_tokens,omitempty"`
}

Jump to

Keyboard shortcuts

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