Skip to main content
When the built-in providers don’t fit, subclass ContextProvider. The base class handles tool wrapping, name derivation, and error shaping.

Minimal Example

The agent now has a query_faq tool. Same shape as every built-in provider.

Required Methods

You must implement these four abstract methods:

Answer

Answer is what query() returns:

Status

Status reports provider health:

Optional Methods

Override these to customize behavior:

Adding Write Support

Override update(), aupdate(), and _default_tools() for writable providers:
Now the agent has both query_notes and update_notes tools.

Async Lifecycle

For providers that need setup and teardown:

Custom Instructions

Override instructions() to provide source-specific guidance:

Using RunContext

The run_context parameter carries caller state. Use it for per-user behavior:
Available on run_context:
  • user_id — identifies the caller
  • session_id — identifies the conversation
  • metadata — arbitrary dict passed through the call chain
  • dependencies — values injected via agent’s dependencies parameter

Wrapping External APIs

Pattern for wrapping a REST API:

Next

Provider Catalog

Browse all built-in providers for inspiration

Runtime Guide

See providers in production context