models

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: MIT Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
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.

View Source
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

func ValidateAgentSchema(agent Agent) error

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.

func ParseAgentInput

func ParseAgentInput(input map[string]any) (Agent, error)

ParseAgentInput parses a generic map into a typed Agent struct. It handles potential data type mismatches gracefully and then validates the schema.

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 of the function
	Description string         `json:"description"` // A description for the LLM
	Parameters  models.JSONMap `json:"parameters"`  // JSON schema for the function's parameters
	ImplKey     string         `json:"impl_key"`    // Key used to look up the actual implementation
	// Collections restricts the collections.* functions to these
	// collections. Empty: every collection (not recommended for writes).
	Collections []string `json:"collections,omitempty"`
}

FunctionSpec describes a tool the agent can call. FunctionSpec represents a tool or function the agent can use.

type FunctionSpecs

type FunctionSpecs []FunctionSpec

func (FunctionSpecs) GormDBDataType added in v0.5.0

func (FunctionSpecs) GormDBDataType(db *gorm.DB, field *schema.Field) string

GormDBDataType makes the column JSON on MySQL.

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

func (f FunctionSpecs) Value() (driver.Value, error)

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

func (LLMConfig) GormDBDataType(db *gorm.DB, field *schema.Field) string

GormDBDataType makes the column JSON on MySQL.

func (*LLMConfig) Scan

func (c *LLMConfig) Scan(value any) error

Scan implements the Scanner interface for `LLMConfig`.

func (LLMConfig) Value

func (c LLMConfig) Value() (driver.Value, error)

Value implements the Valuer interface for `LLMConfig`.

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.

func (Limits) Any added in v0.5.0

func (l Limits) Any() bool

Any reports whether a limit is set.

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

func (MemoryConfig) GormDBDataType(db *gorm.DB, field *schema.Field) string

GormDBDataType makes the column JSON on MySQL.

func (*MemoryConfig) Scan

func (c *MemoryConfig) Scan(value interface{}) error

Scan implements the Scanner interface for `MemoryConfig`.

func (MemoryConfig) Value

func (c MemoryConfig) Value() (driver.Value, error)

Value implements the Valuer interface for `MemoryConfig`.

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

func (TriggerConfig) GormDBDataType(db *gorm.DB, field *schema.Field) string

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.

func (TriggerConfig) Value

func (t TriggerConfig) Value() (driver.Value, error)

Value implements the Valuer interface for `TriggerConfig`. It marshals the struct into JSON for storage in the database.

Jump to

Keyboard shortcuts

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