Quick Start
1
Decorator with Availability Check
2
Class-Based Tool with Availability
How It Works
Implementation Methods
Function Decorator
BaseTool Protocol
Registry Functions
Availability Rules
Behavior Patterns
- No Check Method: Tool is always considered available
- Check Returns True: Tool included in LLM schema; last-success timestamp stamped
- Check Returns False: Tool hidden from LLM; cached
Falsefor 30 s - Check Throws Exception: Flaky — served last-good within the grace window, otherwise hidden (see below)
Exception Handling
A raised probe is treated as flaky, not final:- If the tool succeeded within the last 30 seconds, the last-good result is served and a
DEBUGline is logged. The failure is not cached, so the next probe can recover immediately. - Otherwise (no prior success, or the last success is older than 30 s), the tool is hidden, cached as unavailable for 30 s, and a
WARNINGis logged.
Plain Function Registry
Availability Caching
Availability checks are cached per-tool for 30 seconds so probes aren’t re-run on every schema build.
The TTL and grace window are internal defaults (both 30 s) on
ToolRegistry and are not user-tunable.
When cache entries are cleared:
registry.unregister(name)— evicts the tool’s cache and last-success timestamp.registry.register(new_tool, name=..., overwrite=True)— when the replacement is a different instance, prior availability state is evicted so a broken replacement can’t inherit the previous tool’s “healthy” status.registry.clear()— wipes everything.
Configuration Patterns
Environment-Based Availability
Service Discovery
Conditional Tool Loading
Best Practices
Keep Checks Fast
Keep Checks Fast
Availability checks run at schema-build time and must be fast (< 100ms recommended).Good: Environment variable checks, import tests, quick pings
Bad: Full API calls, heavy file operations, long network requests
Let the Registry Cache Your Probes
Let the Registry Cache Your Probes
The registry already caches every probe result for 30 s — see Availability Caching. Don’t wrap probes in
@lru_cache unless you need caching longer than 30 s.Fail Fast on Missing Dependencies
Fail Fast on Missing Dependencies
Check critical dependencies first, avoid unnecessary work.
Graceful Degradation
Graceful Degradation
Design tools to degrade gracefully when dependencies are partially available.
Related
Tools Overview
Core tool system and registration
Agent Configuration
Agent setup and tool integration

