Documentation
¶
Index ¶
Constants ¶
const ( RunRunning = "running" RunSucceeded = "succeeded" RunFailed = "failed" // RunLimited: stopped, or not started, because a rate or cost limit was // reached. RunLimited = "limited" // RunQueued: requested (run now, test run) and waiting for a worker. RunQueued = "queued" )
Run statuses.
const ( StepLLM = "llm" // a call to the agent's model StepTool = "tool" // a function call requested by the model )
Step types.
Variables ¶
This section is empty.
Functions ¶
func ValidateAgentSchema ¶
ValidateAgentSchema ensures that the agent's configuration is valid.
Types ¶
type Agent ¶
type Agent struct {
gorm.Model
Name string `json:"name" gorm:"uniqueIndex;size:191"`
SystemPrompt string `json:"system_prompt" gorm:"type:text;not null"`
MaxTurns int `json:"max_turns" gorm:"not null;default:4"`
LLMConfig LLMConfig `json:"llm_config" gorm:"type:jsonb"`
Memory MemoryConfig `json:"memory" gorm:"type:jsonb"`
Trigger TriggerConfig `json:"trigger" gorm:"type:jsonb"`
Functions FunctionSpecs `json:"functions" gorm:"type:jsonb"`
Limits Limits `json:"limits" gorm:"type:json;serializer:json"`
// RequireApproval makes content writes proposals that an editor
// approves or rejects, instead of changes.
RequireApproval bool `json:"require_approval" gorm:"not null;default:false"`
Config models.JSONMap `json:"-" gorm:"type:jsonb"`
}
Agent represents an autonomous agent configuration.
type AgentMessage ¶
type AgentMessage struct {
gorm.Model
AgentID uint `gorm:"index"` // Foreign key to the Agent
Role llm.Role `gorm:"type:varchar(20)"`
Content string `gorm:"type:text"`
ToolCallID string `gorm:"type:varchar(255)" json:"tool_call_id,omitempty"`
ToolCall *DBToolCall `gorm:"serializer:json"`
Turn int // The order of the message in the conversation
}
AgentMessage stores a single message in an agent's conversation history.
type AgentRun ¶ added in v0.5.0
type AgentRun struct {
ID uint `json:"id" gorm:"primaryKey"`
// DryRun: a test run; content functions only simulated their writes.
DryRun bool `json:"dryRun" gorm:"not null;default:false"`
AgentID uint `json:"agentId" gorm:"index:idx_agent_runs_agent_started,priority:1"`
AgentName string `json:"agentName"`
Status string `json:"status" gorm:"type:varchar(20);index"`
TriggerType string `json:"triggerType" gorm:"type:varchar(30)"` // collection_event, webhook, schedule, manual
Trigger string `json:"trigger" gorm:"type:text"` // the trigger payload (JSON, truncated)
Input string `json:"input" gorm:"type:text"` // first message sent to the model
Output string `json:"output" gorm:"type:text"` // final answer of the model
Error string `json:"error" gorm:"type:text"`
Attempt int `json:"attempt"` // 1, or more when the queue retried the job
Turns int `json:"turns"`
ToolCalls int `json:"toolCalls"`
Provider string `json:"provider"`
Model string `json:"model"`
InputTokens int `json:"inputTokens"`
OutputTokens int `json:"outputTokens"`
CostUSD float64 `json:"costUsd"`
StartedAt time.Time `json:"startedAt" gorm:"index:idx_agent_runs_agent_started,priority:2"`
FinishedAt *time.Time `json:"finishedAt"`
DurationMs int64 `json:"durationMs"`
Steps []AgentRunStep `json:"steps,omitempty" gorm:"foreignKey:RunID"`
}
AgentRun records one execution of an agent: what started it, what it did, what it cost and how it ended.
type AgentRunStep ¶ added in v0.5.0
type AgentRunStep struct {
ID uint `json:"id" gorm:"primaryKey"`
RunID uint `json:"runId" gorm:"index"`
Seq int `json:"seq"`
Type string `json:"type" gorm:"type:varchar(10)"` // llm | tool
Name string `json:"name"` // model, or function name
ImplKey string `json:"implKey,omitempty"` // tool steps
Arguments string `json:"arguments" gorm:"type:text"` // tool arguments (JSON, truncated)
Result string `json:"result" gorm:"type:text"` // model text / tool result (truncated)
Error string `json:"error" gorm:"type:text"`
InputTokens int `json:"inputTokens"`
OutputTokens int `json:"outputTokens"`
CostUSD float64 `json:"costUsd"`
DurationMs int64 `json:"durationMs"`
CreatedAt time.Time `json:"createdAt"`
}
AgentRunStep is one LLM call or one function call of a run.
type DBToolCall ¶
type DBToolCall struct {
ID string `json:"id"`
Type string `json:"type"`
FunctionName string `json:"function_name"`
Arguments string `json:"arguments"`
}
DBToolCall represents a simplified tool call for database storage
func FromLangChainToolCall ¶
func FromLangChainToolCall(tc *llms.ToolCall) *DBToolCall
FromLangChainToolCall creates DBToolCall from llms.ToolCall
func (*DBToolCall) ToLangChainToolCall ¶
func (d *DBToolCall) ToLangChainToolCall() *llms.ToolCall
ToLangChainToolCall converts a DBToolCall to llms.ToolCall.
type EventTriggerConfig ¶
type EventTriggerConfig struct {
Collection string `json:"collection"` // The name of the collection to listen to.
Events []string `json:"events"` // e.g., ["item:created", "item:updated"]
}
EventTriggerConfig defines the specifics for a collection event trigger.
type FunctionSpec ¶
type FunctionSpec struct {
Name string `json:"name"` // The name the model sees
Description string `json:"description"` // What the model is told about it
Parameters models.JSONMap `json:"parameters"` // JSON schema of its arguments
ImplKey string `json:"impl_key"` // The built-in implementation
// Collections restricts the collections.* functions to these
// collections. Empty: every collection (not recommended for writes).
Collections []string `json:"collections,omitempty"`
// Approval: calls wait for an admin's approval (true) or not (false).
// Unset: the tools of connected apps that may change something wait,
// the others don't.
Approval *bool `json:"approval,omitempty"`
}
FunctionSpec is a tool of an agent, as stored. Name, Description and Parameters are optional: empty, they come from the tool catalog (see Resolved). Agents written with the short form ("tools") store only what they override.
func (FunctionSpec) ForModel ¶ added in v0.7.0
func (f FunctionSpec) ForModel() FunctionSpec
ForModel is the function as the model gets it: Resolved, and a default description says which collections a scoped tool may use. (The scope note stays out of Resolved, which the API returns: a client sending it back would store it as a custom description.)
func (FunctionSpec) Resolved ¶ added in v0.7.0
func (f FunctionSpec) Resolved() FunctionSpec
Resolved returns the function as the model gets it: the name, the description and the parameters it leaves out come from the catalog.
type FunctionSpecs ¶
type FunctionSpecs []FunctionSpec
func (FunctionSpecs) GormDBDataType ¶ added in v0.5.0
GormDBDataType makes the column JSON on MySQL.
func (FunctionSpecs) Resolved ¶ added in v0.7.0
func (f FunctionSpecs) Resolved() FunctionSpecs
Resolved returns every function as the model gets it.
func (*FunctionSpecs) Scan ¶
func (f *FunctionSpecs) Scan(value any) error
Scan implements sql.Scanner for FunctionSpecs, accepting either a JSON array of FunctionSpec or a single JSON object (which will be wrapped into a slice).
func (FunctionSpecs) Tools ¶ added in v0.7.0
func (f FunctionSpecs) Tools() []Tool
Tools returns an agent's functions in the short form.
type LLMConfig ¶
type LLMConfig struct {
Provider string `json:"provider"`
Model string `json:"model"`
APIKey string `json:"api_key"`
APISecret string `json:"api_secret"`
BaseURL string `json:"base_url,omitempty"` // optional API endpoint override
// Prices in USD per million tokens (for cost tracking and limits).
InputCostPerMillion float64 `json:"input_cost_per_million,omitempty"`
OutputCostPerMillion float64 `json:"output_cost_per_million,omitempty"`
}
LLMConfig specifies the large language model to use.
func (LLMConfig) GormDBDataType ¶ added in v0.5.0
GormDBDataType makes the column JSON on MySQL.
type Limits ¶ added in v0.5.0
type Limits struct {
MaxRunsPerHour int `json:"max_runs_per_hour,omitempty"`
MaxRunsPerDay int `json:"max_runs_per_day,omitempty"`
MaxTokensPerRun int `json:"max_tokens_per_run,omitempty"`
MaxTokensPerDay int `json:"max_tokens_per_day,omitempty"`
MaxCostPerDay float64 `json:"max_cost_per_day,omitempty"` // USD; needs prices in llm_config
}
Limits bound how much an agent may run and spend. Zero means no limit. Windows are rolling: "per hour" is the last 60 minutes, "per day" the last 24 hours.
type MemoryConfig ¶
type MemoryConfig struct {
Type string `json:"type"` // e.g., "in-memory", "postgres"
SessionScope string `json:"session_scope"`
}
MemoryConfig defines how the conversation memory is stored.
func (MemoryConfig) GormDBDataType ¶ added in v0.5.0
GormDBDataType makes the column JSON on MySQL.
func (*MemoryConfig) Scan ¶
func (c *MemoryConfig) Scan(value interface{}) error
Scan implements the Scanner interface for `MemoryConfig`.
type Tool ¶ added in v0.7.0
type Tool struct {
// Use names the tool: "content.update", or its implementation key
// "collections.patch_item".
Use string `json:"use"`
// On restricts a content tool to these collections.
On []string `json:"on,omitempty"`
// Name, Description and Parameters override the catalog's (the name
// the model sees, what it is told, the arguments' JSON schema).
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
Parameters models.JSONMap `json:"parameters,omitempty"`
// Approval makes a connected app's tool wait for an admin's approval
// (true) or not (false). Default: tools that may change something wait.
Approval *bool `json:"approval,omitempty"`
}
Tool is the short way to give an agent a built-in tool: which one, and on which collections. Everything else comes from the catalog unless the agent overrides it.
{"use": "content.update", "on": ["articles"]}
func ToolOf ¶ added in v0.7.0
func ToolOf(f FunctionSpec) Tool
ToolOf returns a stored function in the short form: only what differs from the catalog.
func (Tool) Spec ¶ added in v0.7.0
func (t Tool) Spec() FunctionSpec
Spec is the tool as an agent stores it.
type TriggerConfig ¶
type TriggerConfig struct {
Type string `json:"type"` // e.g., "manual", "cron", "webhook", "collection_event"
Cron string `json:"cron,omitempty"`
WebhookToken string `json:"webhook_token,omitempty"`
EventTrigger EventTriggerConfig `json:"event_trigger,omitempty"`
}
TriggerConfig defines what initiates an agent's run.
func (TriggerConfig) GormDBDataType ¶ added in v0.5.0
GormDBDataType makes the column JSON on MySQL.
func (*TriggerConfig) Scan ¶
func (t *TriggerConfig) Scan(value any) error
Scan implements the Scanner interface for `TriggerConfig`. This version is now robust and handles both []byte and string from the database.