Agent Wealth HubFree public resources
中文 EN العربية

Back to catalog / Agent recovery

Feed tool errors back to the agent for recovery

Inspect tool responses in a PostToolUse hook and add actionable error context for the next model turn.

Goal

Turn tool failures into structured feedback so the agent can correct course instead of claiming success.

Steps

  1. Register a PostToolUse matcher, read input_data["tool_response"], and detect an error state. [hooks]
  2. Return systemMessage, reason, and hookSpecificOutput.additionalContext with concise, non-sensitive recovery hints. [hooks]
  3. Test with one reproducibly failing tool and one successful tool; still inspect whether the final ResultMessage succeeded. [hooks]

How to verify

An error response adds context while a successful response does not; the application never treats a tool error as task completion.

Troubleshooting

If the model repeats failures, cap retries and define a stop condition; ensure detection does not flag normal output.

Permissions

Prerequisites

Permissions

Limitations

Bound context size and redact secrets from tool output; after hook feedback, run the checks that confirm the recovery.

Pinned upstream source

https://github.com/anthropics/claude-agent-sdk-python/blob/b6e9d12fe1cc98dde988ab7b7713c1feeee50c6c/examples/hooks.py

Repository
anthropics/claude-agent-sdk-python
File path
examples/hooks.py
Pinned commit
b6e9d12fe1cc98dde988ab7b7713c1feeee50c6c
Source checked
2026-10-14 · Reviewed against the pinned upstream source

Repository metrics

These values describe the upstream repository, not popularity or likes for an individual skill or playbook.

Stars
Not collected
Forks
Not collected
Observed at
Not collected

No metrics snapshot is available yet.

License: MIT

Main topic

Take a coding Agent change from context to verification

Related resources