Skip to content

Commit 9013fd1

Browse files
test: add test scripts for sequential tool calling fix
Add test scripts to verify the fix for issue #839 works correctly with both Gemini and GPT-4 models. Co-authored-by: Mervin Praison <[email protected]>
1 parent 48dca82 commit 9013fd1

File tree

2 files changed

+105
-0
lines changed

2 files changed

+105
-0
lines changed

test_fix.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
from praisonaiagents import Agent
2+
3+
def get_stock_price(company_name: str) -> str:
4+
"""
5+
Get the stock price of a company
6+
7+
Args:
8+
company_name (str): The name of the company
9+
10+
Returns:
11+
str: The stock price of the company
12+
"""
13+
return f"The stock price of {company_name} is 100"
14+
15+
def multiply(a: int, b: int) -> int:
16+
"""
17+
Multiply two numbers
18+
"""
19+
return a * b
20+
21+
22+
23+
agent = Agent(
24+
instructions="You are a helpful assistant. You can use the tools provided to you to help the user.",
25+
llm="gemini/gemini-2.5-pro",
26+
tools=[get_stock_price, multiply]
27+
)
28+
29+
result = agent.start("what is the stock price of Google? multiply the Google stock price with 2")
30+
print(result)

test_fix_comprehensive.py

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
"""
2+
Test script to verify the fix for sequential tool calling.
3+
The agent should:
4+
1. Call get_stock_price to get Google's stock price (100)
5+
2. Call multiply to multiply 100 by 2
6+
3. Return the final result (200)
7+
"""
8+
9+
from praisonaiagents import Agent
10+
11+
def get_stock_price(company_name: str) -> str:
12+
"""
13+
Get the stock price of a company
14+
15+
Args:
16+
company_name (str): The name of the company
17+
18+
Returns:
19+
str: The stock price of the company
20+
"""
21+
print(f"[Tool Called] get_stock_price({company_name})")
22+
return f"The stock price of {company_name} is 100"
23+
24+
def multiply(a: int, b: int) -> int:
25+
"""
26+
Multiply two numbers
27+
28+
Args:
29+
a (int): First number
30+
b (int): Second number
31+
32+
Returns:
33+
int: Product of a and b
34+
"""
35+
print(f"[Tool Called] multiply({a}, {b})")
36+
return a * b
37+
38+
# Test with Gemini
39+
print("=" * 60)
40+
print("Testing with Gemini model")
41+
print("=" * 60)
42+
43+
agent_gemini = Agent(
44+
instructions="You are a helpful assistant. You can use the tools provided to you to help the user. When asked to multiply a stock price, first get the stock price, then multiply it.",
45+
llm="gemini/gemini-2.5-pro",
46+
tools=[get_stock_price, multiply],
47+
verbose=True
48+
)
49+
50+
result_gemini = agent_gemini.start("what is the stock price of Google? multiply the Google stock price with 2")
51+
print(f"\nFinal Result (Gemini): {result_gemini}")
52+
53+
# Test with GPT-4
54+
print("\n" + "=" * 60)
55+
print("Testing with GPT-4 model")
56+
print("=" * 60)
57+
58+
agent_gpt4 = Agent(
59+
instructions="You are a helpful assistant. You can use the tools provided to you to help the user. When asked to multiply a stock price, first get the stock price, then multiply it.",
60+
llm="gpt-4o",
61+
tools=[get_stock_price, multiply],
62+
verbose=True
63+
)
64+
65+
result_gpt4 = agent_gpt4.start("what is the stock price of Google? multiply the Google stock price with 2")
66+
print(f"\nFinal Result (GPT-4): {result_gpt4}")
67+
68+
# Verify results
69+
print("\n" + "=" * 60)
70+
print("Test Results Summary")
71+
print("=" * 60)
72+
print(f"Gemini result contains '200': {'200' in str(result_gemini) if result_gemini else False}")
73+
print(f"GPT-4 result contains '200': {'200' in str(result_gpt4) if result_gpt4 else False}")
74+
print(f"Gemini returned empty: {not result_gemini or result_gemini == ''}")
75+
print(f"GPT-4 returned empty: {not result_gpt4 or result_gpt4 == ''}")

0 commit comments

Comments
 (0)