Dynamic Tool Recovery and Agentic Re-Planning Framework
Formulate dynamic tool self-correction, alternative path selection, and deterministic recovery plans for autonomous agent failures.
Utilize this template when agent tool executions are prone to transient API failures, unexpected parameter schemas, or edge-case runtime errors. It generates an actionable recovery and automated re-planning blueprint.
Role: Staff Agentic Reliability Engineer focused on resilient self-correcting agent runtimes and dynamic replanning workflows.
Context
- Execution pipeline: {{execution_pipeline_name}}
- Primary tool catalog: {{primary_toolset_inventory}}
- Alternative and fallback services: {{fallback_service_matrix}}
- Re-planning loop allowance: {{max_replanning_iterations}}
- Observability and trace backend: {{observability_telemetry_sink}}
- Human intervention criteria: {{human_approval_threshold}}
Task
Construct a resilient dynamic re-planning and tool recovery plan that enables {{execution_pipeline_name}} to self-diagnose execution errors, formulate alternative tool execution paths, and gracefully escalate unrecoverable states.
Method
- Analyze the primary tools in {{primary_toolset_inventory}} to identify fragile operations, common HTTP/database status codes, and deterministic error payloads.
- Map secondary APIs, decomposed query paths, and alternative tools in {{fallback_service_matrix}} for every primary tool failure mode.
- Design a structured error-reflection prompt protocol that forces the agent to classify failures (e.g., Schema Error, Rate Limit, Auth, Stale Entity, Missing Data).
- Formulate the dynamic re-planning loop detailing how the agent mutates arguments, splits tasks, or switches to alternate tools within {{max_replanning_iterations}}.
- Establish hard boundaries where dynamic replanning terminates immediately and triggers escalation based on {{human_approval_threshold}}.
- Detail state preservation rules to ensure partial task achievements are not lost or re-executed during re-planning turns.
- Construct logging schemas to emit recovery traces, failed attempts, argument mutations, and final resolution paths directly to {{observability_telemetry_sink}}.
Constraints
- MUST enforce a hard halt when re-planning attempts reach {{max_replanning_iterations}}.
- MUST NOT attempt automated retries on non-idempotent operations without verifying state idempotency keys.
- Re-planning logic MUST require the agent to generate an explicit rationale before switching from primary to fallback tools.
- Keep tool retry latency overhead bounded to prevent pipeline timeouts.
Output format
1. Tool Error Taxonomy & Classification Engine
(Table mapping Failure Category, Typical Code, Root Cause, and Agent Reflex Action)
2. Primary-to-Fallback Tool Substitution Matrix
(Mapping each tool in {{primary_toolset_inventory}} to its fallback in {{fallback_service_matrix}})
3. Reflection & Re-Planning Step Logic
(Sequential execution algorithm for reflection, argument mutation, and alternate tool invocation)
4. Circuit Breakers & Escalation Protocol
(Explicit triggers matching {{human_approval_threshold}} that pause execution for human review)
5. Telemetry & Failure Trace Specification
(JSON payload schema for events dispatched to {{observability_telemetry_sink}})
Self-review
- Verify every entry in {{primary_toolset_inventory}} has an actionable fallback in {{fallback_service_matrix}} or an explicit terminal failure rule.
- Confirm that re-planning cycles cannot exceed {{max_replanning_iterations}} under any condition.
- Validate that human escalation paths in {{human_approval_threshold}} completely halt automated execution loops.
Explicit role, a named task, and discrete steps the model can follow.
Background, inputs and variables the model needs before it starts.
Hard boundaries — what the model must and must not do.
A named, field-level shape for the response.
Ordered work items that force analysis before an answer.
Length and structure that travel across frontier models.
Signal density — instruction weight without padding.
Documented variables so the scaffold adapts to new inputs.
Quality bar, assumptions and behaviour when inputs are thin.
How much real usage the template has behind it.