agent

package
v0.0.0-...-27cc58a Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2026 License: MIT Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UserRole      = "user"
	AssistantRole = "assistant"
	SystemRole    = "system"
)

Variables

View Source
var CanStopItself = func(o *options) error {
	o.canStopItself = true
	return nil
}
View Source
var DisableSinkState = func(o *options) error {
	o.disableSinkState = true
	return nil
}
View Source
var EnableForceReasoning = func(o *options) error {
	o.forceReasoning = true
	return nil
}
View Source
var EnableForceReasoningTool = func(o *options) error {
	o.forceReasoningTool = true
	return nil
}
View Source
var EnableGuidedTools = func(o *options) error {
	o.enableGuidedTools = true
	return nil
}
View Source
var EnableHUD = func(o *options) error {
	o.enableHUD = true
	return nil
}
View Source
var EnableInitiateConversations = func(o *options) error {
	o.initiateConversations = true
	return nil
}
View Source
var EnableKnowledgeBase = func(o *options) error {
	o.enableKB = true
	o.kbResults = 5
	return nil
}
View Source
var EnableLongTermMemory = func(o *options) error {
	o.enableLongTermMemory = true
	return nil
}
View Source
var EnablePersonality = func(o *options) error {
	o.showCharacter = true
	return nil
}
View Source
var EnablePlanning = func(o *options) error {
	o.canPlan = true
	return nil
}
View Source
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

View Source
var EnableStripThinkingTags = func(o *options) error {
	o.stripThinkingTags = true
	return nil
}
View Source
var EnableSummaryMemory = func(o *options) error {
	o.enableSummaryMemory = true
	return nil
}
View Source
var ErrContextCanceled = fmt.Errorf("context canceled")
View Source
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 (*AddToKnowledgeBaseAction) Run

type Agent

type Agent struct {
	sync.Mutex

	Character Character
	// contains filtered or unexported fields
}

func New

func New(opts ...Option) (*Agent, error)

func (*Agent) AddSubscriber

func (a *Agent) AddSubscriber(f func(*types.ConversationMessage))

func (*Agent) Ask

func (a *Agent) Ask(opts ...types.JobOption) *types.JobResult

Ask is a blocking call that returns the response as soon as it's ready. It discards any other computation.

func (*Agent) Context

func (a *Agent) Context() context.Context

func (*Agent) Enqueue

func (a *Agent) Enqueue(j *types.Job)

func (*Agent) Execute

func (a *Agent) Execute(j *types.Job) *types.JobResult

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 (a *Agent) LoadCharacter(path string) error

func (*Agent) LoadState

func (a *Agent) LoadState(path string) error

func (*Agent) Memory

func (a *Agent) Memory() RAGDB

func (*Agent) Observer

func (a *Agent) Observer() Observer

func (*Agent) Pause

func (a *Agent) Pause()

func (*Agent) Paused

func (a *Agent) Paused() bool

func (*Agent) Resume

func (a *Agent) Resume()

func (*Agent) Run

func (a *Agent) Run() error

func (*Agent) SaveCharacter

func (a *Agent) SaveCharacter(path string) error

func (*Agent) SaveState

func (a *Agent) SaveState(path string) error

func (*Agent) SharedState

func (a *Agent) SharedState() *types.AgentSharedState

func (*Agent) State

func (a *Agent) State() types.AgentInternalState

func (*Agent) Stop

func (a *Agent) Stop()

func (*Agent) TTS

func (a *Agent) TTS(ctx context.Context, text string) ([]byte, error)

func (*Agent) Transcribe

func (a *Agent) Transcribe(ctx context.Context, file string) (string, error)

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 Load

func Load(path string) (*Character, error)

func (*Character) String

func (c *Character) String() string

func (*Character) ToJSONSchema

func (c *Character) ToJSONSchema() jsonschema.Definition

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 KBWrapperActions

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

KBWrapperActions wraps RAGDB functionality as actions

type MCPSTDIOServer

type MCPSTDIOServer struct {
	Name string   `json:"name,omitempty"`
	Args []string `json:"args"`
	Env  []string `json:"env"`
	Cmd  string   `json:"cmd"`
}

type MCPServer

type MCPServer struct {
	URL   string `json:"url"`
	Token string `json:"token"`
}

type Messages

type Messages []openai.ChatCompletionMessage

func (Messages) Exist

func (m Messages) Exist(content string) bool

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 (m Messages) RemoveLastUserMessage() Messages

func (Messages) Save

func (m Messages) Save(path string) error

func (Messages) String

func (m Messages) String() string

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

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 EnableKnowledgeBaseWithResults

func EnableKnowledgeBaseWithResults(results int) Option

func FromFile

func FromFile(path string) Option

func WithActions

func WithActions(actions ...types.Action) Option

func WithAgentReasoningCallback

func WithAgentReasoningCallback(cb func(types.ActionCurrentState) bool) Option

func WithAgentResultCallback

func WithAgentResultCallback(cb func(types.ActionState)) Option

func WithCharacter

func WithCharacter(c Character) Option

func WithCharacterFile

func WithCharacterFile(path string) Option

func WithContext

func WithContext(ctx context.Context) Option

func WithConversationStorageMode

func WithConversationStorageMode(mode ConversationStorageMode) Option

WithConversationStorageMode sets how conversations are stored in the knowledge base

func WithConversationsPath

func WithConversationsPath(path string) Option

func WithJobFilters

func WithJobFilters(filters ...types.JobFilter) Option

func WithKBAutoSearch

func WithKBAutoSearch(enabled bool) Option

func WithLLMAPIKey

func WithLLMAPIKey(key string) Option

func WithLLMAPIURL

func WithLLMAPIURL(url string) Option

func WithLastMessageDuration

func WithLastMessageDuration(duration string) Option

func WithMCPPrepareScript

func WithMCPPrepareScript(script string) Option

func WithMCPSTDIOServers

func WithMCPSTDIOServers(servers ...MCPSTDIOServer) Option

func WithMCPServers

func WithMCPServers(servers ...MCPServer) Option

func WithMaxEvaluationLoops

func WithMaxEvaluationLoops(loops int) Option

func WithModel

func WithModel(model string) Option

func WithMultimodalModel

func WithMultimodalModel(model string) Option

func WithNewConversationSubscriber

func WithNewConversationSubscriber(sub func(*types.ConversationMessage)) Option

func WithObserver

func WithObserver(observer Observer) Option

func WithParallelJobs

func WithParallelJobs(jobs int) Option

func WithPeriodicRuns

func WithPeriodicRuns(duration string) Option

func WithPermanentGoal

func WithPermanentGoal(goal string) Option

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 WithRAGDB

func WithRAGDB(db RAGDB) Option

func WithRandomIdentity

func WithRandomIdentity(guidance ...string) Option

func WithSchedulerPollInterval

func WithSchedulerPollInterval(duration string) Option

func WithSchedulerStorePath

func WithSchedulerStorePath(path string) Option

WithSchedulerStorePath sets the path for the scheduler's JSON storage file

func WithStateFile

func WithStateFile(path string) Option

func WithSystemPrompt

func WithSystemPrompt(prompt string) Option

func WithTTSModel

func WithTTSModel(model string) Option

func WithTimeout

func WithTimeout(timeout string) Option

func WithTranscriptionLanguage

func WithTranscriptionLanguage(language string) Option

func WithTranscriptionModel

func WithTranscriptionModel(model string) Option

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 RAGDB

type RAGDB interface {
	Store(s string) error
	Reset() error
	Search(s string, similarEntries int) ([]string, error)
	Count() int
}

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 (*SearchKnowledgeBaseAction) Run

type ToolInputSchema

type ToolInputSchema struct {
	Type       string                 `json:"type"`
	Properties map[string]interface{} `json:"properties,omitempty"`
	Required   []string               `json:"required,omitempty"`
}

Jump to

Keyboard shortcuts

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