Examples
The programs that ship in the repository, and the complete programs inside the guides.
Every program on this page is in the repository and runs as printed. Clone it first — Installation — then run each one from the directory named in its command.
In the repository
Two examples ship as files of their own, in both languages. Each one is run by the test suite, so they keep working as the framework changes.
Save a case, then check it the way CI does
A support agent answers a refund question, that one turn is saved as a case, and runEvals
(run_evals) replays it, reruns it against the agent as it is now, and reports drift. It needs no
API key and no network: a scripted model stands in for a real one.
| File | Command | |
|---|---|---|
| TypeScript | typescript/examples/evals.ts | cd typescript && bun examples/evals.ts |
| Python | python/examples/evals.py | cd python && uv run python examples/evals.py |
Both print:
1 passed, 0 failedIt is the shortest end-to-end tour of the eval loop: Saved cases for what
a case holds, Run evals for the report and the threads eval command.
Export a run's spans to an OTLP collector
A one-turn run, then otel(...).sync() ships the thread's log to whatever
OTEL_EXPORTER_OTLP_ENDPOINT points at, and prints how many spans it sent. This one needs a
collector listening; everything else is offline.
| File | Command | |
|---|---|---|
| TypeScript | typescript/packages/otel/examples/telemetry.ts | cd typescript/packages/otel && OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4318 bun examples/telemetry.ts |
| Python | python/examples/telemetry.py | cd python && OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4318 uv run python examples/telemetry.py |
The same file is printed on Observability, and a test asserts the page and the file match, so what you read there is what you run.
In the tutorials
The tutorial path is four programs that build on each other. They all run offline.
An agent and a run
The smallest program: instructions, a model, a store.
A tool, and an approval
A tool call, the log it leaves, and a run that parks for a person.
A subagent
A second agent in its own thread, reporting back as a tool result.
A team
Two members in parallel, and a lead that waits for both.
Complete programs in the guides
These pages carry a whole program rather than a fragment, with the output it prints.
A weather agent, offline then live
One tool, a scripted model, then the same agent on Anthropic.
A lead and a researcher
The Teams page's example, which both languages run as a test.
A host with channels
threads dev, and the webhook URL it prints for each channel.
The eval report
What threads eval prints, line by line.