0xPlaygrounds / 0xPlaygrounds/rig
bug: Malformed tool call params kill the whole agent run
- Lingua principale
- Rust
- Stelle
- 8.6k
- Fork
- 959
- Merge medio
- 4h 32m
- PR unite (30g)
- 117
Descrizione
- [x] I have looked for existing issues (including closed) about this
## Bug Report
Malformed JSON in a streamed tool call terminates the entire agent run. This prevents the error being returned to the model so it can retry the call.
In Rig 0.42, [`[parts.rs](https://github.com/0xPlaygrounds/rig/blob/v0.42.0/crates/rig-core/src/streaming/parts.rs#L693-L697)`](https://github.com/0xPlaygrounds/rig/blob/v0.42.0/crates/rig-core/src/streaming/parts.rs#L693-L697) returns a terminal error:
```rust
UnparseableToolInput::Error => {
return Err(CompletionError::ResponseError(format!(
"tool call `{name}` arrived with malformed JSON input: {err}"
)));
}
```
This behaviour is also present on the current `main` branch.
A real example is documented in [[bionic-gpt/bionic-gpt#1041](https://github.com/bionic-gpt/bionic-gpt/issues/1041)](https://github.com/bionic-gpt/bionic-gpt/issues/1041).
## Reproduction
Use an OpenAI-compatible streaming provider and have it return a completed tool call with malformed arguments:
```text
tool: run_bash
arguments: {"command":"printf '\x'"}
finish_reason: tool_calls
```
Rig returns:
```text
tool call `run_bash` arrived with malformed JSON input
```
The agent run then ends.
## Expected behavior
The malformed call must not be executed, but the agent should be able to return a structured failure to the model and allow a bounded retry.
The failure should preserve:
* Tool-call ID
* Tool name
* Raw arguments
* Parse error
Strict completion users could retain the current fail-fast behaviour.
Related work:
* [[#2095](https://github.com/0xPlaygrounds/rig/issues/2095)](https://github.com/0xPlaygrounds/rig/issues/2095) requests bounded model retries for failed tool calls.
* [[#2118](https://github.com/0xPlaygrounds/rig/issues/2118)](https://github.com/0xPlaygrounds/rig/issues/2118) includes making provider failures available to retry policies.
## Screenshots
Not applicable.
## Additional context
Observed with Rig 0.42 using an OpenAI-compatible streaming endpoint. Catching the current `ResponseError` in the application is brittle because the failure is reduced to an error string.
Guida per i contributori
Apri la guida per i contributori
Direzione di ricerca
The bug is in crates/rig-core/src/streaming/parts.rs around lines 693-697, where UnparseableToolInput::Error triggers a terminal CompletionError. Start by reading the streaming module to understand how tool calls are parsed and errors are propagated. The fix should change the error handling to preserve tool-call ID, name, raw arguments, and parse error for model retry, instead of terminating the run. Check related issues #2095 and #2118 for context on retry policies. Run tests to ensure the agent can now return a structured failure.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- rust
- Ambito
- ai-infra-agents
- Tipo di issue
- Bug
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Attiva
- Chiarezza
- Specificata chiaramente
- Idoneità per principianti
- 65/100