Skip to content
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

Improve error messaging #3236

Merged
merged 2 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions autogen/agentchat/conversable_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -2234,7 +2234,7 @@ def execute_function(self, func_call, verbose: bool = False) -> Tuple[bool, Dict
arguments = json.loads(input_string)
except json.JSONDecodeError as e:
arguments = None
content = f"Error: {e}\n You argument should follow json format."
content = f"Error: {e}\n The argument must be in JSON format."

# Try to execute the function
if arguments is not None:
Expand Down Expand Up @@ -2291,7 +2291,7 @@ async def a_execute_function(self, func_call):
arguments = json.loads(input_string)
except json.JSONDecodeError as e:
arguments = None
content = f"Error: {e}\n You argument should follow json format."
content = f"Error: {e}\n The argument must be in JSON format."

# Try to execute the function
if arguments is not None:
Expand Down
6 changes: 3 additions & 3 deletions test/agentchat/test_function_and_tool_calling.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,11 @@ async def _a_tool_func_error(arg1: str, arg2: str) -> str:
{
"tool_call_id": "1",
"role": "tool",
"content": "Error: Expecting property name enclosed in double quotes: line 1 column 37 (char 36)\n You argument should follow json format.",
"content": "Error: Expecting property name enclosed in double quotes: line 1 column 37 (char 36)\n The argument must be in JSON format.",
},
{"tool_call_id": "2", "role": "tool", "content": "_tool_func_2: value3 value4"},
],
"content": "Error: Expecting property name enclosed in double quotes: line 1 column 37 (char 36)\n You argument should follow json format.\n\n_tool_func_2: value3 value4",
"content": "Error: Expecting property name enclosed in double quotes: line 1 column 37 (char 36)\n The argument must be in JSON format.\n\n_tool_func_2: value3 value4",
}

_tool_use_message_1_error_expected_reply = {
Expand Down Expand Up @@ -154,7 +154,7 @@ async def _a_tool_func_error(arg1: str, arg2: str) -> str:
_function_use_message_1_bad_json_expected_reply = {
"name": "_tool_func_1",
"role": "function",
"content": "Error: Expecting property name enclosed in double quotes: line 1 column 37 (char 36)\n You argument should follow json format.",
"content": "Error: Expecting property name enclosed in double quotes: line 1 column 37 (char 36)\n The argument must be in JSON format.",
}

_function_use_message_1_error_expected_reply = {
Expand Down
4 changes: 2 additions & 2 deletions test/agentchat/test_function_call.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def add_num(num_to_be_added):
"name": "add_num",
"arguments": '{ "num_to_be_added": 5, given_num: 10 }',
} # should be "given_num" with quotes
assert "You argument should follow json format." in user.execute_function(func_call=wrong_json_format)[1]["content"]
assert "The argument must be in JSON format." in user.execute_function(func_call=wrong_json_format)[1]["content"]

# function execution error with wrong arguments passed
wrong_args = {"name": "add_num", "arguments": '{ "num_to_be_added": 5, "given_num": 10 }'}
Expand Down Expand Up @@ -174,7 +174,7 @@ async def add_num(num_to_be_added):
"arguments": '{ "num_to_be_added": 5, given_num: 10 }',
} # should be "given_num" with quotes
assert (
"You argument should follow json format."
"The argument must be in JSON format."
in (await user.a_execute_function(func_call=wrong_json_format))[1]["content"]
)

Expand Down
Loading