-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Test validate_tools_and_managed_agents #731
Open
albertvillanova
wants to merge
2
commits into
huggingface:main
Choose a base branch
from
albertvillanova:test-721
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 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 |
---|---|---|
|
@@ -16,6 +16,7 @@ | |
import tempfile | ||
import unittest | ||
import uuid | ||
from contextlib import nullcontext as does_not_raise | ||
from pathlib import Path | ||
from unittest.mock import MagicMock | ||
|
||
|
@@ -41,7 +42,7 @@ | |
MessageRole, | ||
TransformersModel, | ||
) | ||
from smolagents.tools import tool | ||
from smolagents.tools import Tool, tool | ||
from smolagents.utils import BASE_BUILTIN_MODULES | ||
|
||
|
||
|
@@ -559,6 +560,23 @@ def check_always_fails(final_answer, agent_memory): | |
assert "Error raised in check" in str(agent.write_memory_to_messages()) | ||
|
||
|
||
class MockTool(Tool): | ||
def __init__(self, name): | ||
self.name = name | ||
self.description = "Mock tool description" | ||
self.inputs = {} | ||
self.output_type = "string" | ||
|
||
def forward(self): | ||
return "Mock tool output" | ||
|
||
|
||
class MockAgent: | ||
def __init__(self, name, tools): | ||
self.name = name | ||
self.tools = {t.name: t for t in tools} | ||
|
||
|
||
class TestMultiStepAgent: | ||
def test_instantiation_disables_logging_to_terminal(self): | ||
fake_model = MagicMock() | ||
|
@@ -760,6 +778,44 @@ def test_provide_final_answer(self, images, expected_messages_list): | |
for content, expected_content in zip(message["content"], expected_message["content"]): | ||
assert content == expected_content | ||
|
||
@pytest.mark.parametrize( | ||
"tools, managed_agents, expectation", | ||
[ | ||
# Valid case: no duplicates | ||
( | ||
[MockTool("tool1"), MockTool("tool2")], | ||
[MockAgent("agent1", [MockTool("tool3")])], | ||
does_not_raise(), | ||
), | ||
# Invalid case: duplicate tool names | ||
([MockTool("tool1"), MockTool("tool1")], [], pytest.raises(ValueError)), | ||
# Invalid case: tool name same as managed agent name | ||
([MockTool("tool1")], [MockAgent("tool1", [MockTool("final_answer")])], pytest.raises(ValueError)), | ||
# Invalid case: tool name same as managed agent's tool name | ||
([MockTool("tool1")], [MockAgent("agent1", [MockTool("tool1")])], pytest.raises(ValueError)), | ||
# Invalid case: duplicate managed agent name and managed agent tool name | ||
([], [MockAgent("tool1", [MockTool("tool1")])], pytest.raises(ValueError)), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above, I'm not sure that this should raise an error. |
||
# Invalid case: duplicate tool names across managed agents | ||
( | ||
[MockTool("tool1")], | ||
[ | ||
MockAgent("agent1", [MockTool("tool2"), MockTool("final_answer")]), | ||
MockAgent("agent2", [MockTool("tool2"), MockTool("final_answer")]), | ||
], | ||
pytest.raises(ValueError), | ||
), | ||
], | ||
) | ||
def test_validate_tools_and_managed_agents(self, tools, managed_agents, expectation): | ||
# Mock MultiStepAgent class | ||
class MockMultiStepAgent(MultiStepAgent): | ||
def __init__(self): | ||
pass | ||
|
||
agent = MockMultiStepAgent() | ||
with expectation: | ||
agent._validate_tools_and_managed_agents(tools, managed_agents) | ||
|
||
|
||
class TestCodeAgent: | ||
@pytest.mark.parametrize("provide_run_summary", [False, True]) | ||
|
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.
Not sure this specific case should raise an error? For me the disambiguation is to save the model a confusion : since the manager agent's model will never see the managed agent tools, this would not be a problem.