Documentation
¶
Index ¶
- Constants
- Variables
- func NewKBWrapperActions(ragdb RAGDB, kbResults int) (*SearchKnowledgeBaseAction, *AddToKnowledgeBaseAction)
- type AddToKnowledgeBaseAction
- type Agent
- func (a *Agent) AddSubscriber(f func(*types.ConversationMessage))
- func (a *Agent) Ask(opts ...types.JobOption) *types.JobResult
- func (a *Agent) AskDirect(opts ...types.JobOption) *types.JobResult
- func (a *Agent) AskDirectSystem(opts ...types.JobOption) *types.JobResult
- func (a *Agent) Context() context.Context
- func (a *Agent) Enqueue(j *types.Job)
- func (a *Agent) Execute(j *types.Job) *types.JobResult
- func (a *Agent) LoadCharacter(path string) error
- func (a *Agent) LoadState(path string) error
- func (a *Agent) Memory() RAGDB
- func (a *Agent) Observer() Observer
- func (a *Agent) Pause()
- func (a *Agent) Paused() bool
- func (a *Agent) Resume()
- func (a *Agent) Run() error
- func (a *Agent) SaveCharacter(path string) error
- func (a *Agent) SaveState(path string) error
- func (a *Agent) SetStreamCallback(fn func(cogito.StreamEvent))
- func (a *Agent) SharedState() *types.AgentSharedState
- func (a *Agent) StartConversationConsumer()
- func (a *Agent) State() types.AgentInternalState
- func (a *Agent) Stop()
- func (a *Agent) TTS(ctx context.Context, text string) ([]byte, error)
- func (a *Agent) Transcribe(ctx context.Context, file string) (string, error)
- type Character
- type CommonTemplateData
- type ConversationStorageMode
- type DynamicPrompt
- type InnerMonologueTemplateData
- type KBWrapperActions
- type MCPSTDIOServer
- type MCPServer
- type Messages
- func (m Messages) Exist(content string) bool
- func (m Messages) GetLatestUserMessage() *openai.ChatCompletionMessage
- func (m Messages) RemoveIf(f func(msg openai.ChatCompletionMessage) bool) Messages
- func (m Messages) RemoveLastUserMessage() Messages
- func (m Messages) Save(path string) error
- func (m Messages) String() string
- func (m Messages) ToOpenAI() []openai.ChatCompletionMessage
- type NoToolToCallArgs
- type NoToolToCallTool
- type Observer
- type Option
- func EnableEvaluation() Option
- func EnableKnowledgeBaseWithResults(results int) Option
- func FromFile(path string) Option
- func WithActions(actions ...types.Action) Option
- func WithAgentReasoningCallback(cb func(types.ActionCurrentState) bool) Option
- func WithAgentResultCallback(cb func(types.ActionState)) Option
- func WithAutoCompactionThreshold(threshold int) Option
- func WithCancelPreviousOnNewMessage(cancel bool) Option
- func WithCharacter(c Character) Option
- func WithCharacterFile(path string) Option
- func WithContext(ctx context.Context) Option
- func WithConversationStorageMode(mode ConversationStorageMode) Option
- func WithConversationsPath(path string) Option
- func WithInnerMonologueTemplate(template string) Option
- func WithJobFilters(filters ...types.JobFilter) Option
- func WithKBAutoSearch(enabled bool) Option
- func WithLLMAPIKey(key string) Option
- func WithLLMAPIURL(url string) Option
- func WithLastMessageDuration(duration string) Option
- func WithLoopDetection(loops int) Option
- func WithMCPPrepareScript(script string) Option
- func WithMCPSTDIOServers(servers ...MCPSTDIOServer) Option
- func WithMCPServers(servers ...MCPServer) Option
- func WithMCPSession(session *mcp.ClientSession) Option
- func WithMaxAttempts(attempts int) Option
- func WithMaxEvaluationLoops(loops int) Option
- func WithModel(model string) Option
- func WithMultimodalModel(model string) Option
- func WithNewConversationSubscriber(sub func(*types.ConversationMessage)) Option
- func WithObserver(observer Observer) Option
- func WithParallelJobs(jobs int) Option
- func WithPeriodicRuns(duration string) Option
- func WithPermanentGoal(goal string) Option
- func WithPrompts(prompts ...DynamicPrompt) Option
- func WithRAGDB(db RAGDB) Option
- func WithRandomIdentity(guidance ...string) Option
- func WithSchedulerPollInterval(duration string) Option
- func WithSchedulerStorePath(path string) Option
- func WithSchedulerTaskTemplate(template string) Option
- func WithSkillPromptTemplate(template string) Option
- func WithStateFile(path string) Option
- func WithStreamCallback(fn func(cogito.StreamEvent)) Option
- func WithSystemPrompt(prompt string) Option
- func WithTTSModel(model string) Option
- func WithTimeout(timeout string) Option
- func WithTranscriptionLanguage(language string) Option
- func WithTranscriptionModel(model string) Option
- type PromptHUD
- type RAGDB
- type SSEObserver
- type SearchKnowledgeBaseAction
- type ToolInputSchema
Constants ¶
const ( UserRole = "user" AssistantRole = "assistant" SystemRole = "system" )
Variables ¶
var CanStopItself = func(o *options) error { o.canStopItself = true return nil }
var DisableSinkState = func(o *options) error { o.disableSinkState = true return nil }
var EnableAutoCompaction = func(o *options) error { o.enableAutoCompaction = true return nil }
var EnableForceReasoning = func(o *options) error { o.forceReasoning = true return nil }
var EnableForceReasoningTool = func(o *options) error { o.forceReasoningTool = true return nil }
var EnableGuidedTools = func(o *options) error { o.enableGuidedTools = true return nil }
var EnableHUD = func(o *options) error { o.enableHUD = true return nil }
var EnableInitiateConversations = func(o *options) error { o.initiateConversations = true return nil }
var EnableKnowledgeBase = func(o *options) error { o.enableKB = true o.kbResults = 5 return nil }
var EnableLongTermMemory = func(o *options) error { o.enableLongTermMemory = true return nil }
var EnablePersonality = func(o *options) error { o.showCharacter = true return nil }
var EnablePlanning = func(o *options) error { o.canPlan = true return nil }
var EnableStandaloneJob = func(o *options) error { o.standaloneJob = true return nil }
EnableStandaloneJob is an option to enable the agent to run jobs in the background automatically
var EnableStripThinkingTags = func(o *options) error { o.stripThinkingTags = true return nil }
var EnableSummaryMemory = func(o *options) error { o.enableSummaryMemory = true return nil }
var ErrContextCanceled = fmt.Errorf("context canceled")
var WithPlanReviewerLLM = func(model string) Option { return func(o *options) error { o.LLMAPI.ReviewerModel = model return nil } }
Functions ¶
func NewKBWrapperActions ¶
func NewKBWrapperActions(ragdb RAGDB, kbResults int) (*SearchKnowledgeBaseAction, *AddToKnowledgeBaseAction)
NewKBWrapperActions creates factory functions for KB wrapper actions
Types ¶
type AddToKnowledgeBaseAction ¶
type AddToKnowledgeBaseAction struct {
*KBWrapperActions
}
func (*AddToKnowledgeBaseAction) Definition ¶
func (a *AddToKnowledgeBaseAction) Definition() types.ActionDefinition
func (*AddToKnowledgeBaseAction) Run ¶
func (a *AddToKnowledgeBaseAction) Run(ctx context.Context, sharedState *types.AgentSharedState, params types.ActionParams) (types.ActionResult, error)
type Agent ¶
func (*Agent) AddSubscriber ¶
func (a *Agent) AddSubscriber(f func(*types.ConversationMessage))
func (*Agent) Ask ¶
Ask is a blocking call that returns the response as soon as it's ready. It discards any other computation.
func (*Agent) AskDirect ¶
AskDirect executes a job synchronously without requiring Run() to be active. Unlike Ask/Execute which enqueue to the internal jobQueue (consumed by Run()), AskDirect calls consumeJob directly. This enables stateless execution where the caller manages the event loop
func (*Agent) AskDirectSystem ¶
AskDirectSystem is like AskDirect but executes with SystemRole, used for periodic autonomous runs and scheduled tasks.
func (*Agent) Execute ¶
Ask is a pre-emptive, blocking call that returns the response as soon as it's ready. It discards any other computation.
func (*Agent) LoadCharacter ¶
func (*Agent) SaveCharacter ¶
func (*Agent) SetStreamCallback ¶
func (a *Agent) SetStreamCallback(fn func(cogito.StreamEvent))
SetStreamCallback sets (or replaces) the stream callback on a live agent. This allows callers to wire streaming events after agent creation,
func (*Agent) SharedState ¶
func (a *Agent) SharedState() *types.AgentSharedState
func (*Agent) StartConversationConsumer ¶
func (a *Agent) StartConversationConsumer()
StartConversationConsumer starts the goroutine that dispatches new conversation messages to subscribers. This must be called when using AskDirect() without Run(), otherwise the ConversationAction handler will deadlock on the newConversations channel.
func (*Agent) State ¶
func (a *Agent) State() types.AgentInternalState
type Character ¶
type Character struct {
Name string `json:"name"`
Age string `json:"age"`
Occupation string `json:"job_occupation"`
Hobbies []string `json:"hobbies"`
MusicTaste []string `json:"favorites_music_genres"`
Sex string `json:"sex"`
}
func (*Character) ToJSONSchema ¶
func (c *Character) ToJSONSchema() jsonschema.Definition
type CommonTemplateData ¶
type CommonTemplateData struct {
AgentName string
}
type ConversationStorageMode ¶
type ConversationStorageMode string
ConversationStorageMode defines how conversations are stored in the knowledge base
const ( // StoreUserOnly stores only user messages (default) StoreUserOnly ConversationStorageMode = "user_only" // StoreUserAndAssistant stores both user and assistant messages separately StoreUserAndAssistant ConversationStorageMode = "user_and_assistant" // StoreWholeConversation stores the entire conversation as a single block StoreWholeConversation ConversationStorageMode = "whole_conversation" )
type DynamicPrompt ¶
type DynamicPrompt interface {
Render(a *Agent) (types.PromptResult, error)
Role() string
}
type InnerMonologueTemplateData ¶
type InnerMonologueTemplateData struct {
CommonTemplateData
Task string
}
type KBWrapperActions ¶
type KBWrapperActions struct {
// contains filtered or unexported fields
}
KBWrapperActions wraps RAGDB functionality as actions
type MCPSTDIOServer ¶
type Messages ¶
type Messages []openai.ChatCompletionMessage
func (Messages) GetLatestUserMessage ¶
func (m Messages) GetLatestUserMessage() *openai.ChatCompletionMessage
func (Messages) RemoveIf ¶
func (m Messages) RemoveIf(f func(msg openai.ChatCompletionMessage) bool) Messages
func (Messages) RemoveLastUserMessage ¶
func (Messages) ToOpenAI ¶
func (m Messages) ToOpenAI() []openai.ChatCompletionMessage
type NoToolToCallArgs ¶
type NoToolToCallArgs struct {
Reasoning string `json:"reasoning" description:"The reasoning for why no tool is being called"`
}
NoToolToCallArgs defines the arguments for the no_tool_to_call sink state tool
type NoToolToCallTool ¶
type NoToolToCallTool struct{}
NoToolToCallTool is a custom sink state tool that logs when no other tool is needed
func (NoToolToCallTool) Run ¶
func (t NoToolToCallTool) Run(args NoToolToCallArgs) (string, any, error)
Run executes the no_tool_to_call tool and logs a message
type Observer ¶
type Observer interface {
NewObservable() *types.Observable
Update(types.Observable)
History() []types.Observable
ClearHistory()
}
type Option ¶
type Option func(*options) error
func EnableEvaluation ¶
func EnableEvaluation() Option
func WithActions ¶
func WithAgentReasoningCallback ¶
func WithAgentReasoningCallback(cb func(types.ActionCurrentState) bool) Option
func WithAgentResultCallback ¶
func WithAgentResultCallback(cb func(types.ActionState)) Option
func WithCancelPreviousOnNewMessage ¶
WithCancelPreviousOnNewMessage sets whether a new job with the same conversation_id cancels the currently running job (true) or is queued (false). Nil/default means true.
func WithCharacter ¶
func WithCharacterFile ¶
func WithContext ¶
func WithConversationStorageMode ¶
func WithConversationStorageMode(mode ConversationStorageMode) Option
WithConversationStorageMode sets how conversations are stored in the knowledge base
func WithConversationsPath ¶
func WithInnerMonologueTemplate ¶
WithInnerMonologueTemplate sets the prompt used for periodic/standalone runs. If empty, the default template is used.
func WithJobFilters ¶
func WithKBAutoSearch ¶
func WithLLMAPIKey ¶
func WithLLMAPIURL ¶
func WithLastMessageDuration ¶
func WithLoopDetection ¶
func WithMCPPrepareScript ¶
func WithMCPSTDIOServers ¶
func WithMCPSTDIOServers(servers ...MCPSTDIOServer) Option
func WithMCPServers ¶
func WithMCPSession ¶
func WithMCPSession(session *mcp.ClientSession) Option
WithMCPSession adds a pre-connected MCP client session (e.g. in-process skills MCP) to the agent.
func WithMaxAttempts ¶
WithMaxAttempts sets how many times to attempt execution on failure before surfacing the error to the user (1 = no retries).
func WithMaxEvaluationLoops ¶
func WithMultimodalModel ¶
func WithNewConversationSubscriber ¶
func WithNewConversationSubscriber(sub func(*types.ConversationMessage)) Option
func WithObserver ¶
func WithParallelJobs ¶
func WithPeriodicRuns ¶
func WithPermanentGoal ¶
func WithPrompts ¶
func WithPrompts(prompts ...DynamicPrompt) Option
WithPrompts adds additional block prompts to the agent to be rendered internally in the conversation when processing the conversation to the LLM
func WithRandomIdentity ¶
func WithSchedulerStorePath ¶
WithSchedulerStorePath sets the path for the scheduler's JSON storage file
func WithSchedulerTaskTemplate ¶
WithSchedulerTaskTemplate sets the prompt used for scheduled/recurring tasks run by the scheduler. If empty, the default inner monologue template is used with the task injected.
func WithSkillPromptTemplate ¶
WithSkillPromptTemplate sets the template for rendering skills in the prompt. If empty, the default template is used.
func WithStateFile ¶
func WithStreamCallback ¶
func WithStreamCallback(fn func(cogito.StreamEvent)) Option
WithStreamCallback sets a callback to receive streaming events from cogito during final answer generation. This enables live token-by-token delivery.
func WithSystemPrompt ¶
func WithTTSModel ¶
func WithTimeout ¶
func WithTranscriptionModel ¶
type PromptHUD ¶
type PromptHUD struct {
Character Character `json:"character"`
CurrentState types.AgentInternalState `json:"current_state"`
PermanentGoal string `json:"permanent_goal"`
ShowCharacter bool `json:"show_character"`
}
PromptHUD contains all information that should be displayed to the LLM in the prompts
type SSEObserver ¶
type SSEObserver struct {
// contains filtered or unexported fields
}
func NewSSEObserver ¶
func NewSSEObserver(agent string, manager sse.Manager) *SSEObserver
func (*SSEObserver) ClearHistory ¶
func (s *SSEObserver) ClearHistory()
func (*SSEObserver) History ¶
func (s *SSEObserver) History() []types.Observable
func (*SSEObserver) NewObservable ¶
func (s *SSEObserver) NewObservable() *types.Observable
func (*SSEObserver) Update ¶
func (s *SSEObserver) Update(obs types.Observable)
type SearchKnowledgeBaseAction ¶
type SearchKnowledgeBaseAction struct {
*KBWrapperActions
}
func (*SearchKnowledgeBaseAction) Definition ¶
func (a *SearchKnowledgeBaseAction) Definition() types.ActionDefinition
func (*SearchKnowledgeBaseAction) Run ¶
func (a *SearchKnowledgeBaseAction) Run(ctx context.Context, sharedState *types.AgentSharedState, params types.ActionParams) (types.ActionResult, error)