-
Notifications
You must be signed in to change notification settings - Fork 9
feat(harness): add tool-call parsing as harness::tool_calling #102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
45557a2
feat(harness): add tool-call parsing as harness::tool_calling
senamakel 64242dd
fix(tool_calling): handle empty tool call list in harness
senamakel ba916de
fix(harness): handle tool call with no arguments
senamakel 674f657
fix(parse): handle empty tool call blocks without crashing
senamakel da7ad20
chore: files changed src/harness/tool_calling/parse_test.rs
senamakel 7ebfe28
fix(parse): handle missing tool call arguments gracefully
senamakel 64bb8b4
fix(parse_test): correct test for tool call with no arguments
senamakel b282504
chore: files changed src/harness/tool_calling/parse.rs
senamakel cdbd350
fix(parse_test): correct test for tool call with no arguments
senamakel 5d6f549
fix(parse): handle empty tool call arguments
senamakel 3bcc858
fix(parse_test): handle empty tool call block in parsing
senamakel cde87a7
fix(parse): handle empty tool call blocks without crashing
senamakel 49f2c2a
fix(parse_test): correct test assertion for tool call parsing
senamakel b7087fd
fix(parse): handle missing tool call block in parse_tool_call
senamakel 1ae73ef
fix(parse): handle empty tool call blocks without crashing
senamakel d701c30
fix(parse_test): correct test assertion for tool call parsing
senamakel eadc9fd
Merge remote-tracking branch 'origin/main' into harness-tool-calling
senamakel 6962ba9
Merge branch 'main' into harness-tool-calling
senamakel d7e9ace
test(parse): add regression tests for mixed p-format and non-JSON sib…
senamakel ffbbc0c
test(parse): add missing imports for regression probe test
senamakel 628977a
fix(parse): align fallback logic with canonical JSON parser
senamakel 8679dde
fix(parse): rework tag-walk to preserve multi-call JSON bodies
senamakel b66142a
Merge remote-tracking branch 'origin/harness-tool-calling' into harne…
senamakel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| //! Recovering tool calls from model output. | ||
| //! | ||
| //! A model that supports native tool use hands back structured calls and none | ||
| //! of this is needed. Everything else — prompt-guided models, local models, | ||
| //! providers whose native mode is unavailable or disabled — emits tool calls as | ||
| //! *text*, in whatever shape the model was trained to produce. This module | ||
| //! turns that text back into calls. | ||
| //! | ||
| //! ## Why it is this forgiving | ||
| //! | ||
| //! Each accommodation here exists because a model actually produced it and the | ||
| //! alternative was dropping a well-formed call and burning an agent iteration. | ||
| //! Concretely, the parsers accept `<tool_call>` tags in several spellings, | ||
| //! fenced `tool_call` blocks, bare JSON objects, Anthropic-style | ||
| //! `<invoke name="…"><parameter name="…">` XML, and the compact positional | ||
| //! [`pformat`] syntax. | ||
| //! | ||
| //! The permissiveness is bounded on purpose, and the boundary is worth knowing | ||
| //! before widening anything: | ||
| //! | ||
| //! * **Argument keys are aliased; tool names are not.** A model drifting from | ||
| //! `arguments` to `args`/`parameters`/`params`/`input` still yields a usable | ||
| //! call. The *name* stays strict, because loosening it risks reading a plain | ||
| //! JSON answer as a tool call in the whole-response path — turning an ordinary | ||
| //! reply into a phantom invocation. | ||
| //! * **The generic `input` alias is only honoured behind an explicit marker** | ||
| //! (a `tool_calls` array, a `<tool_call>` tag, a fenced block). Untagged text | ||
| //! does not get it. | ||
| //! * **[`pformat`] refuses to invent argument names for an unknown tool**, so a | ||
| //! model cannot tunnel arbitrary JSON through by guessing a tool name that | ||
| //! does not exist. | ||
| //! | ||
| //! ## What the host still owns | ||
| //! | ||
| //! This module takes **schemas**, never a tool trait object. A host's tool type | ||
| //! is its own vocabulary, and depending on it here would defeat the point — so | ||
| //! [`pformat::build_registry`] takes `(name, schema)` pairs and the host keeps a | ||
| //! one-line adapter over its own tool slice. Dispatch and execution stay host-side | ||
| //! too: this module answers "what did the model ask for", never "what happens next". | ||
|
|
||
| pub(crate) mod parse; | ||
| pub(crate) mod pformat; | ||
|
|
||
| pub use parse::{ParsedToolCall, parse_tool_calls, parse_tool_calls_with_pformat}; | ||
| pub use pformat::{ | ||
| PFormatParamType, PFormatRegistry, PFormatToolParams, build_registry, parse_call, | ||
| render_signature, render_signature_from_schema, | ||
| }; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.