P2: run.Executor — executus is runnable
The capstone of the run kernel: run.Executor.Run(ctx, RunnableAgent, inv)
ties model resolution + the tool registry + majordomo's agent loop +
context compaction + run-bounding + step/audit instrumentation into one
path, with every host concern behind the nil-safe run.Ports.
- run/executor.go: New(Config{Registry, Models, Defaults, Ports, Compactor,
ContextTokens, SystemHeader}) + Run -> Result{RunID, Output, Steps, Usage,
Err}. Budget gate (pre-run), model resolve, Audit StartRun/recorder
(satisfies RunTally, stamped on inv.RunState), toolbox build, step observer
(zips tool calls/results -> emitter + recorder.OnStep/OnTool), V10
detached-MaxRuntime context with caller-cancel merged back, compaction wired
from ContextTokens×ratio, audit Close + Budget Commit on a detached cleanup
ctx. Zero Ports = a bounded in-memory run (gadfly's case).
- run/executor_test.go: hermetic end-to-end run against majordomo's fake
provider (hello-world), Budget-rejection (no model call), Audit-port wiring
(StartRun + Close with terminal status/output). All green under -race.
- examples/minimal upgraded to the real "hello, agentic world" (~15 lines:
Configure tiers -> run.New -> Run -> print). README/CLAUDE.md updated.
Remaining P2 follow-ups (incremental): wire Critic/Checkpointer/PaletteSource/
Delivery into the loop, multi-phase Pipelines, and the no-tools direct path.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
+35
-13
@@ -1,27 +1,49 @@
|
||||
// Command minimal demonstrates executus's standalone core primitives available
|
||||
// today (P0): the config seam + bounded fan-out. The full zero-config "agentic
|
||||
// in ~12 lines" example arrives once the model, tool, and run packages land
|
||||
// (P1–P3).
|
||||
// Command minimal is executus's "hello, agentic world": wire a model resolver,
|
||||
// a tool registry, and the run executor, then run an agent. With no batteries
|
||||
// (Audit/Budget/Critic/Checkpointer/Palette/Delivery all nil) this is a
|
||||
// bounded, in-memory run — the light-host shape (gadfly's case).
|
||||
//
|
||||
// Run it with a provider key for the configured tier, e.g.
|
||||
//
|
||||
// ANTHROPIC_API_KEY=sk-... go run ./examples/minimal
|
||||
//
|
||||
// Override a tier from the environment without touching code, e.g.
|
||||
//
|
||||
// EXECUTUS_MODEL_TIER_FAST=openai/gpt-4o-mini ANTHROPIC_API_KEY= OPENAI_KEY=sk-... go run ./examples/minimal
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"gitea.stevedudenhoeffer.com/steve/executus/config"
|
||||
"gitea.stevedudenhoeffer.com/steve/executus/fanout"
|
||||
"gitea.stevedudenhoeffer.com/steve/executus/model"
|
||||
"gitea.stevedudenhoeffer.com/steve/executus/run"
|
||||
"gitea.stevedudenhoeffer.com/steve/executus/tool"
|
||||
)
|
||||
|
||||
func main() {
|
||||
cfg := config.Env("EXECUTUS_") // e.g. EXECUTUS_FANOUT_MAX_CONCURRENT=8
|
||||
max := cfg.Int("fanout.max_concurrent", 4)
|
||||
// 1. Configure model tiers: live values come from the environment
|
||||
// (EXECUTUS_MODEL_TIER_<NAME>), falling back to these defaults.
|
||||
model.Configure(config.Env("EXECUTUS_"), map[string]string{
|
||||
"fast": "anthropic/claude-haiku-4-5",
|
||||
"thinking": "anthropic/claude-opus-4-8",
|
||||
}, 0)
|
||||
|
||||
items := []string{"alpha", "beta", "gamma", "delta"}
|
||||
results := fanout.Run(context.Background(), items,
|
||||
fanout.Options[string]{MaxConcurrent: max},
|
||||
func(_ context.Context, s string) (int, error) { return len(s), nil })
|
||||
// 2. Build the executor: a tool registry + the model resolver. No batteries.
|
||||
ex := run.New(run.Config{
|
||||
Registry: tool.NewRegistry(),
|
||||
Models: model.ParseModelForContext,
|
||||
})
|
||||
|
||||
for _, r := range results {
|
||||
fmt.Printf("%-6s -> %d (err=%v)\n", items[r.Index], r.Value, r.Err)
|
||||
// 3. Run an agent and print its answer.
|
||||
res := ex.Run(context.Background(),
|
||||
run.RunnableAgent{Name: "assistant", SystemPrompt: "You are concise.", ModelTier: "fast"},
|
||||
tool.Invocation{RunID: "demo-1", CallerID: "local"},
|
||||
"In one sentence, what is an agent harness?")
|
||||
if res.Err != nil {
|
||||
log.Fatalf("run failed: %v", res.Err)
|
||||
}
|
||||
fmt.Println(res.Output)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user