Documentation
¶
Index ¶
- Constants
- func IsActionUserDefined(action Action) bool
- type Action
- type ActionContext
- type ActionCurrentState
- type ActionDefinition
- type ActionDefinitionName
- type ActionParams
- type ActionRequest
- type ActionResult
- type ActionState
- type Actions
- type AgentInternalState
- type AgentSharedState
- type BaseAction
- type Completion
- type ConversationMessage
- type Creation
- type FilterResult
- type Job
- func (j *Job) Callback(stateResult ActionCurrentState) bool
- func (j *Job) CallbackWithResult(stateResult ActionState)
- func (j *Job) Cancel()
- func (j *Job) GetAllTools() []ActionDefinition
- func (j *Job) GetBuiltinTools() []ActionDefinition
- func (j *Job) GetContext() context.Context
- func (j *Job) GetEvaluationLoop() int
- func (j *Job) GetUserTools() []ActionDefinition
- func (j *Job) IncrementEvaluationLoop()
- type JobFilter
- type JobFilters
- type JobOption
- func WithBuiltinTools(tools []ActionDefinition) JobOption
- func WithContext(ctx context.Context) JobOption
- func WithConversationHistory(history []openai.ChatCompletionMessage) JobOption
- func WithMetadata(metadata map[string]any) JobOption
- func WithObservable(obs *Observable) JobOption
- func WithReasoningCallback(f func(ActionCurrentState) bool) JobOption
- func WithResultCallback(f func(ActionState)) JobOption
- func WithText(text string) JobOption
- func WithTextImage(text, image string) JobOption
- func WithToolChoice(choice string) JobOption
- func WithUUID(uuid string) JobOption
- func WithUserTools(tools []ActionDefinition) JobOption
- type JobResult
- type Observable
- type OneTimeReminderParams
- type Progress
- type PromptResult
- type RecurringReminderParams
- type ReminderActionResponse
- type TaskScheduler
- type UserDefinedAction
- type UserDefinedChecker
Constants ¶
const (
DefaultLastMessageDuration = 5 * time.Minute
)
const MetadataKeyConversationID = "conversation_id"
MetadataKeyConversationID is the job metadata key for per-conversation identity. When set (e.g. "slack:CHANNEL_ID", "telegram:CHAT_ID"), the agent may cancel the currently running job for that conversation before enqueueing a new one.
Variables ¶
This section is empty.
Functions ¶
func IsActionUserDefined ¶
IsActionUserDefined checks if an action is user-defined
Types ¶
type Action ¶
type Action interface {
Run(ctx context.Context, sharedState *AgentSharedState, action ActionParams) (ActionResult, error)
Definition() ActionDefinition
}
Actions is something the agent can do
func CreateUserDefinedActions ¶
func CreateUserDefinedActions(userTools []ActionDefinition) []Action
CreateUserDefinedActions converts user tools to UserDefinedAction instances
type ActionContext ¶
func NewActionContext ¶
func NewActionContext(ctx context.Context, cancel context.CancelFunc) *ActionContext
func (*ActionContext) Cancel ¶
func (ac *ActionContext) Cancel()
type ActionCurrentState ¶
type ActionCurrentState struct {
Job *Job
Action Action
Params ActionParams
Reasoning string
}
type ActionDefinition ¶
type ActionDefinition struct {
Properties map[string]jsonschema.Definition
Required []string
Name ActionDefinitionName
Description string
}
func (ActionDefinition) ToFunctionDefinition ¶
func (a ActionDefinition) ToFunctionDefinition() *openai.FunctionDefinition
type ActionDefinitionName ¶
type ActionDefinitionName string
func (ActionDefinitionName) Is ¶
func (a ActionDefinitionName) Is(name string) bool
func (ActionDefinitionName) String ¶
func (a ActionDefinitionName) String() string
type ActionParams ¶
type ActionParams map[string]interface{}
func (ActionParams) Read ¶
func (ap ActionParams) Read(s string) error
func (ActionParams) String ¶
func (ap ActionParams) String() string
func (ActionParams) Unmarshal ¶
func (ap ActionParams) Unmarshal(v interface{}) error
type ActionRequest ¶
type ActionRequest struct {
Action Action
Params *ActionParams
}
type ActionResult ¶
type ActionState ¶
type ActionState struct {
ActionCurrentState
ActionResult
}
type Actions ¶
type Actions []Action
func (Actions) ToCogitoTools ¶
func (a Actions) ToCogitoTools(ctx context.Context, sharedState *AgentSharedState) []cogito.ToolDefinitionInterface
type AgentInternalState ¶
type AgentInternalState struct {
NowDoing string `json:"doing_now"`
DoingNext string `json:"doing_next"`
DoneHistory []string `json:"done_history"`
Memories []string `json:"memories"`
Goal string `json:"goal"`
}
State is the structure that is used to keep track of the current state and the Agent's short memory that it can update Besides a long term memory that is accessible by the agent (With vector database), And a context memory (that is always powered by a vector database), this memory is the shorter one that the LLM keeps across conversation and across its reasoning process's and life time. TODO: A special action is then used to let the LLM itself update its memory periodically during self-processing, and the same action is ALSO exposed during the conversation to let the user put for example, a new goal to the agent.
func (AgentInternalState) String ¶
func (c AgentInternalState) String() string
type AgentSharedState ¶
type AgentSharedState struct {
}
func NewAgentSharedState ¶
func NewAgentSharedState(lastMessageDuration time.Duration) *AgentSharedState
type BaseAction ¶
type BaseAction struct{}
BaseAction provides default implementation for Action interface Embed this in action implementations to get the default IsUserDefined behavior
func (*BaseAction) IsUserDefined ¶
func (b *BaseAction) IsUserDefined() bool
type Completion ¶
type Completion struct {
Error string `json:"error,omitempty"`
ChatCompletionResponse *openai.ChatCompletionResponse `json:"chat_completion_response,omitempty"`
Conversation []openai.ChatCompletionMessage `json:"conversation,omitempty"`
ActionResult string `json:"action_result,omitempty"`
AgentState *AgentInternalState `json:"agent_state,omitempty"`
FilterResult *FilterResult `json:"filter_result,omitempty"`
}
type ConversationMessage ¶
type ConversationMessage struct {
Message openai.ChatCompletionMessage
Metadata map[string]interface{}
}
ConversationMessage represents a message with associated metadata Used when the agent initiates new conversations to preserve context such as generated images, files, or URLs
func NewConversationMessage ¶
func NewConversationMessage(msg openai.ChatCompletionMessage) *ConversationMessage
NewConversationMessage creates a new ConversationMessage with the given message
func (*ConversationMessage) WithMetadata ¶
func (c *ConversationMessage) WithMetadata(metadata map[string]interface{}) *ConversationMessage
WithMetadata adds metadata to the conversation message
type Creation ¶
type Creation struct {
ChatCompletionMessage *openai.ChatCompletionMessage `json:"chat_completion_message,omitempty"`
ChatCompletionRequest *openai.ChatCompletionRequest `json:"chat_completion_request,omitempty"`
FunctionDefinition *openai.FunctionDefinition `json:"function_definition,omitempty"`
FunctionParams ActionParams `json:"function_params,omitempty"`
}
type FilterResult ¶
type Job ¶
type Job struct {
// The job is a request to the agent to do something
// It can be a question, a command, or a request to do something
// The agent will try to do it, and return a response
Result *JobResult
ReasoningCallback func(ActionCurrentState) bool
ResultCallback func(ActionState)
ConversationHistory []openai.ChatCompletionMessage
UUID string
Metadata map[string]interface{}
DoneFilter bool
// Tools available for this job
BuiltinTools []ActionDefinition // Built-in tools like web search
UserTools []ActionDefinition // User-defined function tools
ToolChoice string
Obs *Observable
// contains filtered or unexported fields
}
Job is a request to the agent to do something
func NewJob ¶
NewJob creates a new job It is a request to the agent to do something It has a JobResult to get the result asynchronously To wait for a Job result, use JobResult.WaitResult()
func (*Job) Callback ¶
func (j *Job) Callback(stateResult ActionCurrentState) bool
func (*Job) CallbackWithResult ¶
func (j *Job) CallbackWithResult(stateResult ActionState)
func (*Job) GetAllTools ¶
func (j *Job) GetAllTools() []ActionDefinition
GetAllTools returns all tools (builtin + user) for this job
func (*Job) GetBuiltinTools ¶
func (j *Job) GetBuiltinTools() []ActionDefinition
GetBuiltinTools returns the builtin tools for this job
func (*Job) GetContext ¶
func (*Job) GetEvaluationLoop ¶
GetEvaluationLoop returns the current evaluation loop count
func (*Job) GetUserTools ¶
func (j *Job) GetUserTools() []ActionDefinition
GetUserTools returns the user tools for this job
func (*Job) IncrementEvaluationLoop ¶
func (j *Job) IncrementEvaluationLoop()
IncrementEvaluationLoop increments the evaluation loop count
type JobFilters ¶
type JobFilters []JobFilter
type JobOption ¶
type JobOption func(*Job)
func WithBuiltinTools ¶
func WithBuiltinTools(tools []ActionDefinition) JobOption
func WithContext ¶
func WithConversationHistory ¶
func WithConversationHistory(history []openai.ChatCompletionMessage) JobOption
func WithMetadata ¶
func WithObservable ¶
func WithObservable(obs *Observable) JobOption
func WithReasoningCallback ¶
func WithReasoningCallback(f func(ActionCurrentState) bool) JobOption
func WithResultCallback ¶
func WithResultCallback(f func(ActionState)) JobOption
func WithTextImage ¶
func WithToolChoice ¶
func WithUserTools ¶
func WithUserTools(tools []ActionDefinition) JobOption
type JobResult ¶
type JobResult struct {
sync.Mutex
// The result of a job
State []ActionState
Plans []cogito.PlanStatus
Conversation []openai.ChatCompletionMessage
Finalizers []func([]openai.ChatCompletionMessage)
Response string
Error error
// contains filtered or unexported fields
}
JobResult is the result of a job
func (*JobResult) AddFinalizer ¶
func (j *JobResult) AddFinalizer(f func([]openai.ChatCompletionMessage))
AddFinalizer adds a finalizer to the job result
func (*JobResult) SetResponse ¶
SetResult sets the result of a job
func (*JobResult) SetResult ¶
func (j *JobResult) SetResult(text ActionState)
SetResult sets the result of a job
type Observable ¶
type Observable struct {
ID int32 `json:"id"`
ParentID int32 `json:"parent_id,omitempty"`
Agent string `json:"agent"`
Name string `json:"name"`
Icon string `json:"icon"`
Creation *Creation `json:"creation,omitempty"`
Progress []Progress `json:"progress,omitempty"`
Completion *Completion `json:"completion,omitempty"`
}
func (*Observable) AddProgress ¶
func (o *Observable) AddProgress(p Progress)
func (*Observable) MakeLastProgressCompletion ¶
func (o *Observable) MakeLastProgressCompletion()
type OneTimeReminderParams ¶
type OneTimeReminderParams struct {
Message string `json:"message"`
Delay string `json:"delay"` // Go duration format with day support: "30m", "2h", "1d", "1d12h"
}
OneTimeReminderParams are the parameters the LLM provides for set_onetime_reminder.
type Progress ¶
type Progress struct {
Error string `json:"error,omitempty"`
ChatCompletionResponse *openai.ChatCompletionResponse `json:"chat_completion_response,omitempty"`
ActionResult string `json:"action_result,omitempty"`
AgentState *AgentInternalState `json:"agent_state"`
}
type PromptResult ¶
type RecurringReminderParams ¶
type RecurringReminderParams struct {
Message string `json:"message"`
CronExpr string `json:"cron_expr"`
}
RecurringReminderParams are the parameters the LLM provides for set_recurring_reminder.
type ReminderActionResponse ¶
type ReminderActionResponse = RecurringReminderParams
ReminderActionResponse is kept for backward compatibility. Deprecated: use RecurringReminderParams or OneTimeReminderParams.
type TaskScheduler ¶
type TaskScheduler interface {
CreateTask(task *scheduler.Task) error
GetAllTasks() ([]*scheduler.Task, error)
GetTask(id string) (*scheduler.Task, error)
DeleteTask(id string) error
PauseTask(id string) error
ResumeTask(id string) error
}
Forward declaration to avoid circular import
type UserDefinedAction ¶
type UserDefinedAction struct {
ActionDef *ActionDefinition
}
UserDefinedAction represents a user-defined function tool
func (*UserDefinedAction) Definition ¶
func (u *UserDefinedAction) Definition() ActionDefinition
func (*UserDefinedAction) IsUserDefined ¶
func (u *UserDefinedAction) IsUserDefined() bool
func (*UserDefinedAction) Plannable ¶
func (u *UserDefinedAction) Plannable() bool
func (*UserDefinedAction) Run ¶
func (u *UserDefinedAction) Run(ctx context.Context, sharedState *AgentSharedState, action ActionParams) (ActionResult, error)
type UserDefinedChecker ¶
type UserDefinedChecker interface {
IsUserDefined() bool
}
UserDefinedChecker interface to identify user-defined actions