Help us shape the future of Go! Take the 2026 Go Developer Survey

baseAgent

package module
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: May 26, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MessageRoleCustom            = "custom"
	MessageRoleBranchSummary     = "branchSummary"
	MessageRoleCompactionSummary = "compactionSummary"
	BranchSummaryPrefix          = `The following is a summary of a branch that this conversation came back from:

<summary>
`
	BranchSummarySuffix = `</summary>`

	CompactionSummaryPrefix = `The conversation history before this point was compacted into the following summary:

<summary>
`
	CompactionSummarySuffix = `
</summary>`
)
View Source
const CurrentSessionVersion = 1
View Source
const DefaultThinkingLevel = ai.ThinkingLevelMedium

Variables

This section is empty.

Functions

func ConvertToLLM

func ConvertToLLM(messages []agent.AgentMessage) []ai.Message

func FindInitialModel

func FindInitialModel(registry *ModelRegistry) (ai.Model[ai.API], bool)

Types

type AgentSession

type AgentSession struct {
	Agent          *agent.Agent
	SessionManager *SessionManager
}

func NewAgentSession

func NewAgentSession(a *agent.Agent, sm *SessionManager) *AgentSession

func (*AgentSession) GetActiveToolNames

func (s *AgentSession) GetActiveToolNames() ([]string, error)

* Get the names of currently active tools. * Returns the names of tools currently set on the agent.

func (*AgentSession) GetFollowUpMode

func (s *AgentSession) GetFollowUpMode() (string, error)

* Current follow-up mode

func (*AgentSession) GetMessages

func (s *AgentSession) GetMessages() ([]agent.AgentMessage, error)

* Current messages in the conversation

func (*AgentSession) GetModel

func (s *AgentSession) GetModel() (ai.Model[ai.API], error)

* Current model (may be undefined if not yet selected)

func (*AgentSession) GetSessionID

func (s *AgentSession) GetSessionID() (string, error)

* Current session ID

func (*AgentSession) GetSessionName

func (s *AgentSession) GetSessionName() (*string, error)

* Current session name

func (*AgentSession) GetState

func (s *AgentSession) GetState() (agent.AgentState, error)

* Return full agent state

func (*AgentSession) GetSteeringMode

func (s *AgentSession) GetSteeringMode() (string, error)

* Current steering mode

func (*AgentSession) GetSystemPrompt

func (s *AgentSession) GetSystemPrompt() (string, error)

* Current effective system prompt

func (*AgentSession) GetThinkingLevel

func (s *AgentSession) GetThinkingLevel() (ai.ModelThinkingLevel, error)

* Current thinking level

func (*AgentSession) IsStreaming

func (s *AgentSession) IsStreaming() bool

* Whether agent is currently streaming a response

func (*AgentSession) Prompt

func (s *AgentSession) Prompt(ctx context.Context, text string, options *PromptOptions) error

*

  • Send a prompt to the agent.
  • - During streaming, queues via steer() or followUp() based on streamingBehavior option
  • - Validates model and API key before sending (when not streaming)
  • Error if streaming and no streamingBehavior specified
  • Error if no model selected or no API key available (when not streaming)

type AuthStore

type AuthStore interface {
	APIKey(provider ai.Provider) (string, bool)
}

AuthStore resolves provider API keys for model requests.

type BranchSummaryEntry

type BranchSummaryEntry struct {
	SessionEntryBase
	FromID   string `json:"fromId"`
	Summary  string `json:"summary"`
	Details  any    `json:"details,omitempty"`
	FromHook *bool  `json:"fromHook,omitempty"`
}

func (*BranchSummaryEntry) GetBase

func (e *BranchSummaryEntry) GetBase() *SessionEntryBase

type BranchSummaryMessage

type BranchSummaryMessage struct {
	Role      string `json:"role"`
	Summary   string `json:"summary"`
	FromID    string `json:"fromId"`
	Timestamp int64  `json:"timestamp"`
}

func CreateBranchSummaryMessage

func CreateBranchSummaryMessage(summary, fromID string, timestamp int64) BranchSummaryMessage

func (BranchSummaryMessage) AgentMessageType

func (BranchSummaryMessage) AgentMessageType() string

type CompactionEntry

type CompactionEntry struct {
	SessionEntryBase
	Summary          string `json:"summary"`
	FirstKeptEntryID string `json:"firstKeptEntryId"`
	TokensBefore     int64  `json:"tokensBefore"`
	Details          any    `json:"details,omitempty"`
	FromHook         *bool  `json:"fromHook,omitempty"`
}

func GetLatestCompactionEntry

func GetLatestCompactionEntry(entries []SessionEntry) *CompactionEntry

func (*CompactionEntry) GetBase

func (e *CompactionEntry) GetBase() *SessionEntryBase

type CompactionSummaryMessage

type CompactionSummaryMessage struct {
	Role         string `json:"role"`
	Summary      string `json:"summary"`
	TokensBefore int64  `json:"tokensBefore"`
	Timestamp    int64  `json:"timestamp"`
}

func CreateCompactionSummaryMessage

func CreateCompactionSummaryMessage(summary string, tokensBefore, timestamp int64) CompactionSummaryMessage

func (CompactionSummaryMessage) AgentMessageType

func (CompactionSummaryMessage) AgentMessageType() string

type CreateAgentSessionOptions

type CreateAgentSessionOptions struct {
	Model          ai.Model[ai.API]
	ThinkingLevel  ai.ModelThinkingLevel
	SessionManager *SessionManager
	ModelRegistry  *ModelRegistry
	AuthStore      AuthStore
}

type CreateAgentSessionResult

type CreateAgentSessionResult struct {
	Session              *AgentSession
	ModelFallbackMessage *string
}

func CreateAgentSession

func CreateAgentSession(ctx context.Context, options CreateAgentSessionOptions) (*CreateAgentSessionResult, error)

CreateAgentSession creates a minimal, generic agent session with no tools.

type CustomEntry

type CustomEntry struct {
	SessionEntryBase
	CustomType string `json:"customType"`
	Data       any    `json:"data,omitempty"`
}

func (*CustomEntry) GetBase

func (e *CustomEntry) GetBase() *SessionEntryBase

type CustomMessage

type CustomMessage struct {
	Role       string           `json:"role"`
	CustomType string           `json:"customType"`
	Content    []ai.UserContent `json:"content"`
	Display    bool             `json:"display"`
	Details    any              `json:"details,omitempty"`
	Timestamp  int64            `json:"timestamp"`
}

func CreateCustomMessage

func CreateCustomMessage(customType string, content []ai.UserContent, display bool, details any, timestamp int64) CustomMessage

func (CustomMessage) AgentMessageType

func (CustomMessage) AgentMessageType() string

type CustomMessageEntry

type CustomMessageEntry struct {
	SessionEntryBase
	CustomType string           `json:"customType"`
	Content    []ai.UserContent `json:"content"`
	Details    any              `json:"details,omitempty"`
	Display    bool             `json:"display"`
}

func (*CustomMessageEntry) GetBase

func (e *CustomMessageEntry) GetBase() *SessionEntryBase

type EnvAuthStore

type EnvAuthStore struct{}

EnvAuthStore resolves API keys from environment variables.

func (EnvAuthStore) APIKey

func (EnvAuthStore) APIKey(provider ai.Provider) (string, bool)

type LabelEntry

type LabelEntry struct {
	SessionEntryBase
	TargetID string  `json:"targetId"`
	Label    *string `json:"label,omitempty"`
}

func (*LabelEntry) GetBase

func (e *LabelEntry) GetBase() *SessionEntryBase

type ModelChangeEntry

type ModelChangeEntry struct {
	SessionEntryBase
	Provider string `json:"provider"`
	ModelID  string `json:"modelId"`
}

func (*ModelChangeEntry) GetBase

func (e *ModelChangeEntry) GetBase() *SessionEntryBase

type ModelRegistry

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

ModelRegistry provides model lookup and request auth resolution.

func NewModelRegistry

func NewModelRegistry(auth AuthStore) *ModelRegistry

NewModelRegistry creates a registry using the built-in ai.Models list.

func NewModelRegistryWithModels

func NewModelRegistryWithModels(auth AuthStore, models map[ai.Provider]map[string]ai.Model[ai.API]) *ModelRegistry

NewModelRegistryWithModels creates a registry using an explicit model set.

func (*ModelRegistry) APIKeyAndHeaders

func (r *ModelRegistry) APIKeyAndHeaders(model ai.Model[ai.API]) (RequestAuth, error)

APIKeyAndHeaders resolves the API key and headers to use for a model request.

func (*ModelRegistry) APIKeyForProvider

func (r *ModelRegistry) APIKeyForProvider(provider ai.Provider) (string, bool)

APIKeyForProvider resolves a provider API key.

func (*ModelRegistry) All

func (r *ModelRegistry) All() []ai.Model[ai.API]

All returns every model in deterministic provider/id order.

func (*ModelRegistry) Available

func (r *ModelRegistry) Available() []ai.Model[ai.API]

Available returns models whose provider has configured auth.

func (*ModelRegistry) Find

func (r *ModelRegistry) Find(provider ai.Provider, modelID string) (ai.Model[ai.API], bool)

Find returns a model by provider and model ID.

func (*ModelRegistry) HasConfiguredAuth

func (r *ModelRegistry) HasConfiguredAuth(model ai.Model[ai.API]) bool

HasConfiguredAuth reports whether a model's provider has an API key.

func (*ModelRegistry) ProviderDisplayName

func (r *ModelRegistry) ProviderDisplayName(provider ai.Provider) string

ProviderDisplayName returns a human-friendly provider name.

type PromptOptions

type PromptOptions struct {
	Images []ai.ImageContent
	/** When streaming, how to queue the message: "steer" (interrupt) or "followUp" (wait). Required if streaming. */
	StreamingBehavior StreamingBehavior
}

type RequestAuth

type RequestAuth struct {
	APIKey  *string
	Headers map[string]string
}

RequestAuth is the request-level auth and headers resolved for a model.

type SessionContext

type SessionContext struct {
	Messages      []agent.AgentMessage
	ThinkingLevel string
	Model         *SessionModel
}

func BuildSessionContext

func BuildSessionContext(entries []SessionEntry, leafID *string, byID map[string]SessionEntry) SessionContext

type SessionEntry

type SessionEntry interface{ GetBase() *SessionEntryBase }

type SessionEntryBase

type SessionEntryBase struct {
	Type      string  `json:"type"`
	ID        string  `json:"id"`
	ParentID  *string `json:"parentId"`
	Timestamp string  `json:"timestamp"`
}

type SessionHeader

type SessionHeader struct {
	Type          string         `json:"type"`
	Version       int            `json:"version,omitempty"`
	ID            string         `json:"id"`
	Timestamp     string         `json:"timestamp"`
	ParentSession *string        `json:"parentSession,omitempty"`
	Name          *string        `json:"name,omitempty"`
	MessageCount  int64          `json:"messageCount,omitempty"`
	FirstMessage  *string        `json:"firstMessage,omitempty"`
	Metadata      map[string]any `json:"metadata,omitempty"`
}

func NewDefaultSessionHeader

func NewDefaultSessionHeader(parentSession *string, metadata map[string]any) *SessionHeader

type SessionInfo

type SessionInfo struct {
	ID                      string
	Name, ParentSessionPath *string
	Created, Modified       time.Time
	MessageCount            int
	FirstMessage            string
}

type SessionInfoEntry

type SessionInfoEntry struct {
	SessionEntryBase
	Name *string `json:"name,omitempty"`
}

func (*SessionInfoEntry) GetBase

func (e *SessionInfoEntry) GetBase() *SessionEntryBase

type SessionListProgress

type SessionListProgress func(loaded, total int)

type SessionManager

type SessionManager struct {
	Header  *SessionHeader
	Entries []SessionEntry

	Store SessionStore
	// contains filtered or unexported fields
}

func InMemorySessionManager

func InMemorySessionManager(ctx context.Context) (*SessionManager, error)

func NewSessionManager

func NewSessionManager(ctx context.Context, header *SessionHeader, sessionID *string, persist bool, store SessionStore, metadata map[string]any) (*SessionManager, error)

func (*SessionManager) AppendCompaction

func (s *SessionManager) AppendCompaction(ctx context.Context, summary, first string, tokens int64, details any, fromHook *bool) (string, error)

func (*SessionManager) AppendCustomEntry

func (s *SessionManager) AppendCustomEntry(ctx context.Context, t string, data any) (string, error)

func (*SessionManager) AppendCustomMessageEntry

func (s *SessionManager) AppendCustomMessageEntry(ctx context.Context, t string, c []ai.UserContent, display bool, details any) (string, error)

func (*SessionManager) AppendLabelChange

func (s *SessionManager) AppendLabelChange(ctx context.Context, target string, label *string) (string, error)

func (*SessionManager) AppendMessage

func (s *SessionManager) AppendMessage(ctx context.Context, m agent.AgentMessage) (string, error)

func (*SessionManager) AppendMessageWithID added in v0.1.3

func (s *SessionManager) AppendMessageWithID(ctx context.Context, id string, m agent.AgentMessage) (string, error)

func (*SessionManager) AppendModelChange

func (s *SessionManager) AppendModelChange(ctx context.Context, p, m string) (string, error)

func (*SessionManager) AppendSessionInfo

func (s *SessionManager) AppendSessionInfo(ctx context.Context, name string) (string, error)

func (*SessionManager) AppendThinkingLevelChange

func (s *SessionManager) AppendThinkingLevelChange(ctx context.Context, v string) (string, error)

func (*SessionManager) BuildSessionContext

func (s *SessionManager) BuildSessionContext() SessionContext

func (*SessionManager) CreateBranchedSession

func (s *SessionManager) CreateBranchedSession(ctx context.Context, leafID string) (*SessionManager, error)

func (*SessionManager) GetBranch

func (s *SessionManager) GetBranch(from ...string) []SessionEntry

func (*SessionManager) GetChildren

func (s *SessionManager) GetChildren(parentID string) []SessionEntry

func (*SessionManager) GetEntries

func (s *SessionManager) GetEntries() []SessionEntry

func (*SessionManager) GetEntry

func (s *SessionManager) GetEntry(id string) SessionEntry

func (*SessionManager) GetHeader

func (s *SessionManager) GetHeader() *SessionHeader

func (*SessionManager) GetLabel

func (s *SessionManager) GetLabel(id string) *string

func (*SessionManager) GetLeafEntry

func (s *SessionManager) GetLeafEntry() SessionEntry

func (*SessionManager) GetLeafID

func (s *SessionManager) GetLeafID() *string

func (*SessionManager) GetSessionID

func (s *SessionManager) GetSessionID() string

func (*SessionManager) GetSessionName

func (s *SessionManager) GetSessionName() *string

func (*SessionManager) GetTree

func (s *SessionManager) GetTree() []*SessionTreeNode

func (*SessionManager) IsPersisted

func (s *SessionManager) IsPersisted() bool

func (*SessionManager) LoadSession

func (s *SessionManager) LoadSession(ctx context.Context, id string) error

func (*SessionManager) NewSession

func (s *SessionManager) NewSession(ctx context.Context, header *SessionHeader, metadata map[string]any) error

func (*SessionManager) ResetLeaf

func (s *SessionManager) ResetLeaf()

func (*SessionManager) SetLeaf

func (s *SessionManager) SetLeaf(id string) error

type SessionMessageEntry

type SessionMessageEntry struct {
	SessionEntryBase
	Message agent.AgentMessage `json:"message"`
}

func (*SessionMessageEntry) GetBase

func (e *SessionMessageEntry) GetBase() *SessionEntryBase

type SessionModel

type SessionModel struct{ Provider, ModelID string }

type SessionStore

type SessionStore interface {
	CreateSession(ctx context.Context, header *SessionHeader) error
	LoadSession(ctx context.Context, sessionID string) (*SessionHeader, []SessionEntry, error)
	AppendEntry(ctx context.Context, header *SessionHeader, entry SessionEntry) error
	ListSessions(ctx context.Context, metadata map[string]any) ([]SessionInfo, error)
	FindMostRecentSession(ctx context.Context, metadata map[string]any) (*SessionInfo, error)
	CreateBranch(ctx context.Context, fromLeafID string, newHeader SessionHeader) error
}

type SessionTreeNode

type SessionTreeNode struct {
	Entry          SessionEntry       `json:"entry"`
	Children       []*SessionTreeNode `json:"children"`
	Label          *string            `json:"label,omitempty"`
	LabelTimestamp *string            `json:"labelTimestamp,omitempty"`
}

type StreamingBehavior

type StreamingBehavior string
const (
	StreamingBehaviorSteer    StreamingBehavior = "steer"
	StreamingBehaviorFollowUp StreamingBehavior = "followUp"
)

type ThinkingLevelChangeEntry

type ThinkingLevelChangeEntry struct {
	SessionEntryBase
	ThinkingLevel string `json:"thinkingLevel"`
}

func (*ThinkingLevelChangeEntry) GetBase

Jump to

Keyboard shortcuts

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