Documentation
¶
Index ¶
- Constants
- func ConvertToLLM(messages []agent.AgentMessage) []ai.Message
- func FindInitialModel(registry *ModelRegistry) (ai.Model[ai.API], bool)
- type AgentSession
- func (s *AgentSession) GetActiveToolNames() ([]string, error)
- func (s *AgentSession) GetFollowUpMode() (string, error)
- func (s *AgentSession) GetMessages() ([]agent.AgentMessage, error)
- func (s *AgentSession) GetModel() (ai.Model[ai.API], error)
- func (s *AgentSession) GetSessionID() (string, error)
- func (s *AgentSession) GetSessionName() (*string, error)
- func (s *AgentSession) GetState() (agent.AgentState, error)
- func (s *AgentSession) GetSteeringMode() (string, error)
- func (s *AgentSession) GetSystemPrompt() (string, error)
- func (s *AgentSession) GetThinkingLevel() (ai.ModelThinkingLevel, error)
- func (s *AgentSession) IsStreaming() bool
- func (s *AgentSession) Prompt(ctx context.Context, text string, options *PromptOptions) error
- type AuthStore
- type BranchSummaryEntry
- type BranchSummaryMessage
- type CompactionEntry
- type CompactionSummaryMessage
- type CreateAgentSessionOptions
- type CreateAgentSessionResult
- type CustomEntry
- type CustomMessage
- type CustomMessageEntry
- type EnvAuthStore
- type LabelEntry
- type ModelChangeEntry
- type ModelRegistry
- func (r *ModelRegistry) APIKeyAndHeaders(model ai.Model[ai.API]) (RequestAuth, error)
- func (r *ModelRegistry) APIKeyForProvider(provider ai.Provider) (string, bool)
- func (r *ModelRegistry) All() []ai.Model[ai.API]
- func (r *ModelRegistry) Available() []ai.Model[ai.API]
- func (r *ModelRegistry) Find(provider ai.Provider, modelID string) (ai.Model[ai.API], bool)
- func (r *ModelRegistry) HasConfiguredAuth(model ai.Model[ai.API]) bool
- func (r *ModelRegistry) ProviderDisplayName(provider ai.Provider) string
- type PromptOptions
- type RequestAuth
- type SessionContext
- type SessionEntry
- type SessionEntryBase
- type SessionHeader
- type SessionInfo
- type SessionInfoEntry
- type SessionListProgress
- type SessionManager
- func (s *SessionManager) AppendCompaction(ctx context.Context, summary, first string, tokens int64, details any, ...) (string, error)
- func (s *SessionManager) AppendCustomEntry(ctx context.Context, t string, data any) (string, error)
- func (s *SessionManager) AppendCustomMessageEntry(ctx context.Context, t string, c []ai.UserContent, display bool, details any) (string, error)
- func (s *SessionManager) AppendLabelChange(ctx context.Context, target string, label *string) (string, error)
- func (s *SessionManager) AppendMessage(ctx context.Context, m agent.AgentMessage) (string, error)
- func (s *SessionManager) AppendMessageWithID(ctx context.Context, id string, m agent.AgentMessage) (string, error)
- func (s *SessionManager) AppendModelChange(ctx context.Context, p, m string) (string, error)
- func (s *SessionManager) AppendSessionInfo(ctx context.Context, name string) (string, error)
- func (s *SessionManager) AppendThinkingLevelChange(ctx context.Context, v string) (string, error)
- func (s *SessionManager) BuildSessionContext() SessionContext
- func (s *SessionManager) CreateBranchedSession(ctx context.Context, leafID string) (*SessionManager, error)
- func (s *SessionManager) GetBranch(from ...string) []SessionEntry
- func (s *SessionManager) GetChildren(parentID string) []SessionEntry
- func (s *SessionManager) GetEntries() []SessionEntry
- func (s *SessionManager) GetEntry(id string) SessionEntry
- func (s *SessionManager) GetHeader() *SessionHeader
- func (s *SessionManager) GetLabel(id string) *string
- func (s *SessionManager) GetLeafEntry() SessionEntry
- func (s *SessionManager) GetLeafID() *string
- func (s *SessionManager) GetSessionID() string
- func (s *SessionManager) GetSessionName() *string
- func (s *SessionManager) GetTree() []*SessionTreeNode
- func (s *SessionManager) IsPersisted() bool
- func (s *SessionManager) LoadSession(ctx context.Context, id string) error
- func (s *SessionManager) NewSession(ctx context.Context, header *SessionHeader, metadata map[string]any) error
- func (s *SessionManager) ResetLeaf()
- func (s *SessionManager) SetLeaf(id string) error
- type SessionMessageEntry
- type SessionModel
- type SessionStore
- type SessionTreeNode
- type StreamingBehavior
- type ThinkingLevelChangeEntry
Constants ¶
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>` )
const CurrentSessionVersion = 1
const DefaultThinkingLevel = ai.ThinkingLevelMedium
Variables ¶
This section is empty.
Functions ¶
func ConvertToLLM ¶
func ConvertToLLM(messages []agent.AgentMessage) []ai.Message
func FindInitialModel ¶
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) 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 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
SystemPrompt *string
Tools []agent.AgentTool[any, any]
ToolExecutionMode *agent.ToolExecutionMode
/* Optional func to call before each tool call is executed. */
BeforeToolCall func(
ctx context.Context,
call agent.BeforeToolCallContext,
) (*agent.BeforeToolCallResult, error)
/* Optional func to call after each tool call is executed. */
AfterToolCall func(
ctx context.Context,
call agent.AfterToolCallContext[any],
) (*agent.AfterToolCallResult, error)
/* Optional func to call before each payload is sent to the provider. */
OnPayload func(
payload any,
model ai.Model[ai.API],
) (any, error)
/* Optional func to call after each response is received from the provider. */
OnResponse func(
response ai.ProviderResponse,
model ai.Model[ai.API],
) error
}
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.
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) HasConfiguredAuth ¶
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 ¶
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 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 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 (*SessionManager) AppendCustomEntry ¶
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 (*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 (*SessionManager) AppendSessionInfo ¶
func (*SessionManager) AppendThinkingLevelChange ¶
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 ¶
func (e *ThinkingLevelChangeEntry) GetBase() *SessionEntryBase