Threads AI

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.

FileCommand
TypeScripttypescript/examples/evals.tscd typescript && bun examples/evals.ts
Pythonpython/examples/evals.pycd python && uv run python examples/evals.py

Both print:

1 passed, 0 failed

It 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.

FileCommand
TypeScripttypescript/packages/otel/examples/telemetry.tscd typescript/packages/otel && OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4318 bun examples/telemetry.ts
Pythonpython/examples/telemetry.pycd 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.

Complete programs in the guides

These pages carry a whole program rather than a fragment, with the output it prints.

Edit on GitHub

On this page