-
Notifications
You must be signed in to change notification settings - Fork 109
fix: handle direct model answers in ReACT loop #763
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
Draft
markstur
wants to merge
2
commits into
generative-computing:main
Choose a base branch
from
markstur:issue_762
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.
+119
−0
Draft
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,75 @@ | ||
| """Test ReACT framework handling of direct answers without tool calls.""" | ||
|
|
||
| import pytest | ||
|
|
||
| from mellea.backends.tools import tool | ||
| from mellea.stdlib.context import ChatContext | ||
| from mellea.stdlib.frameworks.react import react | ||
| from mellea.stdlib.session import start_session | ||
|
|
||
|
|
||
| @pytest.mark.ollama | ||
| @pytest.mark.llm | ||
| async def test_react_direct_answer_without_tools(): | ||
| """Test that ReACT handles direct answers when model doesn't call tools. | ||
|
|
||
| This tests the case where the model provides a direct answer in step.value | ||
| without making any tool calls. The fix ensures the loop terminates properly | ||
| instead of continuing until loop_budget is exhausted. | ||
| """ | ||
| m = start_session() | ||
|
|
||
| # Ask a simple question that doesn't require tools | ||
| # The model should provide a direct answer without calling any tools | ||
| out, _ = await react( | ||
| goal="What is 2 + 2?", | ||
| context=ChatContext(), | ||
| backend=m.backend, | ||
| tools=[], # No tools provided | ||
| loop_budget=3, # Should complete in 1 iteration, not exhaust budget | ||
| ) | ||
|
|
||
| # Verify we got an answer | ||
| assert out.value is not None | ||
| assert len(out.value) > 0 | ||
|
|
||
| # The answer should contain "4" or "four" | ||
| answer_lower = out.value.lower() | ||
| assert "4" in answer_lower or "four" in answer_lower | ||
|
|
||
|
|
||
| @pytest.mark.ollama | ||
| @pytest.mark.llm | ||
| async def test_react_direct_answer_with_unused_tools(): | ||
| """Test that ReACT handles direct answers even when tools are available. | ||
|
|
||
| This tests the case where tools are provided but the model chooses to | ||
| answer directly without using them. | ||
| """ | ||
| m = start_session() | ||
|
|
||
| # Create a dummy tool that won't be needed | ||
| @tool | ||
| def search_web(query: str) -> str: | ||
| """Search the web for information.""" | ||
| return "Search results" | ||
|
|
||
| # Ask a question that doesn't need the tool | ||
| out, _ = await react( | ||
| goal="What is the capital of France?", | ||
| context=ChatContext(), | ||
| backend=m.backend, | ||
| tools=[search_web], | ||
| loop_budget=3, | ||
| ) | ||
|
|
||
| # Verify we got an answer | ||
| assert out.value is not None | ||
| assert len(out.value) > 0 | ||
|
|
||
| # The answer should mention Paris | ||
| answer_lower = out.value.lower() | ||
| assert "paris" in answer_lower | ||
|
|
||
|
|
||
| # Made with Bob | ||
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.
We updated our markers (llm->e2e).