-
Notifications
You must be signed in to change notification settings - Fork 46
fix(runner): handle model-object tool calls in verbose logging #55
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
Open
Sai Asish Y (SAY-5)
wants to merge
2
commits into
dedalus-labs:main
Choose a base branch
from
SAY-5:fix/verbose-tool-call-attribute-error
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| # ============================================================================== | ||
| # © 2025 Dedalus Labs, Inc. and affiliates | ||
| # Licensed under MIT | ||
| # github.com/dedalus-labs/dedalus-sdk-python/LICENSE | ||
| # ============================================================================== | ||
|
|
||
| """Regression tests for verbose-mode logging in DedalusRunner. | ||
|
|
||
| Reproduces dedalus-labs/dedalus-sdk-python#54: ``verbose=True`` crashed with an | ||
| ``AttributeError`` on the first response containing tool calls because the | ||
| verbose print path called ``.get(...)`` on SDK model objects (which behave like | ||
| attribute-only objects, not dicts). | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from types import SimpleNamespace | ||
| from unittest.mock import MagicMock | ||
|
|
||
| from dedalus_labs.lib.runner.core import DedalusRunner, _tool_call_name | ||
|
|
||
|
|
||
| def add(a: int, b: int) -> int: | ||
| """Add two numbers.""" | ||
| return a + b | ||
|
|
||
|
|
||
| def _model_tool_call(call_id: str, name: str, arguments: str): | ||
| """A tool call shaped like an SDK model object (attribute access, no ``.get``).""" | ||
| return SimpleNamespace( | ||
| id=call_id, | ||
| type="function", | ||
| function=SimpleNamespace(name=name, arguments=arguments), | ||
| ) | ||
|
|
||
|
|
||
| def _response_with_tool_calls(*tool_calls): | ||
| message = SimpleNamespace(content=None, tool_calls=list(tool_calls)) | ||
| return SimpleNamespace(model="test-model", choices=[SimpleNamespace(message=message)]) | ||
|
|
||
|
|
||
| def _response_with_text(text: str): | ||
| message = SimpleNamespace(content=text, tool_calls=None) | ||
| return SimpleNamespace(model="test-model", choices=[SimpleNamespace(message=message)]) | ||
|
|
||
|
|
||
| def test_tool_call_name_accepts_dicts_and_model_objects(): | ||
| assert _tool_call_name({"function": {"name": "add"}}) == "add" | ||
| assert _tool_call_name(_model_tool_call("c1", "add", "{}")) == "add" | ||
| assert _tool_call_name({"function": SimpleNamespace(name="add")}) == "add" | ||
| assert _tool_call_name({}) == "?" | ||
| assert _tool_call_name(SimpleNamespace()) == "?" | ||
|
|
||
|
|
||
| def test_run_verbose_with_model_tool_calls_does_not_crash(capsys): | ||
| client = MagicMock() | ||
| client.chat.completions.create.side_effect = [ | ||
| _response_with_tool_calls(_model_tool_call("call_1", "add", '{"a": 3, "b": 4}')), | ||
| _response_with_text("The sum is 7."), | ||
| ] | ||
| client.mcp_tool_results = None | ||
|
|
||
| runner = DedalusRunner(client, verbose=True) | ||
| result = runner.run( | ||
| model="openai/gpt-test", | ||
| input="What is 3 + 4? You MUST call the add tool.", | ||
| tools=[add], | ||
| ) | ||
|
|
||
| assert result.tools_called == ["add"] | ||
| assert result.final_output == "The sum is 7." | ||
| # The verbose path should have printed the tool call name, not "?". | ||
| assert "add" in capsys.readouterr().out |
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.