agent

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CompactionResult added in v0.0.2

type CompactionResult struct {
	Changed      bool
	TokensBefore int
	TokensAfter  int
	Reason       string
}

type ModelFactory

type ModelFactory func(prov, model, apiKey, baseURL string) (agentcore.ChatModel, error)

ModelFactory creates a chat model instance for a provider/model tuple.

type Session

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

Session is the business-logic core that wraps Agent + session persistence. It is independent of any UI framework and drives interactive, print, and RPC modes.

func NewSession

func NewSession(cfg SessionConfig) *Session

NewSession creates a Session and wires auto-persist to the agent.

func (*Session) APIKey

func (s *Session) APIKey() string

func (*Session) Abort

func (s *Session) Abort()

func (*Session) AbortSilent

func (s *Session) AbortSilent()

func (*Session) BaseURL

func (s *Session) BaseURL() string

func (*Session) ClearConversation

func (s *Session) ClearConversation()

func (*Session) Close

func (s *Session) Close()

func (*Session) Compact

func (s *Session) Compact() (CompactionResult, error)

func (*Session) ContextUsage

func (s *Session) ContextUsage() *agentcore.ContextUsage

func (*Session) CostEstimate

func (s *Session) CostEstimate() (inputTokens, outputTokens int, cost float64)

func (*Session) CurrentSessionInfo

func (s *Session) CurrentSessionInfo() (storage.SessionInfo, error)

func (*Session) IsRunning

func (s *Session) IsRunning() bool

func (*Session) LastAssistantText

func (s *Session) LastAssistantText() string

func (*Session) ListSessions

func (s *Session) ListSessions() ([]storage.SessionInfo, error)

func (*Session) Messages added in v0.0.2

func (s *Session) Messages() []agentcore.AgentMessage

Messages returns the current agent message history.

func (*Session) ModelName

func (s *Session) ModelName() string

func (*Session) NewSession

func (s *Session) NewSession() error

func (*Session) Prompt

func (s *Session) Prompt(text string) error

func (*Session) PromptWithBlocks

func (s *Session) PromptWithBlocks(blocks []agentcore.ContentBlock) error

func (*Session) Provider

func (s *Session) Provider() string

func (*Session) Registry

func (s *Session) Registry() *provider.ModelRegistry

func (*Session) Reload

func (s *Session) Reload()

func (*Session) ReplaceAllTools

func (s *Session) ReplaceAllTools(tools []agentcore.Tool)

func (*Session) ResolveAndSetModel

func (s *Session) ResolveAndSetModel(pattern string) (string, error)

func (*Session) RestoreAllTools

func (s *Session) RestoreAllTools(extra ...agentcore.Tool)

func (*Session) SetBeforePrompt

func (s *Session) SetBeforePrompt(fn func())

func (*Session) SetModel

func (s *Session) SetModel(prov, model string) error

func (*Session) SetSystemSuffix

func (s *Session) SetSystemSuffix(suffix string)

func (*Session) SetThinkingLevel

func (s *Session) SetThinkingLevel(level agentcore.ThinkingLevel)

func (*Session) SetTools

func (s *Session) SetTools(tools ...agentcore.Tool)

func (*Session) Settings

func (s *Session) Settings() config.Resolved

func (*Session) Skills

func (s *Session) Skills() []config.Skill

func (*Session) Steer

func (s *Session) Steer(text string)

func (*Session) Subscribe

func (s *Session) Subscribe(fn func(SessionEvent)) func()

func (*Session) SwitchSession

func (s *Session) SwitchSession(id string) error

func (*Session) ToolsByName

func (s *Session) ToolsByName(names ...string) []agentcore.Tool

func (*Session) TotalTokens

func (s *Session) TotalTokens() int

type SessionConfig

type SessionConfig struct {
	Agent    *agentcore.Agent
	Store    *storage.Store
	Manager  *storage.Manager
	Registry *provider.ModelRegistry
	Settings config.Resolved
	Cwd      string
	// CreateModel allows tests/integrations to override model construction.
	// Defaults to provider.CreateModel when nil.
	CreateModel ModelFactory
	// LazyPersist buffers user messages and flushes them only when
	// an assistant response arrives. Disabled by default for safety.
	LazyPersist bool
	// ChatModel is the active ChatModel reference, used for max_tokens adjustment
	// during overflow recovery.
	ChatModel agentcore.ChatModel
	// HookRunner fires lifecycle hooks (notification, etc.). Nil when no hooks configured.
	HookRunner *hooks.Runner

	// Tools is the full set of tools registered with the agent.
	// Used by ToolsByName / RestoreAllTools for plan mode filtering.
	Tools []agentcore.Tool
	// ContextFiles holds loaded context files for dynamic system prompt rebuilding.
	// When tools change the prompt is regenerated from these inputs.
	ContextFiles config.ContextFiles
	// Skills holds loaded skills for system prompt injection and /skill: commands.
	Skills []config.Skill
	// DeferredToolsPreamble is injected as the first user message (once).
	DeferredToolsPreamble string
	// Reminders are <system-reminder> fragments prepended to each user message.
	Reminders []string
	// PreambleInjected indicates the preamble was already in conversation history (resume).
	PreambleInjected bool
}

SessionConfig configures a new Session.

type SessionEvent

type SessionEvent struct {
	Type       SessionEventType
	AgentEvent *agentcore.Event

	// Session-level fields (populated based on Type)
	ModelName string
	Provider  string
	Level     agentcore.ThinkingLevel
	SessionID string
	Error     error

	// Retry fields (populated for SEAutoRetryStart / SEAutoRetryEnd)
	RetryAttempt int
	RetryMax     int
	RetryDelay   time.Duration
	RetrySuccess bool

	// Compaction reason: "overflow" or "threshold"
	CompactionReason  string
	CompactionChanged bool
	TokensBefore      int
	TokensAfter       int
}

SessionEvent extends agent events with session-level metadata. When Type == SEAgentEvent, AgentEvent is non-nil.

type SessionEventType

type SessionEventType string

SessionEventType identifies a session-level event.

const (
	// SEAgentEvent wraps an agentcore.Event transparently.
	SEAgentEvent SessionEventType = "agent_event"

	// Session lifecycle events
	SEAutoCompactionStart SessionEventType = "auto_compaction_start"
	SEAutoCompactionEnd   SessionEventType = "auto_compaction_end"
	SEAutoRetryStart      SessionEventType = "auto_retry_start"
	SEAutoRetryEnd        SessionEventType = "auto_retry_end"
	SEModelChanged        SessionEventType = "model_changed"
	SEThinkingChanged     SessionEventType = "thinking_changed"
	SESessionSwitched     SessionEventType = "session_switched"
	SEError               SessionEventType = "session_error"
)

Jump to

Keyboard shortcuts

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