Preserve provider reasoning metadata and batch concurrent tool results - #155
Merged
Conversation
Contributor
Reviewer's GuideEnsure assistant messages created during tool execution round-trip provider thinking fields verbatim (including reasoning_signature and extra fields) and batch concurrent tool calls into a single assistant message followed by ordered ToolResults, while tightening error handling behavior and updating docs and templates. Sequence diagram for batched tool-call handling and thinking-field round-tripsequenceDiagram
participant Agent as ReactBaseAgent
participant Provider as LLMProvider
participant ToolRunner as ToolRunner
participant Ctx as ContextMessageList
Agent->>Provider: _execute_tool_loop(request)
Provider-->>Agent: UniResponse(response_msg with tool_calls)
Agent->>ToolRunner: _run_tool_calls_concurrently(tool_calls)
ToolRunner-->>Agent: concurrent_results[ToolCall, func_response, exc]
Agent->>Agent: _append_tool_results_batch(response_msg, results)
Agent->>Ctx: append Message(role=assistant, content=response_msg.content, tool_calls=[all ToolCall])
Agent->>Agent: _assistant_fields_from_response(response_msg)
Agent->>Ctx: append ToolResult for each ToolCall
Agent->>Agent: _maybe_inject_tool_failure_hint(tool_call, func_response)
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Member
Author
|
@sourcery-ai title |
Contributor
There was a problem hiding this comment.
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="src/amrita_core/builtins/agent/react_base.py" line_range="1154-1159" />
<code_context>
# concurrent runner); surface the error, don't swallow.
self.reasoning_pc = 0
await self._handle_error_append(
- function_name,
+ tc,
</code_context>
<issue_to_address>
**issue (bug_risk):** Error paths are now appended twice: once via `_handle_error_append` and again in the batch helper.
In the `exc is not None` branch, `_handle_error_append` appends an assistant+tool message pair, and the `(tc, func_response, exc)` tuple is still added to `collected` for `_append_tool_results_batch`. That causes error outputs to be emitted twice and may violate the "one tool_result per tool_call" assumption, breaking downstream logic expecting a single error record. To avoid this, either make `_handle_error_append` non-append-only for exceptions (e.g., diagnostics only), or skip adding to `collected`/`result_msg_list` when `exc is not None` so errors are surfaced only via the handler.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Deploying amritacore with
|
| Latest commit: |
9b29a24
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://9b4d5ec0.amritacore.pages.dev |
| Branch Preview URL: | https://fix-agent.amritacore.pages.dev |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary by Sourcery
Ensure agent tool-call handling preserves provider reasoning metadata and batches concurrent tool results into a single assistant message per response.
Bug Fixes:
Enhancements:
Build:
Documentation: