types

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultLastMessageDuration = 5 * time.Minute
)
View Source
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

func IsActionUserDefined(action Action) bool

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

type ActionContext struct {
	context.Context
	// contains filtered or unexported fields
}

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 ActionResult struct {
	Job               *Job
	Result            string
	ImageBase64Result string
	Metadata          map[string]interface{}
}

type ActionState

type ActionState struct {
	ActionCurrentState
	ActionResult
}

type Actions

type Actions []Action

func (Actions) Find

func (a Actions) Find(name string) Action

func (Actions) ToCogitoTools

func (a Actions) ToCogitoTools(ctx context.Context, sharedState *AgentSharedState) []cogito.ToolDefinitionInterface

func (Actions) ToTools

func (a Actions) ToTools() []openai.Tool

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 {
	ConversationTracker *conversations.ConversationTracker[string] `json:"conversation_tracker"`
	Scheduler           TaskScheduler                              `json:"-"` // Not serialized, set at runtime
	AgentName           string                                     `json:"agent_name"`
}

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 FilterResult struct {
	HasTriggers bool   `json:"has_triggers"`
	TriggeredBy string `json:"triggered_by,omitempty"`
	FailedBy    string `json:"failed_by,omitempty"`
}

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

func NewJob(opts ...JobOption) *Job

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) Cancel

func (j *Job) Cancel()

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 (j *Job) GetContext() context.Context

func (*Job) GetEvaluationLoop

func (j *Job) GetEvaluationLoop() int

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 JobFilter

type JobFilter interface {
	Name() string
	Apply(job *Job) (bool, error)
	IsTrigger() bool
}

type JobFilters

type JobFilters []JobFilter

type JobOption

type JobOption func(*Job)

func WithBuiltinTools

func WithBuiltinTools(tools []ActionDefinition) JobOption

func WithContext

func WithContext(ctx context.Context) JobOption

func WithConversationHistory

func WithConversationHistory(history []openai.ChatCompletionMessage) JobOption

func WithMetadata

func WithMetadata(metadata map[string]any) JobOption

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 WithText

func WithText(text string) JobOption

func WithTextImage

func WithTextImage(text, image string) JobOption

func WithToolChoice

func WithToolChoice(choice string) JobOption

func WithUUID

func WithUUID(uuid string) JobOption

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 NewJobResult

func NewJobResult() *JobResult

NewJobResult creates a new job result

func (*JobResult) AddFinalizer

func (j *JobResult) AddFinalizer(f func([]openai.ChatCompletionMessage))

AddFinalizer adds a finalizer to the job result

func (*JobResult) Finish

func (j *JobResult) Finish(e error)

Finish marks the job as done and closes the ready channel.

func (*JobResult) SetResponse

func (j *JobResult) SetResponse(response string)

SetResult sets the result of a job

func (*JobResult) SetResult

func (j *JobResult) SetResult(text ActionState)

SetResult sets the result of a job

func (*JobResult) WaitResult

func (j *JobResult) WaitResult(ctx context.Context) (*JobResult, error)

WaitResult waits for 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 PromptResult struct {
	Content     string
	ImageBase64 string
}

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

Jump to

Keyboard shortcuts

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