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.

Tool failsClassifyFix argsRetryStore precedentconnector_failuretimeout, networkauth_failure401, bad credentialsdata_failure422, validationrate_limit_failure429, throttled

7 recovery strategies: retry, sub_mission, human_handoff, skip, reconfigure, coerce, regenerate

2

Failure classification

Cadreen classifies failures using LLM inference, not string matching. The classification determines the recovery strategy.

connector_failure
Try alternative pathwayTimeout → try different connector
auth_failure
Skip same-credential pathways401 → don't retry with same key
permission_failure
Find broader scope403 → try path with more permissions
capability_failure
Try different path404 → try alternative connector
rate_limit_failure
Wait and retry429 → exponential backoff
data_failure
Fix 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 atom. 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.