-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
fix: sequential tool calling for non-streaming responses #832
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
Changes from all commits
48d0f8d
9abd2a3
4466e50
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| """Test sequential tool calling fix""" | ||
| from praisonaiagents import Agent | ||
|
|
||
| def get_stock_price(company_name: str) -> str: | ||
| """ | ||
| Get the stock price of a company | ||
|
|
||
| Args: | ||
| company_name (str): The name of the company | ||
|
|
||
| Returns: | ||
| str: The stock price of the company | ||
| """ | ||
| print(f"Tool called: get_stock_price({company_name})") | ||
| return f"The stock price of {company_name} is 100" | ||
|
|
||
| def multiply(a: int, b: int) -> int: | ||
| """ | ||
| Multiply two numbers | ||
| """ | ||
| print(f"Tool called: multiply({a}, {b})") | ||
| return a * b | ||
|
|
||
| # Test with streaming disabled to verify the fix | ||
| print("Testing sequential tool calling with stream=False...") | ||
| agent = Agent( | ||
| instructions="You are a helpful assistant. You can use the tools provided to you to help the user.", | ||
| llm="gemini/gemini-2.5-flash-lite-preview-06-17", | ||
| self_reflect=False, | ||
| verbose=True, | ||
| tools=[get_stock_price, multiply], | ||
| stream=False # Force non-streaming mode - use stream parameter directly | ||
| ) | ||
|
|
||
| result = agent.chat("Get the stock price of Google and multiply it by 2") | ||
| print(f"\nFinal result: {result}") | ||
|
|
||
| # Test with default streaming mode | ||
| print("\n\nTesting sequential tool calling with default streaming...") | ||
| agent2 = Agent( | ||
| instructions="You are a helpful assistant. You can use the tools provided to you to help the user.", | ||
| llm="gemini/gemini-2.5-flash-lite-preview-06-17", | ||
| self_reflect=False, | ||
| verbose=True, | ||
| tools=[get_stock_price, multiply] | ||
| ) | ||
|
|
||
| result2 = agent2.chat("Get the stock price of Google and multiply it by 2") | ||
| print(f"\nFinal result: {result2}") | ||
|
Comment on lines
+38
to
+49
Contributor
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. 🛠️ Refactor suggestion Add result validation and consider error handling. Similar to the non-streaming test, this streaming test needs validation to confirm the expected behavior. Additionally, consider adding basic error handling. Add validation and basic error handling: result2 = agent2.chat("Get the stock price of Google and multiply it by 2")
print(f"\nFinal result: {result2}")
+
+# Validate the result
+if result2 is None:
+ print("❌ FAILED: Result is None - sequential tool calling not working in streaming mode")
+elif "200" in str(result2):
+ print("✅ PASSED: Sequential tool calling working correctly in streaming mode")
+else:
+ print(f"⚠️ UNEXPECTED: Got result '{result2}' - please verify manually")
+
+# Basic error handling for the entire test
+if __name__ == "__main__":
+ try:
+ # Move the existing test code here
+ pass
+ except Exception as e:
+ print(f"❌ TEST FAILED with exception: {e}")
🤖 Prompt for AI Agents |
||
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.
🛠️ Refactor suggestion
Add result validation to verify the fix works correctly.
The non-streaming test configuration looks good, but the test lacks validation to ensure the sequential tool calling produces the expected result. Based on the PR comments mentioning that the final response was
None, this validation is crucial.Add validation after the result to verify the fix:
result = agent.chat("Get the stock price of Google and multiply it by 2") print(f"\nFinal result: {result}") + +# Validate the result +if result is None: + print("❌ FAILED: Result is None - sequential tool calling not working in non-streaming mode") +elif "200" in str(result): + print("✅ PASSED: Sequential tool calling working correctly in non-streaming mode") +else: + print(f"⚠️ UNEXPECTED: Got result '{result}' - please verify manually")📝 Committable suggestion
🤖 Prompt for AI Agents