ContextProvider. The base class handles tool wrapping, name derivation, and error shaping.
Minimal Example
query_faq tool. Same shape as every built-in provider.
Required Methods
You must implement these four abstract methods:| Method | Purpose |
|---|---|
query(question, *, run_context=None) -> Answer | Sync read |
aquery(question, *, run_context=None) -> Answer | Async read |
status() -> Status | Sync health check |
astatus() -> Status | Async health check |
Answer
Answer is what query() returns:
Status
Status reports provider health:
Optional Methods
Override these to customize behavior:| Method | Default | Override when |
|---|---|---|
update() / aupdate() | Raises NotImplementedError | Provider supports writes |
asetup() | No-op | Need async init (MCP sessions, cache priming) |
aclose() | No-op | Hold long-lived state (watches, connections) |
instructions() | Generic guidance | Want source-specific usage hints |
Adding Write Support
Overrideupdate(), aupdate(), and _default_tools() for writable providers:
query_notes and update_notes tools.
Async Lifecycle
For providers that need setup and teardown:Custom Instructions
Overrideinstructions() to provide source-specific guidance:
Using RunContext
Therun_context parameter carries caller state. Use it for per-user behavior:
run_context:
user_id— identifies the callersession_id— identifies the conversationmetadata— arbitrary dict passed through the call chaindependencies— values injected via agent’sdependenciesparameter
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