examplehost
A worked, runnable skeleton of the wiring a provider-API proxy does around the accountant and
accountant/host libraries. Copy it as a starting point for a new host.
What it is
- About 140 lines, one command, in
main.go.
- NOT a real proxy: no network, no real provider body, no host-specific rewriting.
- Shows the SHAPE of the four steps a host repeats for each request:
Begin, the host's own rewrite,
End, and Price.
Run it
cd host && go run ./examplehost
It prices two turns of one thread. Turn 1 writes a prompt prefix to the provider cache. Turn 2 reads
that prefix, and the host shrinks one message before it forwards it. The program prints the saving
the accountant books for the shrink:
operator=shrink changeID=shrink:turn2:msg2
saved tokens: {Input:0 CacheWrite5m:6721 CacheWrite1h:0 CacheRead:0}
checks failed: 0
The real thing
The example simplifies what the real hosts do. context-guru and Cortex each run this wiring for
real, over real provider bodies, with their own rewriting components, metrics and event output. For
the full prose description of the lifecycle, read docs/cortex-wiring.md, sections W6.1 through W6.7.
What the example leaves out on purpose
- Keep-alive pings and the tier store (the
Recorder holds them; this example does not exercise
them). End does run the sibling store on every call (facts.SharedWarm); the example just does
not show that effect in its two-turn run.
wire.EnvelopeOps, the real tools/system/TTL diff. The example reports one hand-built
accountant.Operation instead.
- Turning saved tokens into money: a host does that with
accountant.Figure and its own rate table.
- Any real provider wire format, streamed usage merge (
usage.Merger), or thinking-block counts.
accountant.Withhold: W6.5 books a figure only once it returns empty. The example prints
Result.Ops[0].Saved straight from Price, with no such gate, to keep the demo to one path; a
real host must add it before it trusts a figure.