#11274: fix(tools): truncate overly long tool names for API compatibility
agents
stale
Cluster:
Tool Execution and Error Handling
## Summary
- Truncate tool names to stay within provider/API limits and avoid runtime failures.
- Keep tool-name handling behavior consistent across policy/adapter paths.
- AI-Assisted: Yes (built with Claude/OpenCode)
## Testing
- Verified branch diff against `upstream/main` is non-zero.
- Verified branch head SHA matches expected prepared commit.
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This change introduces `truncateToolNameForOpenAI()` in `src/agents/tool-policy.ts` and applies it in `src/agents/pi-tool-definition-adapter.ts` so tool/function names sent to the provider stay within a 64-character limit.
The main integration concern is that truncation changes the external identifier (`ToolDefinition.name`) while other parts of the tool-call flow (hooks, client delegation callback, and JSON result payloads) continue to reference the original/untruncated name. If any layer expects a single canonical identifier for dispatch/policy/telemetry, truncation can cause tool calls to fail or be mis-attributed when names exceed the limit.
<h3>Confidence Score: 3/5</h3>
- This PR is directionally correct but may break tool-call name consistency when truncation occurs.
- Truncating the provider-facing tool name addresses API limits, but the implementation currently introduces two tool identifiers in the same execution path (truncated vs original). If downstream dispatch/policy or client delegation relies on exact name matching, tool calls with long names can fail or be inconsistently handled. Otherwise, changes are small and localized.
- src/agents/pi-tool-definition-adapter.ts
<!-- greptile_other_comments_section -->
<sub>(3/5) Reply to the agent's comments like "Can you suggest a fix for this @greptileai?" or ask follow-up questions!</sub>
<!-- /greptile_comment -->
Most Similar PRs
#23803: Fix tool metadata truncation
by kamal-ayman · 2026-02-22
79.5%
#11453: fix: apply normalizeToolName() at all tool lookup points
by sypsyp97 · 2026-02-07
79.4%
#19094: Fix empty tool_call_id and function names in provider transcript pa...
by yxshee · 2026-02-17
79.3%
#9861: fix(agents): re-run tool_use/tool_result repair after limitHistoryT...
by CyberSinister · 2026-02-05
78.0%
#8888: fix: increase tool result/error context limits
by joetomasone · 2026-02-04
77.9%
#12608: fix: sanitize client tool call IDs per provider requirements
by piyushhhxyz · 2026-02-09
77.5%
#21166: fix(agents): sanitize tool names in session transcript repair (#8595)
by dinakars777 · 2026-02-19
77.1%
#12812: fix(transcript-policy): sanitize tool call IDs for all non-OpenAI p...
by justin-nevins · 2026-02-09
76.6%
#8117: Agents: sanitize tool call ids for OpenAI
by TylonHH · 2026-02-03
76.3%
#13976: fix(anthropic): include Anthropic in tool call ID sanitization
by omair445 · 2026-02-11
76.0%