examplehost

command
v0.18.0 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: Apache-2.0 Imports: 9 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

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.

Documentation

Overview

Command examplehost is a worked, runnable skeleton of the wiring a provider-API proxy does around the accountant and accountant/host libraries. It is about 140 lines and NOT a real proxy: it has no network, no real provider body and no host-specific rewriting. It shows the SHAPE of the four steps a host repeats for each request, so a new host can copy it instead of reading a real host's much larger code. The README beside this file names the real hosts that do this for real.

Run it from the host module:

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.

Jump to

Keyboard shortcuts

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