-
Notifications
You must be signed in to change notification settings - Fork 16
allow reasoning details to pass through #355
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
8 commits
Select commit
Hold shift + click to select a range
55eafa2
allow reasoning details to pass through
xzrderek a8c103d
update
xzrderek 1d630d4
address comments
xzrderek 8366a85
make generic
xzrderek 4bc58f7
update
xzrderek 4ebc8c4
more generic storing of provider_specific_fields
xzrderek 15ff290
add a test
xzrderek 16ffbac
put message back in dict
xzrderek 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,95 @@ | ||
| import types | ||
|
|
||
| import pytest | ||
|
|
||
| import eval_protocol.mcp.execution.policy as policy_mod | ||
| from eval_protocol.mcp.execution.policy import LiteLLMPolicy | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_litellm_policy_surfaces_provider_specific_reasoning_details(monkeypatch): | ||
| """ | ||
| Ensure that provider_specific_fields from the LiteLLM message object are | ||
| preserved on the returned message dict from LiteLLMPolicy._make_llm_call. | ||
| """ | ||
|
|
||
| # Define a fake ModelResponse base class and patch the module's ModelResponse | ||
| class FakeModelResponseBase: ... | ||
|
|
||
| policy_mod.ModelResponse = FakeModelResponseBase | ||
|
|
||
| async def fake_acompletion(*args, **kwargs): | ||
| # This mimics the LiteLLM Message object shape we rely on in policy._make_llm_call | ||
| message_obj = types.SimpleNamespace( | ||
| role="assistant", | ||
| content="", | ||
| tool_calls=[ | ||
| types.SimpleNamespace( | ||
| id="tool_get_reservation_details_123", | ||
| type="function", | ||
| function=types.SimpleNamespace( | ||
| name="get_reservation_details", | ||
| arguments='{"reservation_id":"EHGLP3"}', | ||
| ), | ||
| ) | ||
| ], | ||
| provider_specific_fields={ | ||
| "reasoning_details": [{"id": "tool_get_reservation_details_123", "type": "reasoning.encrypted"}], | ||
| "custom_field": "keep_me", | ||
| }, | ||
| ) | ||
|
|
||
| class FakeModelResponse(FakeModelResponseBase): | ||
| def __init__(self) -> None: | ||
| self.choices = [ | ||
| types.SimpleNamespace( | ||
| finish_reason="tool_calls", | ||
| index=0, | ||
| message=message_obj, | ||
| ) | ||
| ] | ||
| self.usage = types.SimpleNamespace( | ||
| prompt_tokens=10, | ||
| completion_tokens=5, | ||
| total_tokens=15, | ||
| ) | ||
|
|
||
| return FakeModelResponse() | ||
|
|
||
| # Patch acompletion so we don't hit the network | ||
| monkeypatch.setattr(policy_mod, "acompletion", fake_acompletion) | ||
|
|
||
| # Use a concrete policy instance; base_url/model_id values don't matter for this unit test | ||
| policy = LiteLLMPolicy(model_id="openrouter/google/gemini-3-pro-preview", use_caching=False) | ||
|
|
||
| messages = [ | ||
| { | ||
| "role": "assistant", | ||
| "content": "", | ||
| "tool_calls": [ | ||
| { | ||
| "id": "tool_get_reservation_details_123", | ||
| "type": "function", | ||
| "function": {"name": "get_reservation_details", "arguments": '{"reservation_id":"EHGLP3"}'}, | ||
| } | ||
| ], | ||
| } | ||
| ] | ||
|
|
||
| # No tools are needed for this test – we only care about the returned message shape | ||
| result = await policy._make_llm_call(messages, tools=[]) | ||
|
|
||
| assert "choices" in result | ||
| assert len(result["choices"]) == 1 | ||
| msg = result["choices"][0]["message"] | ||
|
|
||
| # Core fields should be present | ||
| assert msg["role"] == "assistant" | ||
| assert isinstance(msg.get("tool_calls"), list) | ||
|
|
||
| # provider_specific_fields should be preserved on the message | ||
| ps = msg.get("provider_specific_fields") | ||
| assert isinstance(ps, dict) | ||
| assert ps["reasoning_details"] == [{"id": "tool_get_reservation_details_123", "type": "reasoning.encrypted"}] | ||
| # Non-core provider_specific_fields should also be preserved | ||
| assert ps.get("custom_field") == "keep_me" |
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.