aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Reinier van der Leer <pwuts@agpt.co> 2024-04-24 18:59:13 +0200
committerGravatar Reinier van der Leer <pwuts@agpt.co> 2024-04-26 19:34:49 +0200
commit7d727d1b54a6894d282441b2aa895094b9bc7c79 (patch)
treeb84521d87a831163c610b4841d87bcb56243e149
parentfix(agent): Expand failure check in `json_loads(..)` (diff)
downloadAuto-GPT-7d727d1b54a6894d282441b2aa895094b9bc7c79.tar.gz
Auto-GPT-7d727d1b54a6894d282441b2aa895094b9bc7c79.tar.bz2
Auto-GPT-7d727d1b54a6894d282441b2aa895094b9bc7c79.zip
fix(agent): Fix `OneShotAgentPromptStrategy` parser when using functions/tools API
Also: - Improve error message when the LLM doesn't call any tools
-rw-r--r--autogpts/autogpt/autogpt/agents/prompt_strategies/one_shot.py11
1 files changed, 9 insertions, 2 deletions
diff --git a/autogpts/autogpt/autogpt/agents/prompt_strategies/one_shot.py b/autogpts/autogpt/autogpt/agents/prompt_strategies/one_shot.py
index 994df6181..28502349d 100644
--- a/autogpts/autogpt/autogpt/agents/prompt_strategies/one_shot.py
+++ b/autogpts/autogpt/autogpt/agents/prompt_strategies/one_shot.py
@@ -392,7 +392,14 @@ class OneShotAgentPromptStrategy(PromptStrategy):
f"{json.dumps(assistant_reply_dict, indent=4)}"
)
- _, errors = self.response_schema.validate_object(assistant_reply_dict)
+ response_schema = self.response_schema.copy(deep=True)
+ if (
+ self.config.use_functions_api
+ and response_schema.properties
+ and "command" in response_schema.properties
+ ):
+ del response_schema.properties["command"]
+ _, errors = response_schema.validate_object(assistant_reply_dict)
if errors:
raise InvalidAgentResponseError(
"Validation of response failed:\n "
@@ -433,7 +440,7 @@ def extract_command(
"""
if use_openai_functions_api:
if not assistant_reply.tool_calls:
- raise InvalidAgentResponseError("No 'tool_calls' in assistant reply")
+ raise InvalidAgentResponseError("Assistant did not use any tools")
assistant_reply_json["command"] = {
"name": assistant_reply.tool_calls[0].function.name,
"args": assistant_reply.tool_calls[0].function.arguments,