Orphaned tool call sanitizer

From ychampion/cskill-agents · View interactive version

Orphaned tool call sanitizer is an AI agent skill from the GitHub repository ychampion/cskill-agents. Remove assistant messages that reference tools without recorded results before feeding the history back into runAgent.

How to use this skill

Skill file

SKILL: Orphaned Tool Call Sanitizer

Domain: messaging

Trigger: When replaying history for a subagent, make sure assistant tool_use blocks never refer to tool_use_ids that lack results.

Source Pattern: Distilled from reviewed subagent orchestration, isolation, and lifecycle implementations.

Core Method

Collect every tool_use_id emitted inside tool_result blocks on user messages, then drop any assistant message whose content includes a tool_use block that references an ID missing from that set. Non-assistant messages and assistant messages without tool_use blocks pass through unchanged, so only the incomplete invocations are pruned before query runs.

Key Rules

Example Application

When the main agent forks to an Explore or Plan subagent, sanitize the shared history first so the subagent never inherits an assistant tool_use record that was never followed by a tool_result. The downstream query call then succeeds without rejecting the payload.

Anti-Patterns (What NOT to do)

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.