Examples: basics¶
Tools, the registry, schemas, the executor, models and guides. Back to the Examples gallery. Files here: 48.
| File | Shows | Install | Run | Docs |
|---|---|---|---|---|
examples/anthropic_results.py |
Answer Anthropic tool_use blocks with tool_result blocks. | pip install agent-adapter |
python examples/anthropic_results.py |
Anthropic |
examples/attach_any.py |
attach(): one call gives any framework its native tools; approval stays on the executor. | pip install agent-adapter |
python examples/attach_any.py |
Attach anywhere |
examples/chat_any_agent.py |
Chat with any agent: a plain async function that runs a small flow and streams its answer. | pip install agent-adapter |
python examples/chat_any_agent.py |
Chat with your agent |
examples/chat_builtin.py |
Chat with the built-in tool loop: a scripted model, a weather tool and a booking to approve. | pip install agent-adapter |
python examples/chat_builtin.py |
Chat with your agent |
examples/chat_flows.py |
A city visitor help desk to chat with: five scripted flows, one per agent pattern. | pip install agent-adapter |
python examples/chat_flows.py |
Chat flows by example |
examples/chat_memory.py |
Chat memory across chats: a ticket desk that remembers what a user told it last time. | pip install agent-adapter |
python examples/chat_memory.py |
Remember users across chats |
examples/chat_minimal.py |
The smallest chat agent: one async function served in the local chat page. | pip install agent-adapter |
python examples/chat_minimal.py |
Chat with your agent |
examples/chat_wrappers.py |
Chat wrappers: LangGraph, ADK, CrewAI or your own HTTP backend as a chat agent. | pip install "agent-adapter[gemini]" |
import only | Wrap a framework for chat |
examples/context.py |
ToolContext in a tool: ids, custom events, child contexts; errors as ErrorInfo. | pip install agent-adapter |
python examples/context.py |
Context, events and ports |
examples/discover_integrations.py |
Find integrations through entry points and export a registry with one. | pip install agent-adapter |
python examples/discover_integrations.py |
Writing an integration |
examples/errors.py |
Typed errors: catch them narrowly; send argument errors back to the model. | pip install agent-adapter |
python examples/errors.py |
Errors |
examples/executor.py |
Run tools through the Executor: one call, a batch, a plan, non-tool work, approval. | pip install agent-adapter |
python examples/executor.py |
Executor |
examples/guide_migrate_langchain.py |
Migration: from LangChain @tool functions to a registry, keeping LangChain as a caller. |
pip install "agent-adapter[langchain]" |
python examples/guide_migrate_langchain.py |
From LangChain tools |
examples/guide_migrate_raw.py |
Migration: from hand-written provider tool calling to a registry and the executor. | pip install agent-adapter |
python examples/guide_migrate_raw.py |
From raw OpenAI or Anthropic tool calling |
examples/guide_observability.py |
Observability guide: events, the ledger, OTel spans (when installed) and log hygiene. | pip install agent-adapter |
python examples/guide_observability.py |
Observability |
examples/guide_performance.py |
Performance guide: import cost, concurrency caps, cache hits and per-call overhead. | pip install agent-adapter |
python examples/guide_performance.py |
Performance |
examples/guide_security.py |
Security guide: what fails closed when a model, a replay or a bug tries its luck. | pip install agent-adapter |
python examples/guide_security.py |
Security |
examples/guide_troubleshooting.py |
Troubleshooting: reproduce common failures and print the error each one gives. | pip install agent-adapter |
python examples/guide_troubleshooting.py |
Troubleshooting |
examples/guide_versioning.py |
Versioning guide: check that a name you use is public, and find where moved names live. | pip install agent-adapter |
python examples/guide_versioning.py |
Versioning and compatibility |
examples/hello.py |
Hello world: one function, one call, through the default executor. | pip install agent-adapter |
python examples/hello.py |
Quickstart |
examples/hooks.py |
Built-in hooks: redact logs, cap spend, block payloads, pace calls; plus a custom hook. | pip install agent-adapter |
python examples/hooks.py |
Hooks |
examples/howto_attach.py |
Attach one tool to plain code, a sync caller and two model APIs, with the same safety. | pip install agent-adapter |
python examples/howto_attach.py |
Attach anywhere |
examples/howto_byom.py |
Bring your own model: wrap any local or remote model function; the adapter adds the rest. | pip install agent-adapter |
python examples/howto_byom.py |
Bring your own model |
examples/howto_sync.py |
Call async tools from sync code: a WSGI view, a worker task, a script, a running loop. | pip install agent-adapter |
python examples/howto_sync.py |
Sync code and backends |
examples/howto_testing.py |
Test tools offline: the plain function, its schema, the executor with fakes, a fake LLM. | pip install agent-adapter pytest |
python examples/howto_testing.py |
Testing tools |
examples/howto_wrap_legacy.py |
Expose a legacy sync service class as tools: read methods, a guarded write, clean errors. | pip install agent-adapter |
python examples/howto_wrap_legacy.py |
Wrap a legacy class |
examples/imported_tools.py |
Tools from a raw JSON schema, a hand-written argument model, and per-target export. | pip install agent-adapter |
python examples/imported_tools.py |
Tools |
examples/models.py |
Model ports: wrap a host LLM function, fall back on transient errors, normalise usage. | pip install agent-adapter |
python examples/models.py |
Model ports |
examples/models_bedrock.py |
Amazon Bedrock's Converse API (boto3) wrapped as a CallableModel, with usage and prices. | pip install agent-adapter; optional: pip install boto3 |
python examples/models_bedrock.py |
Model recipes: Bedrock, Azure OpenAI, Mistral, Groq, OpenRouter |
examples/models_common.py |
Shared by the model recipes: vendor SDK errors as typed model errors, and one priced demo run. | pip install agent-adapter |
import only | Model recipes: Bedrock, Azure OpenAI, Mistral, Groq, OpenRouter |
examples/models_mistral.py |
Mistral's own SDK (mistralai) wrapped as a CallableModel, with usage and prices. |
pip install agent-adapter; optional: pip install mistralai |
python examples/models_mistral.py |
Model recipes: Bedrock, Azure OpenAI, Mistral, Groq, OpenRouter |
examples/models_openai_compatible.py |
Azure OpenAI, Groq and OpenRouter: each vendor's own SDK wrapped as a CallableModel. | pip install agent-adapter; optional: pip install "agent-adapter[openai]" groq |
python examples/models_openai_compatible.py |
Model recipes: Bedrock, Azure OpenAI, Mistral, Groq, OpenRouter |
examples/models_streaming.py |
Streaming: tool-call arguments and structured output as they arrive, through the tool loop. | pip install agent-adapter |
python examples/models_streaming.py |
Streaming |
examples/providers.py |
One tool, three providers: render it for each and run the model's tool calls. | pip install agent-adapter |
python examples/providers.py |
OpenAI |
examples/quickstart.py |
Quickstart: define tools once, render them for two providers, run them with the executor. | pip install agent-adapter |
python examples/quickstart.py |
Quickstart |
examples/registry_views.py |
Filter a registry per agent and render a prompt catalogue from it. | pip install agent-adapter |
python examples/registry_views.py |
Tools |
examples/runtime.py |
Call async tools from sync code with run_sync; keep one client per event loop. | pip install agent-adapter |
python examples/runtime.py |
Runtime |
examples/sandbox_code_tool.py |
Sandboxed code: a shop assistant model writes Python, a person approves it, a sandbox runs it. | pip install agent-adapter |
python examples/sandbox_code_tool.py |
Sandboxed code |
examples/sandbox_docker.py |
Docker sandbox: model-written code in a locked-down container, when Docker is available. | pip install agent-adapter |
python examples/sandbox_docker.py |
Sandboxed code |
examples/sandbox_hosted.py |
Hosted sandboxes: E2B and Modal as a CallableSandbox, each a short recipe. |
pip install agent-adapter |
python examples/sandbox_hosted.py |
Sandboxed code |
examples/strict_mode.py |
OpenAI strict mode: every field required, and null means "use the default". | pip install agent-adapter |
python examples/strict_mode.py |
Strict mode and nulls |
examples/template_script.py |
Starter script: one tool, one executor, a sync call. Scaffolded by agent-adapter init. |
pip install agent-adapter |
python examples/template_script.py |
CLI |
examples/tool_loop.py |
Tool loop: an instrumented model calls registry tools; the ledger and cache track it all. | pip install agent-adapter |
python examples/tool_loop.py |
Instrumented models and the tool loop |
examples/traces_otlp.py |
Send the adapter's OpenTelemetry spans to Langfuse, Arize Phoenix or OpenLLMetry over OTLP. | pip install "agent-adapter[otel]" opentelemetry-sdk; optional: pip install opentelemetry-exporter-otlp-proto-http traceloop-sdk |
python examples/traces_otlp.py |
Send traces to Langfuse, Phoenix or OpenLLMetry |
examples/tracing.py |
Send trace events to several sinks; export them as OpenTelemetry spans when installed. | pip install agent-adapter; optional: pip install "agent-adapter[otel]" opentelemetry-sdk |
python examples/tracing.py |
Tracing: event sinks and OpenTelemetry |
examples/viewer_search_import.py |
Viewer: import an OTLP JSON trace file from another app as a run you can browse and search. | pip install agent-adapter |
python examples/viewer_search_import.py |
Search and tag runs |
examples/viewer_setups.py |
Turn on run recording in each kind of app: every set-up is one record(...) line. |
pip install agent-adapter |
python examples/viewer_setups.py |
See your runs |
examples/wrap_existing.py |
Expose existing code as tools without editing it. | pip install agent-adapter |
python examples/wrap_existing.py |
Wrap existing code |