Skip to content

fix: bridge tool-calls in copilot-acp adapter - #5460

Merged
teknium1 merged 1 commit into
mainfrom
hermes/hermes-be07ee70
Apr 6, 2026
Merged

fix: bridge tool-calls in copilot-acp adapter#5460
teknium1 merged 1 commit into
mainfrom
hermes/hermes-be07ee70

Conversation

@teknium1

@teknium1 teknium1 commented Apr 6, 2026

Copy link
Copy Markdown
Contributor

Summary

Enables Hermes tool execution through the copilot-acp adapter. Previously, the adapter explicitly told the ACP backend "Do not emit OpenAI tool-call JSON" — the backend could only respond in prose, never actually calling tools.

Changes

  • Pass tool schemas and tool_choice into the ACP prompt text so the backend knows what tools are available
  • Instruct ACP backend to emit structured <tool_call>{...}</tool_call> blocks
  • Parse XML tool-call blocks back into Hermes-compatible SimpleNamespace objects
  • Bare JSON fallback regex for backends that emit raw JSON without XML tags
  • Set finish_reason='tool_calls' when tool calls are extracted
  • Clean tool-call markup from response text before passing to the agent

Follow-up fix

Fixed duplicate tool call extraction bug in original PR — when both XML block regex and bare JSON regex matched the same content, the same tool call was extracted twice. XML blocks now take precedence; bare JSON fallback only runs when no XML blocks are found.

What was stripped from original PR

  • Heuristic fallback system (_heuristic_fallback_tool_calls) that auto-synthesized tool calls from prose — dangerous because it bypasses model judgment
  • Portuguese-language patterns in regexes and intent detection — adapter should be language-agnostic
  • Vision/terminal-specific hardcoded fallbacks

Validation

  • 12 E2E tests covering: XML block parsing, bare JSON parsing, multiple calls, auto-generated IDs, invalid JSON handling, dict→string argument serialization, empty/None inputs, prompt formatting with/without tools, duplicate prevention, SimpleNamespace shape verification

Salvaged from PR #4536 by @MestreY0d4-Uninter — contributor authorship preserved in commit.

Enable Hermes tool execution through the copilot-acp adapter by:
- Passing tool schemas and tool_choice into the ACP prompt text
- Instructing ACP backend to emit <tool_call>{...}</tool_call> blocks
- Parsing XML tool-call blocks and bare JSON fallback back into
  Hermes-compatible SimpleNamespace tool call objects
- Setting finish_reason='tool_calls' when tool calls are extracted
- Cleaning tool-call markup from response text

Fix duplicate tool call extraction when both XML block and bare JSON
regexes matched the same content (XML blocks now take precedence).

Cherry-picked from PR #4536 by MestreY0d4-Uninter. Stripped heuristic
fallback system (auto-synthesized tool calls from prose) and
Portuguese-language patterns — tool execution should be model-decided,
not heuristic-guessed.
@teknium1
teknium1 merged commit 6c12999 into main Apr 6, 2026
3 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants