agent

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildSystemPrompt added in v0.2.0

func BuildSystemPrompt(projectContext, globalContext string) string

BuildSystemPrompt constructs the complete system prompt with project and global context.

func BuildSystemPromptWithOptions added in v0.4.0

func BuildSystemPromptWithOptions(opts PromptOptions) string

BuildSystemPromptWithOptions constructs the system prompt with rich runtime context.

func FindProjectContext added in v0.2.0

func FindProjectContext(startDir string) (string, string, error)

FindProjectContext scans startDir and parent directories for AGENTS.md, .gocode/AGENTS.md, or docs/AGENTS.md.

func LoadGlobalContext added in v0.2.0

func LoadGlobalContext() (string, string, error)

LoadGlobalContext loads ~/.config/gocode/CONTEXT.md or %APPDATA%\gocode\CONTEXT.md.

Types

type AgentLoop

type AgentLoop struct {
	Registry       *provider.Registry
	Session        *Session
	ToolRegistry   *tools.Registry
	Approval       *tools.ApprovalGate
	ContextManager *ContextManager
	WorkspaceRoot  string
}

func NewAgentLoop

func NewAgentLoop(registry *provider.Registry, session *Session, toolReg *tools.Registry, approval *tools.ApprovalGate) *AgentLoop

func (*AgentLoop) Run

func (a *AgentLoop) Run(ctx context.Context) error

type CommandContext added in v0.4.0

type CommandContext struct {
	Session        *Session
	Registry       *provider.Registry
	ContextManager *ContextManager
	WorkspaceRoot  string
	AskApproval    func(prompt string) bool
}

CommandContext holds the environment and services needed to execute slash commands.

type CommandResult added in v0.4.0

type CommandResult struct {
	Handled bool
	Output  string
	Error   error
	Exit    bool
}

CommandResult represents the outcome of executing a command.

func HandleCommand added in v0.4.0

func HandleCommand(ctx context.Context, cmdCtx CommandContext, input string) CommandResult

HandleCommand processes slash commands (and exit/quit). Returns Handled=true if the input was a command, or Handled=false if it should be sent to the LLM.

type ContextManager

type ContextManager struct {
	MaxTokens int
}

ContextManager manages message history size, truncation, and compaction.

func NewContextManager

func NewContextManager(maxTokens int) *ContextManager

NewContextManager creates a ContextManager with the specified max tokens limit. If maxTokens <= 0, defaults to 8192.

func (*ContextManager) Compact added in v0.4.0

func (cm *ContextManager) Compact(history []provider.Message, keepLastTurns int) []provider.Message

Compact summarizes or compresses the history by retaining the system prompt, a brief summary of omitted turns, and the most recent N turns.

func (*ContextManager) EstimateTokens

func (cm *ContextManager) EstimateTokens(msg provider.Message) int

EstimateTokens calculates an approximate token count for a message.

func (*ContextManager) FormatContextStats added in v0.4.0

func (cm *ContextManager) FormatContextStats(history []provider.Message) string

FormatContextStats returns a formatted status string of token usage.

func (*ContextManager) Truncate

func (cm *ContextManager) Truncate(history []provider.Message) []provider.Message

Truncate enforces MaxTokens while preserving conversation structure: 1. Always preserves the system message (if present). 2. Truncates in whole conversation turns so tool-call / tool-result pairs are never separated. 3. Never leaves an orphaned "tool" message at the beginning of the context. 4. Always retains at least the latest user turn.

type PromptOptions added in v0.4.0

type PromptOptions struct {
	ProjectContext string
	GlobalContext  string
	WorkspaceRoot  string
	OS             string
	Provider       string
	Model          string
}

PromptOptions provides runtime context and custom instructions for prompt construction.

func DefaultPromptOptions added in v0.4.0

func DefaultPromptOptions(workspaceRoot, provider, model string) PromptOptions

DefaultPromptOptions creates a PromptOptions prefilled with host OS and discovered context.

type Session

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

func NewSession

func NewSession(model string) *Session

func NewSessionWithStore added in v0.2.0

func NewSessionWithStore(id, providerName, model string, store *session.SessionStore) *Session

func (*Session) AddMessage

func (s *Session) AddMessage(msg provider.Message)

func (*Session) Clear

func (s *Session) Clear()

func (*Session) ClearModifiedFiles added in v0.2.0

func (s *Session) ClearModifiedFiles()

func (*Session) History

func (s *Session) History() []provider.Message

func (*Session) ID added in v0.2.0

func (s *Session) ID() string

func (*Session) LastAssistantMessage

func (s *Session) LastAssistantMessage() string

func (*Session) LoadMessages added in v0.2.0

func (s *Session) LoadMessages(msgs []provider.Message)

func (*Session) Model

func (s *Session) Model() string

func (*Session) ModifiedFiles added in v0.2.0

func (s *Session) ModifiedFiles() []string

func (*Session) Provider added in v0.2.0

func (s *Session) Provider() string

func (*Session) SetID added in v0.2.0

func (s *Session) SetID(id string)

func (*Session) SetModel

func (s *Session) SetModel(model string)

func (*Session) SetProvider added in v0.2.0

func (s *Session) SetProvider(p string)

func (*Session) Store added in v0.2.0

func (s *Session) Store() *session.SessionStore

func (*Session) TrackModifiedFile added in v0.2.0

func (s *Session) TrackModifiedFile(path string)

type Turn added in v0.4.0

type Turn struct {
	Messages []provider.Message
}

Turn represents a logical conversation turn starting with a user message and including all associated assistant responses, tool calls, and tool results.

func (Turn) Tokens added in v0.4.0

func (t Turn) Tokens(cm *ContextManager) int

Jump to

Keyboard shortcuts

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