agentruntime

package
v0.31.36 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultWorkspaceID = "default"

Variables

This section is empty.

Functions

func NormalizeWorkspaceID

func NormalizeWorkspaceID(workspaceID string) string

func WithPromptExecution

func WithPromptExecution(ctx context.Context, override *ProviderOverride, source string, metadata *PromptExecutionMetadata) context.Context

Types

type AgentExecutor

type AgentExecutor interface {
	Info() AgentInfo
	Execute(ctx context.Context, req ExecuteRequest) (string, error)
}

type AgentInfo

type AgentInfo struct {
	Name               string            `json:"name"`
	Description        string            `json:"description,omitempty"`
	Enabled            bool              `json:"enabled"`
	Kind               string            `json:"kind,omitempty"`
	Source             string            `json:"source,omitempty"`
	Entry              string            `json:"entry,omitempty"`
	PolicyMode         string            `json:"policy_mode"`
	ToolsAllow         []string          `json:"tools_allow,omitempty"`
	ToolsAllowCount    int               `json:"tools_allow_count"`
	ToolsDeny          []string          `json:"tools_deny,omitempty"`
	ToolsDenyCount     int               `json:"tools_deny_count"`
	ToolsRiskMax       string            `json:"tools_risk_max,omitempty"`
	ToolsAllowGroups   []string          `json:"tools_allow_groups,omitempty"`
	ToolsDenyGroups    []string          `json:"tools_deny_groups,omitempty"`
	ToolsAllowPatterns []string          `json:"tools_allow_patterns,omitempty"`
	SessionRoutingMode string            `json:"session_routing_mode,omitempty"`
	SessionFixedID     string            `json:"session_fixed_id,omitempty"`
	Tier               string            `json:"tier,omitempty"`
	ProviderOverride   *ProviderOverride `json:"provider_override,omitempty"`
}

type AgentRuntimeStatus added in v0.31.5

type AgentRuntimeStatus struct {
	Enabled                    bool   `json:"enabled"`
	Version                    int64  `json:"version"`
	RunsTotal                  int    `json:"runs_total"`
	RunsActive                 int    `json:"runs_active"`
	AgentsCount                int    `json:"agents_count"`
	AgentsWatchEnabled         bool   `json:"agents_watch_enabled"`
	AgentsReloadVersion        int64  `json:"agents_reload_version"`
	AgentsLastReloadAt         string `json:"agents_last_reload_at,omitempty"`
	ChannelsLocal              bool   `json:"channels_local_enabled"`
	ChannelsWebhook            bool   `json:"channels_webhook_enabled"`
	ChannelsTelegram           bool   `json:"channels_telegram_enabled"`
	PersistenceEnabled         bool   `json:"persistence_enabled"`
	RunsPersistenceEnabled     bool   `json:"runs_persistence_enabled"`
	ChannelsPersistenceEnabled bool   `json:"channels_persistence_enabled"`
	RestoreOnStartup           bool   `json:"restore_on_startup"`
	PersistenceDir             string `json:"persistence_dir,omitempty"`
	RunsRestored               int    `json:"runs_restored"`
	ChannelsRestored           int    `json:"channels_restored"`
	LastPersistAt              string `json:"last_persist_at,omitempty"`
	LastRestoreAt              string `json:"last_restore_at,omitempty"`
	LastRestoreError           string `json:"last_restore_error,omitempty"`
	LastReloadAt               string `json:"last_reload_at,omitempty"`
	LastRestartAt              string `json:"last_restart_at,omitempty"`
}

type ChannelMessage

type ChannelMessage struct {
	ID          string         `json:"id"`
	WorkspaceID string         `json:"-"`
	ChannelID   string         `json:"channel_id"`
	ThreadID    string         `json:"thread_id,omitempty"`
	Direction   string         `json:"direction"`
	Source      string         `json:"source"`
	Text        string         `json:"text"`
	Payload     map[string]any `json:"payload,omitempty"`
	Timestamp   string         `json:"timestamp"`
}

type CommandExecutor

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

func NewCommandExecutor

func NewCommandExecutor(opts CommandExecutorOptions) (*CommandExecutor, error)

func (*CommandExecutor) Execute

func (e *CommandExecutor) Execute(ctx context.Context, req ExecuteRequest) (string, error)

func (*CommandExecutor) Info

func (e *CommandExecutor) Info() AgentInfo

type CommandExecutorOptions

type CommandExecutorOptions struct {
	Name        string
	Description string
	Source      string
	Entry       string
	Command     string
	Args        []string
	Env         map[string]string
	WorkDir     string
	Timeout     time.Duration
}

type ConsensusSpec

type ConsensusSpec struct {
	Strategy   string             `json:"strategy,omitempty"`
	Variants   []ProviderOverride `json:"variants,omitempty"`
	Aggregator *ProviderOverride  `json:"aggregator,omitempty"`
}

type ConsensusVariantRecord

type ConsensusVariantRecord struct {
	VariantIdx int     `json:"variant_idx"`
	Alias      string  `json:"alias,omitempty"`
	Kind       string  `json:"kind,omitempty"`
	Model      string  `json:"model,omitempty"`
	Status     string  `json:"status,omitempty"`
	Response   string  `json:"response,omitempty"`
	Error      string  `json:"error,omitempty"`
	TokensIn   int     `json:"tokens_in,omitempty"`
	TokensOut  int     `json:"tokens_out,omitempty"`
	CostUSD    float64 `json:"cost_usd,omitempty"`
	StartedAt  string  `json:"started_at,omitempty"`
	FinishedAt string  `json:"finished_at,omitempty"`
}

type ExecuteRequest

type ExecuteRequest struct {
	RunID            string
	WorkspaceID      string
	SessionID        string
	Prompt           string
	AllowedTools     []string
	Tier             string
	ProviderOverride *ProviderOverride
	OverrideSource   string
	Metadata         *PromptExecutionMetadata
}

type PromptExecutionContext

type PromptExecutionContext struct {
	ProviderOverride *ProviderOverride
	OverrideSource   string
	Metadata         *PromptExecutionMetadata
}

func PromptExecutionFromContext

func PromptExecutionFromContext(ctx context.Context) PromptExecutionContext

type PromptExecutionMetadata

type PromptExecutionMetadata struct {
	ResolvedAlias  string
	ResolvedKind   string
	ResolvedModel  string
	OverrideSource string
}

func ResolveOverride

func ResolveOverride(cfg *config.Config, tier string, override *ProviderOverride, overrideSource string) (config.ResolvedLLMTier, PromptExecutionMetadata, error)

type PromptExecutor

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

func NewPromptExecutor

func NewPromptExecutor(name, description string, runPrompt func(ctx context.Context, runLabel string, prompt string) (string, error)) (*PromptExecutor, error)

func NewPromptExecutorWithOptions

func NewPromptExecutorWithOptions(opts PromptExecutorOptions) (*PromptExecutor, error)

func (*PromptExecutor) Execute

func (e *PromptExecutor) Execute(ctx context.Context, req ExecuteRequest) (string, error)

func (*PromptExecutor) Info

func (e *PromptExecutor) Info() AgentInfo

type PromptExecutorOptions

type PromptExecutorOptions struct {
	Name               string
	Description        string
	Source             string
	Entry              string
	PolicyMode         string
	ToolsAllow         []string
	ToolsDeny          []string
	ToolsRiskMax       string
	ToolsAllowGroups   []string
	ToolsDenyGroups    []string
	ToolsAllowPatterns []string
	SessionRoutingMode string
	SessionFixedID     string
	Tier               string
	ProviderOverride   *ProviderOverride
	RunPrompt          func(ctx context.Context, runLabel string, prompt string, allowedTools []string, tier string, providerOverride *ProviderOverride) (string, error)
}

type ProviderOverride

type ProviderOverride struct {
	Alias string `json:"alias,omitempty" yaml:"alias,omitempty"`
	Model string `json:"model,omitempty" yaml:"model,omitempty"`
}

func CloneProviderOverride

func CloneProviderOverride(value *ProviderOverride) *ProviderOverride

type ReportChannels

type ReportChannels struct {
	GeneratedAt    string                      `json:"generated_at"`
	ArchiveEnabled bool                        `json:"archive_enabled"`
	Count          int                         `json:"count"`
	Messages       map[string][]ChannelMessage `json:"messages"`
}

type ReportRuns

type ReportRuns struct {
	GeneratedAt    string `json:"generated_at"`
	ArchiveEnabled bool   `json:"archive_enabled"`
	Count          int    `json:"count"`
	Runs           []Run  `json:"runs"`
}

type ReportSummary

type ReportSummary struct {
	GeneratedAt      string         `json:"generated_at"`
	SummaryEnabled   bool           `json:"summary_enabled"`
	ArchiveEnabled   bool           `json:"archive_enabled"`
	RunsTotal        int            `json:"runs_total"`
	RunsActive       int            `json:"runs_active"`
	RunsByStatus     map[string]int `json:"runs_by_status"`
	ChannelsTotal    int            `json:"channels_total"`
	MessagesTotal    int            `json:"messages_total"`
	MessagesBySource map[string]int `json:"messages_by_source"`
}

type ResolvedProviderOverride

type ResolvedProviderOverride struct {
	Alias string `json:"alias,omitempty"`
	Kind  string `json:"kind,omitempty"`
	Model string `json:"model,omitempty"`
	Tier  string `json:"tier,omitempty"`
}

type Run

type Run struct {
	ID                  string                   `json:"run_id"`
	WorkspaceID         string                   `json:"-"`
	SessionID           string                   `json:"session_id,omitempty"`
	SessionKind         string                   `json:"session_kind,omitempty"`
	Agent               string                   `json:"agent,omitempty"`
	Prompt              string                   `json:"prompt,omitempty"`
	ParentRunID         string                   `json:"parent_run_id,omitempty"`
	RootRunID           string                   `json:"root_run_id,omitempty"`
	ParentSessionID     string                   `json:"parent_session_id,omitempty"`
	Depth               int                      `json:"depth,omitempty"`
	Status              RunStatus                `json:"status"`
	Accepted            bool                     `json:"accepted"`
	Response            string                   `json:"response,omitempty"`
	Error               string                   `json:"error,omitempty"`
	DiagnosticCode      string                   `json:"diagnostic_code,omitempty"`
	DiagnosticReason    string                   `json:"diagnostic_reason,omitempty"`
	PolicyBlockedTool   string                   `json:"policy_blocked_tool,omitempty"`
	PolicyBlockedRule   string                   `json:"policy_blocked_rule,omitempty"`
	PolicyBlockedGroup  string                   `json:"policy_blocked_group,omitempty"`
	PolicyBlockedSource string                   `json:"policy_blocked_source,omitempty"`
	PolicyAllowedTools  []string                 `json:"policy_allowed_tools,omitempty"`
	PolicyDeniedTools   []string                 `json:"policy_denied_tools,omitempty"`
	PolicyRiskMax       string                   `json:"policy_risk_max,omitempty"`
	FlowID              string                   `json:"flow_id,omitempty"`
	StepID              string                   `json:"step_id,omitempty"`
	Tier                string                   `json:"tier,omitempty"`
	ConsensusMode       string                   `json:"consensus_mode,omitempty"`
	ConsensusVariants   []ConsensusVariantRecord `json:"consensus_variants,omitempty"`
	ConsensusCostUSD    float64                  `json:"consensus_cost_usd,omitempty"`
	ConsensusBudgetUSD  float64                  `json:"consensus_budget_usd,omitempty"`
	ProviderOverride    *ProviderOverride        `json:"provider_override,omitempty"`
	ResolvedAlias       string                   `json:"resolved_alias,omitempty"`
	ResolvedKind        string                   `json:"resolved_kind,omitempty"`
	ResolvedModel       string                   `json:"resolved_model,omitempty"`
	OverrideSource      string                   `json:"override_source,omitempty"`
	CreatedAt           string                   `json:"created_at"`
	StartedAt           string                   `json:"started_at,omitempty"`
	CompletedAt         string                   `json:"completed_at,omitempty"`
	UpdatedAt           string                   `json:"updated_at"`
}

type RunEvent

type RunEvent struct {
	Type            string  `json:"type"`
	RunID           string  `json:"run_id"`
	Timestamp       string  `json:"timestamp,omitempty"`
	Agent           string  `json:"agent,omitempty"`
	Status          string  `json:"status,omitempty"`
	Tier            string  `json:"tier,omitempty"`
	ResolvedAlias   string  `json:"resolved_alias,omitempty"`
	ResolvedKind    string  `json:"resolved_kind,omitempty"`
	ResolvedModel   string  `json:"resolved_model,omitempty"`
	Error           string  `json:"error,omitempty"`
	Message         string  `json:"message,omitempty"`
	Response        string  `json:"response,omitempty"`
	VariantCount    int     `json:"variant_count,omitempty"`
	VariantIdx      int     `json:"variant_idx,omitempty"`
	Alias           string  `json:"alias,omitempty"`
	Kind            string  `json:"kind,omitempty"`
	Model           string  `json:"model,omitempty"`
	Strategy        string  `json:"strategy,omitempty"`
	TokenBudget     int     `json:"token_budget,omitempty"`
	TokensIn        int     `json:"tokens_in,omitempty"`
	TokensOut       int     `json:"tokens_out,omitempty"`
	FinalTokens     int     `json:"final_tokens,omitempty"`
	CostUSDEstimate float64 `json:"cost_usd_estimate,omitempty"`
	CostUSDActual   float64 `json:"cost_usd_actual,omitempty"`
}

type RunStatus

type RunStatus string
const (
	RunStatusAccepted  RunStatus = "accepted"
	RunStatusRunning   RunStatus = "running"
	RunStatusCompleted RunStatus = "completed"
	RunStatusFailed    RunStatus = "failed"
	RunStatusCanceled  RunStatus = "canceled"
)

type Runtime

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

func NewRuntime

func NewRuntime(opts RuntimeOptions) *Runtime

func (*Runtime) Agents

func (r *Runtime) Agents() []map[string]any

func (*Runtime) Cancel

func (r *Runtime) Cancel(runID string) (Run, error)

func (*Runtime) CancelByWorkspace

func (r *Runtime) CancelByWorkspace(workspaceID, runID string) (Run, error)

func (*Runtime) Close

func (r *Runtime) Close(ctx context.Context) error

func (*Runtime) Enabled

func (r *Runtime) Enabled() bool

func (*Runtime) Get

func (r *Runtime) Get(runID string) (Run, bool)

func (*Runtime) GetByWorkspace

func (r *Runtime) GetByWorkspace(workspaceID, runID string) (Run, bool)

func (*Runtime) GetOrZero

func (r *Runtime) GetOrZero(runID string) Run

func (*Runtime) InboundTelegram

func (r *Runtime) InboundTelegram(botID, threadID, text string, payload map[string]any) (ChannelMessage, error)

func (*Runtime) InboundTelegramByWorkspace

func (r *Runtime) InboundTelegramByWorkspace(workspaceID, botID, threadID, text string, payload map[string]any) (ChannelMessage, error)

func (*Runtime) InboundWebhook

func (r *Runtime) InboundWebhook(channelID, threadID, text string, payload map[string]any) (ChannelMessage, error)

func (*Runtime) InboundWebhookByWorkspace

func (r *Runtime) InboundWebhookByWorkspace(workspaceID, channelID, threadID, text string, payload map[string]any) (ChannelMessage, error)

func (*Runtime) List

func (r *Runtime) List(limit int) []Run

func (*Runtime) ListByWorkspace

func (r *Runtime) ListByWorkspace(workspaceID string, limit int) []Run

func (*Runtime) LookupAgent

func (r *Runtime) LookupAgent(name string) (AgentInfo, bool)

func (*Runtime) MessageRead

func (r *Runtime) MessageRead(channelID string, limit int) ([]ChannelMessage, error)

func (*Runtime) MessageReadByWorkspace

func (r *Runtime) MessageReadByWorkspace(workspaceID, channelID string, limit int) ([]ChannelMessage, error)

func (*Runtime) MessageSend

func (r *Runtime) MessageSend(channelID, threadID, text string) (ChannelMessage, error)

func (*Runtime) MessageSendByWorkspace

func (r *Runtime) MessageSendByWorkspace(workspaceID, channelID, threadID, text string) (ChannelMessage, error)

func (*Runtime) OutboundTelegram

func (r *Runtime) OutboundTelegram(botID, chatID, threadID, text string, payload map[string]any) (ChannelMessage, error)

func (*Runtime) OutboundTelegramByWorkspace

func (r *Runtime) OutboundTelegramByWorkspace(workspaceID, botID, chatID, threadID, text string, payload map[string]any) (ChannelMessage, error)

func (*Runtime) Reload

func (r *Runtime) Reload() AgentRuntimeStatus

func (*Runtime) ReportsChannels

func (r *Runtime) ReportsChannels(limit int) (ReportChannels, error)

func (*Runtime) ReportsChannelsByWorkspace

func (r *Runtime) ReportsChannelsByWorkspace(workspaceID string, limit int) (ReportChannels, error)

ReportsChannelsByWorkspace returns recent in-memory channel messages. See ReportsRunsByWorkspace for why AgentRuntimeArchiveEnabled also gates this endpoint despite reading from in-memory state (RF-057, ID-005).

func (*Runtime) ReportsRuns

func (r *Runtime) ReportsRuns(limit int) (ReportRuns, error)

func (*Runtime) ReportsRunsByWorkspace

func (r *Runtime) ReportsRunsByWorkspace(workspaceID string, limit int) (ReportRuns, error)

ReportsRunsByWorkspace returns recent in-memory run summaries.

Despite the name, the gating flag AgentRuntimeArchiveEnabled doubles as the "report endpoint visibility" switch — it controls both on-disk archive writes and whether this in-memory report endpoint serves data, even though the data itself is from r.runs (memory) and never touches the archive directory. Operators who want only the report endpoint without disk archives still have to enable archive_enabled. Splitting this into a dedicated AgentRuntimeReportEnabled flag is tracked in RF-057 as part of the broader config namespace migration (ID-005).

func (*Runtime) ReportsSummary

func (r *Runtime) ReportsSummary() (ReportSummary, error)

func (*Runtime) ReportsSummaryByWorkspace

func (r *Runtime) ReportsSummaryByWorkspace(workspaceID string) (ReportSummary, error)

func (*Runtime) Restart

func (r *Runtime) Restart() AgentRuntimeStatus

func (*Runtime) SetAgentsWatchEnabled

func (r *Runtime) SetAgentsWatchEnabled(enabled bool)

func (*Runtime) SetExecutors

func (r *Runtime) SetExecutors(executors []AgentExecutor, defaultAgent string)

func (*Runtime) Spawn

func (r *Runtime) Spawn(ctx context.Context, req SpawnRequest) (Run, error)

func (*Runtime) Status

func (r *Runtime) Status() AgentRuntimeStatus

func (*Runtime) SubagentLimits

func (r *Runtime) SubagentLimits() (maxThreads int, maxDepth int)

func (*Runtime) SubscribeRunEvents

func (r *Runtime) SubscribeRunEvents(runID string) (<-chan RunEvent, func())

func (*Runtime) ThreadReply

func (r *Runtime) ThreadReply(channelID, threadID, text string) (ChannelMessage, error)

func (*Runtime) ThreadReplyByWorkspace

func (r *Runtime) ThreadReplyByWorkspace(workspaceID, channelID, threadID, text string) (ChannelMessage, error)

func (*Runtime) Wait

func (r *Runtime) Wait(ctx context.Context, runID string) (Run, error)

type RuntimeOptions

type RuntimeOptions struct {
	Enabled                                   bool
	WorkspaceDir                              string
	SessionStore                              *session.Store
	SessionStoreForWorkspace                  func(workspaceID string) *session.Store
	RunPrompt                                 func(ctx context.Context, runLabel string, prompt string) (string, error)
	Executors                                 []AgentExecutor
	DefaultAgent                              string
	AgentRuntimeAgentsWatchEnabled            bool
	ChannelsLocalEnabled                      bool
	ChannelsWebhookEnabled                    bool
	ChannelsTelegramEnabled                   bool
	AgentRuntimePersistenceEnabled            bool
	AgentRuntimeRunsPersistenceEnabled        bool
	AgentRuntimeChannelsPersistenceEnabled    bool
	AgentRuntimeRunsMaxRecords                int
	AgentRuntimeChannelsMaxMessagesPerChannel int
	AgentRuntimeSubagentsMaxThreads           int
	AgentRuntimeSubagentsMaxDepth             int
	AgentRuntimeConsensusEnabled              bool
	AgentRuntimeConsensusMaxFanout            int
	AgentRuntimeConsensusBudgetTokens         int
	AgentRuntimeConsensusBudgetUSD            float64
	AgentRuntimeConsensusTimeoutSeconds       int
	AgentRuntimeConsensusAllowedAliases       []string
	AgentRuntimeConsensusConcurrentRuns       int
	AgentRuntimePersistenceDir                string
	AgentRuntimeRestoreOnStartup              bool
	AgentRuntimeReportSummaryEnabled          bool
	AgentRuntimeArchiveEnabled                bool
	AgentRuntimeArchiveDir                    string
	AgentRuntimeArchiveRetentionDays          int
	AgentRuntimeArchiveMaxFileBytes           int
	ResolveProviderOverride                   func(tier string, override *ProviderOverride) (ResolvedProviderOverride, error)
	EstimateTokensCost                        func(provider, model string, inputTokens, outputTokens int) (float64, bool)
	UsageTracker                              *usage.Tracker
	Now                                       func() time.Time
}

type SpawnRequest

type SpawnRequest struct {
	WorkspaceID      string
	SessionID        string
	Title            string
	Prompt           string
	Agent            string
	ParentRunID      string
	RootRunID        string
	ParentSessionID  string
	Depth            int
	SessionKind      string
	SessionHidden    bool
	FlowID           string
	StepID           string
	Tier             string
	Mode             string
	Consensus        *ConsensusSpec
	ProviderOverride *ProviderOverride
}

Jump to

Keyboard shortcuts

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