-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
feat(agents): propagate tool_call_id through middleware context #4023
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
MervinPraison
merged 2 commits into
MervinPraison:main
from
MkaliezZ:feat/agentfuse-tool-middleware
Aug 19, 2026
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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
68 changes: 68 additions & 0 deletions
68
src/praisonai-agents/tests/unit/hooks/test_tool_call_identity_context.py
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,68 @@ | ||
| """Tests for tool-call identity exposed through middleware context.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import pytest | ||
| from praisonaiagents import Agent | ||
| from praisonaiagents.hooks import wrap_tool_call | ||
|
|
||
|
|
||
| def test_sync_tool_middleware_receives_original_tool_call_id(): | ||
| observed_ids: list[str | None] = [] | ||
| handler_calls: list[str] = [] | ||
|
|
||
| @wrap_tool_call | ||
| def capture_identity(request, call_next): | ||
| observed_ids.append(request.context.metadata.get("tool_call_id")) | ||
| return call_next(request) | ||
|
|
||
| def inert_tool(value: str) -> str: | ||
| handler_calls.append(value) | ||
| return "completed" | ||
|
|
||
| agent = Agent( | ||
| name="sync-middleware-identity", | ||
| instructions="Exercise one inert test tool.", | ||
| tools=[inert_tool], | ||
| hooks=[capture_identity], | ||
| approval=True, | ||
| ) | ||
|
|
||
| result = agent.execute_tool( | ||
| "inert_tool", {"value": "synthetic-value"}, "sync-tool-call-001" | ||
| ) | ||
|
|
||
| assert result == "completed" | ||
| assert handler_calls == ["synthetic-value"] | ||
| assert observed_ids == ["sync-tool-call-001"] | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_async_tool_middleware_receives_original_tool_call_id(): | ||
| observed_ids: list[str | None] = [] | ||
| handler_calls: list[str] = [] | ||
|
|
||
| @wrap_tool_call | ||
| def capture_identity(request, call_next): | ||
| observed_ids.append(request.context.metadata.get("tool_call_id")) | ||
| return call_next(request) | ||
|
|
||
| async def inert_tool(value: str) -> str: | ||
| handler_calls.append(value) | ||
| return "completed" | ||
|
|
||
| agent = Agent( | ||
| name="async-middleware-identity", | ||
| instructions="Exercise one inert test tool.", | ||
| tools=[inert_tool], | ||
| hooks=[capture_identity], | ||
| approval=True, | ||
| ) | ||
|
|
||
| result = await agent.execute_tool_async( | ||
| "inert_tool", {"value": "synthetic-value"}, "async-tool-call-001" | ||
| ) | ||
|
|
||
| assert result == "completed" | ||
| assert handler_calls == ["synthetic-value"] | ||
| assert observed_ids == ["async-tool-call-001"] | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📐 Maintainability & Code Quality | 🟠 Major | 🏗️ Heavy lift
Add the required real agentic test.
These tests call tool execution or
_achat_completiondirectly. They do not callagent.start()with a real prompt, invoke the LLM, and print the full output. Add the required agentic test in the appropriate test category. Verify that the provider-originated tool-call ID reaches middleware during the full agent flow.src/praisonai-agents/tests/unit/hooks/test_tool_call_identity_context.py#L10-L68: retain these unit tests and add coverage for the full agent flow.src/praisonai-agents/tests/unit/agent/test_achat_unified_dispatch.py#L88-L122: include legacy dispatch in the real agentic coverage if that path remains supported.As per coding guidelines, “Every feature requires both smoke tests and a real agentic test in which an Agent calls
agent.start()with a real prompt, invokes the LLM, and prints the full output.”📍 Affects 2 files
src/praisonai-agents/tests/unit/hooks/test_tool_call_identity_context.py#L10-L68(this comment)src/praisonai-agents/tests/unit/agent/test_achat_unified_dispatch.py#L88-L122🤖 Prompt for AI Agents
Source: Coding guidelines