Back to Guides & Cookbooks
Cookbook
Building self-healing tool chains with precedent memory
When a tool call fails, Cadreen classifies the failure, fixes the arguments, and retries. After a few successes, it stores the fix as a precedent for future failures.
1
How self-healing works
Cadreen classifies failures into categories and applies the right recovery strategy. This happens automatically — you don't need to implement retry logic.
Self-healing pipeline
Click a step for details
2
Failure classification
Cadreen classifies failures using LLM inference, not string matching. The classification determines the recovery strategy.
connector_failureTry alternative approachTimeout → try different connector
auth_failureSkip same-credential methods401 → don't retry with same key
permission_failureFind broader scope403 → try path with more permissions
capability_failureTry different path404 → try alternative connector
rate_limit_failureWait and retry429 → exponential backoff
data_failureFix the input422 → model fixes arguments
3
See it in action
A self-healing conversation
> Create an invoice for $500 for Acme Corp
Let me create that invoice for you.
[Calling create_invoice... Error: invalid address format]
I noticed the address format needs adjustment. Let me fix that.
[Calling create_invoice... Success]
Invoice created: inv_abc123 for $500.
Acme Corp will receive it shortly.The user sees the final result. The self-healing happened transparently. The intelligence trace records both the failure and the recovery.
4
Precedent memory
After 3 similar successful recoveries, Cadreen stores the fix as a precedent. Future failures of the same type use the stored solution — faster and more reliable.
Query healing precedents
const precedents = await cadreen.healing.precedents();
console.log(precedents);
// [
// {
// failure_type: "data_failure",
// tool: "create_invoice",
// fix: "normalize address format",
// success_count: 12,
// last_used: "2026-06-21T10:00:00Z"
// }
// ]Note
Precedents are stored as knowledge items in the semantic memory. They persist across sessions and are shared across all surfaces.
Note
Next: How to turn any REST API into a governed AI tool — upload an OpenAPI spec, get governed tools.