From 787b7fb1aed92c2b701724a7741576053b93cccb Mon Sep 17 00:00:00 2001 From: Claude Sonnet 5 Date: Fri, 3 Jul 2026 23:01:50 +0000 Subject: feat(role): add versioned role configs + escalation ladder + scheduler (Phase 5) Two parts: Part A (fixes a gap from Phase 1): Groq/OpenRouter/OpenAI were documented in docs/api-keys-setup.md as usable once configured, but nothing actually constructed runners for them. internal/cli/cloudrunners.go consolidates anthropic/google/groq/openrouter/openai NativeRunner construction into one table-driven registerCloudRunners() helper, replacing the two hand-written per-provider blocks in serve.go/run.go. Groq/OpenRouter/OpenAI reuse openaicompat (no new adapter code) at SandboxKind: "docker". Part B: the token-husbanding harness's core routing mechanism. - internal/role: RoleConfig/Tier/Rung -- a role's system prompt and a multi-tier (provider, model) escalation ladder, versioned via config_json. - storage: new role_configs table (draft/active/retired, UNIQUE(role, version)) with transactional activate-retires-prior-active semantics; new executions.escalation_rung column. - task.AgentConfig.Role string -- purely additive; every existing task shape (Agent.Role == "") is unaffected, proven by TestPool_Execute_NonRoleTask_Unaffected plus the full pre-existing suite passing unchanged. - executor.Pool.execute(): role-typed tasks with no Agent.Type yet resolve tier 0 of their active ladder (round-robin across multi-candidate tiers, skipping rate-limited providers, falling back to soonest-clearing) before the existing pickAgent/Classifier path runs; SystemPrompt applies to Agent.SystemPromptAppend. Already-resolved role tasks (scheduler resubmits) get their escalation_rung re-derived read-only via findTierIndex. - internal/scheduler: polls role-typed FAILED tasks, retries at the same rung under MaxRetries or escalates to the next tier's first candidate when budget.Accountant.Allow() permits (emitting event.KindEscalated), else leaves the task FAILED with a final:true KindEscalated event. An in-memory per-execution-ID "handled" set keeps the poll loop convergent. Started by `serve` only, config knob [scheduler].poll_interval_seconds. - internal/api: POST/GET /api/roles/{role}/versions, POST /api/roles/{role}/activate -- unauthenticated, matching the existing projects/tasks REST endpoints' auth posture (only chatbot MCP, agent MCP, and WebSocket are api_token-gated in this codebase today). Documented as stored-but-not-yet-enforced (CLAUDE.md Design Debt, matching how task.Priority/RetryConfig are already documented): RoleConfig.Tools/ SandboxKind don't affect dispatch yet; DefaultBudgetUSD is read narrowly as the scheduler's escalation cost estimate, not enforced at initial dispatch; scheduler escalation always targets Candidates[0] (no round-robin, unlike initial-dispatch tier-0 resolution); the scheduler's dedupe is per-process and resets on restart (idempotent, harmless). go build/vet/test -race -count=1 all pass, 21 packages. Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_01V1moSNCJRcP6kykA4tyUSs --- internal/config/config.go | 43 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 37 insertions(+), 6 deletions(-) (limited to 'internal/config/config.go') diff --git a/internal/config/config.go b/internal/config/config.go index b9454d1..9e065b5 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -72,14 +72,26 @@ type RunnersConfig struct { // Anthropic vs. Claude above. Also requires [providers.google].api_key to // be set; Google = true with no configured key has no effect. Google *bool `toml:"google"` + // Groq, OpenRouter, and OpenAI gate NativeRunners registered under agent + // types "groq"/"openrouter"/"openai", all backed by + // internal/provider/openaicompat (they're OpenAI-wire-compatible, so no + // dedicated adapter package is needed — see docs/api-keys-setup.md). + // Each also requires the matching [providers.].api_key to be set; + // true with no configured key has no effect, same as Anthropic/Google. + Groq *bool `toml:"groq"` + OpenRouter *bool `toml:"openrouter"` + OpenAI *bool `toml:"openai"` } -func (r RunnersConfig) ClaudeEnabled() bool { return r.Claude == nil || *r.Claude } -func (r RunnersConfig) GeminiEnabled() bool { return r.Gemini == nil || *r.Gemini } -func (r RunnersConfig) LocalEnabled() bool { return r.Local == nil || *r.Local } -func (r RunnersConfig) ContainerEnabled() bool { return r.Container == nil || *r.Container } -func (r RunnersConfig) AnthropicEnabled() bool { return r.Anthropic == nil || *r.Anthropic } -func (r RunnersConfig) GoogleEnabled() bool { return r.Google == nil || *r.Google } +func (r RunnersConfig) ClaudeEnabled() bool { return r.Claude == nil || *r.Claude } +func (r RunnersConfig) GeminiEnabled() bool { return r.Gemini == nil || *r.Gemini } +func (r RunnersConfig) LocalEnabled() bool { return r.Local == nil || *r.Local } +func (r RunnersConfig) ContainerEnabled() bool { return r.Container == nil || *r.Container } +func (r RunnersConfig) AnthropicEnabled() bool { return r.Anthropic == nil || *r.Anthropic } +func (r RunnersConfig) GoogleEnabled() bool { return r.Google == nil || *r.Google } +func (r RunnersConfig) GroqEnabled() bool { return r.Groq == nil || *r.Groq } +func (r RunnersConfig) OpenRouterEnabled() bool { return r.OpenRouter == nil || *r.OpenRouter } +func (r RunnersConfig) OpenAIEnabled() bool { return r.OpenAI == nil || *r.OpenAI } // ProviderConfig configures a native (or OpenAI-compatible) LLM provider // backend for the multi-provider harness — see docs/api-keys-setup.md. Phase @@ -131,6 +143,10 @@ type Config struct { LocalModel LocalModel `toml:"local_model"` Runners RunnersConfig `toml:"runners"` Budget BudgetConfig `toml:"budget"` + // Scheduler configures internal/scheduler.Scheduler, the retry-then- + // escalate loop for role-typed tasks. Started only by `serve` (the + // one-shot `run` command has no background scheduler). + Scheduler SchedulerConfig `toml:"scheduler"` // Providers configures native/OpenAI-compatible LLM backends by name (see // ProviderConfig). Unused by runner construction in Phase 1. Providers map[string]ProviderConfig `toml:"providers"` @@ -145,6 +161,21 @@ type BudgetConfig struct { Provider5hUSD map[string]float64 `toml:"provider_5h_usd"` } +// SchedulerConfig configures internal/scheduler.Scheduler's poll loop. +type SchedulerConfig struct { + // PollIntervalSeconds is how often the scheduler checks for role-typed + // FAILED tasks to retry or escalate. Defaults to 30 when zero/unset. + PollIntervalSeconds int `toml:"poll_interval_seconds"` +} + +// PollInterval returns the configured poll interval, defaulting to 30s. +func (c SchedulerConfig) PollInterval() time.Duration { + if c.PollIntervalSeconds <= 0 { + return 30 * time.Second + } + return time.Duration(c.PollIntervalSeconds) * time.Second +} + func Default() (*Config, error) { home, err := os.UserHomeDir() if err != nil { -- cgit v1.2.3