Help us shape the future of Go! Take the 2026 Go Developer Survey

agentrunner

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultTaskNamespace       = "default"
	DefaultBaseBranch          = "main"
	DefaultMaxIterations       = 5
	DefaultTokenFile           = "/etc/diverge/token/token"
	DefaultMCPURL              = "http://diverge-server.diverge-system.svc:8080/mcp"
	DefaultMeterURL            = "http://diverge-server.diverge-system.svc:8080/api/v1/agenttask/meter"
	DefaultPreviewHeaderKey    = "x-diverge-env"
	DefaultWorkspaceDir        = "/workspace"
	DefaultModel               = "claude-3-7-sonnet"
	DefaultTokensPerIteration  = int64(2500)
	DefaultCostPerIterationUSD = 0.05
)

Variables

View Source
var (
	// ErrBudgetExceeded is returned when the LLM metering endpoint reports that the task has exceeded its token or USD budget.
	ErrBudgetExceeded = errors.New("agent task budget exceeded")
	// ErrModelDisallowed is returned when the LLM metering endpoint rejects the requested model under the Macaroon token caveats.
	ErrModelDisallowed = errors.New("agent task model disallowed")
	// ErrMaxIterationsReached is returned when the agent loop exhausts MaxIterations without passing verification.
	ErrMaxIterationsReached = errors.New("max iterations reached without passing verification")
)

Functions

This section is empty.

Types

type CommandExecutor

type CommandExecutor interface {
	Run(ctx context.Context, dir string, env []string, name string, args ...string) (string, error)
}

CommandExecutor abstracts external command execution for testability.

type Config

type Config struct {
	TaskName            string
	TaskNamespace       string
	Objective           string
	RepoURL             string
	BaseBranch          string
	WorkingBranch       string
	BudgetUSD           string
	MaxIterations       int
	TokenFile           string
	MCPURL              string
	MeterURL            string
	PreviewURL          string
	PreviewHeaderKey    string
	PreviewHeaderValue  string
	WorkspaceDir        string
	AgentCommand        string
	VerifyCommand       string
	Model               string
	TokensPerIteration  int64
	CostPerIterationUSD float64
}

Config holds the runtime configuration for the autonomous agent runner.

func LoadConfigFromEnv

func LoadConfigFromEnv(getenv func(string) string) (*Config, error)

LoadConfigFromEnv parses and validates the agent runner configuration from environment variables.

type MeterRequest

type MeterRequest struct {
	Model      string  `json:"model"`
	TokensUsed int64   `json:"tokensUsed"`
	CostUSD    float64 `json:"costUSD"`
}

MeterRequest matches internal/server.LLMMeterRequest JSON schema for POST /api/v1/agenttask/meter.

type MeterResponse

type MeterResponse struct {
	Allowed         bool    `json:"allowed"`
	Suspended       bool    `json:"suspended"`
	Reason          string  `json:"reason,omitempty"`
	TotalTokensUsed int64   `json:"totalTokensUsed"`
	TotalCostUSD    float64 `json:"totalCostUSD"`
}

MeterResponse matches internal/server.LLMMeterResponse JSON schema returned by POST /api/v1/agenttask/meter.

type OSCommandExecutor

type OSCommandExecutor struct{}

OSCommandExecutor runs commands on the host OS via os/exec.

func (OSCommandExecutor) Run

func (e OSCommandExecutor) Run(ctx context.Context, dir string, env []string, name string, args ...string) (string, error)

Run executes a command with context, working directory, and additional environment variables.

type RunResult

type RunResult struct {
	Succeeded       bool
	Iterations      int
	Committed       bool
	WorkingBranch   string
	TotalTokensUsed int64
	TotalCostUSD    float64
}

RunResult summarizes the outcome of an autonomous agent runner execution.

type Runner

type Runner struct {
	Config     *Config
	Exec       CommandExecutor
	HTTPClient *http.Client
	Logger     io.Writer
}

Runner orchestrates the autonomous agent loop inside a Diverge sandbox pod.

func NewRunner

func NewRunner(cfg *Config) *Runner

NewRunner constructs a Runner with default OSCommandExecutor and HTTPClient.

func (*Runner) CheckPreviewHealth

func (r *Runner) CheckPreviewHealth(ctx context.Context) error

CheckPreviewHealth probes the ephemeral preview URL (if configured) with the Diverge isolation header.

func (*Runner) ReportUsage

func (r *Runner) ReportUsage(ctx context.Context, token, model string, tokensUsed int64, costUSD float64) (*MeterResponse, error)

ReportUsage reports token and cost consumption for an iteration to the Diverge metering endpoint.

func (*Runner) ResolveToken

func (r *Runner) ResolveToken() (string, error)

ResolveToken loads the Macaroon capability token from DIVERGE_MACAROON_TOKEN or Config.TokenFile.

func (*Runner) Run

func (r *Runner) Run(ctx context.Context) (*RunResult, error)

Run executes the end-to-end autonomous agent workflow: token resolution, repo clone, iterative metered execution + verification, and git commit/push upon passing verification.

Jump to

Keyboard shortcuts

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