From 7a7a144690489c6cbe54db9b3c8ecf70111ca06c Mon Sep 17 00:00:00 2001 From: Reinier van der Leer Date: Tue, 7 Nov 2023 16:51:32 -0600 Subject: [PATCH] refactor: Tweak prompts & improve AutoGPT agent step output - Make minor adjustments to prompts in the OneShotAgentPromptConfiguration class - Enhance the output format of the execute_result in AgentProtocolServer - Update the key name from "criticism" to "self_criticism" in print_assistant_thoughts function - Modify the output format of the web search results in the web_search function --- .../agents/prompt_strategies/one_shot.py | 18 +++++++++++++----- .../autogpt/app/agent_protocol_server.py | 3 ++- autogpts/autogpt/autogpt/app/main.py | 2 +- .../autogpt/autogpt/commands/web_search.py | 15 +++++++++++++-- 4 files changed, 29 insertions(+), 9 deletions(-) diff --git a/autogpts/autogpt/autogpt/agents/prompt_strategies/one_shot.py b/autogpts/autogpt/autogpt/agents/prompt_strategies/one_shot.py index d927d65c..304bd4a5 100644 --- a/autogpts/autogpt/autogpt/agents/prompt_strategies/one_shot.py +++ b/autogpts/autogpt/autogpt/agents/prompt_strategies/one_shot.py @@ -42,7 +42,8 @@ class OneShotAgentPromptConfiguration(SystemConfiguration): "{resources}\n" "\n" "## Commands\n" - "You have access to the following commands:\n" + "These are the ONLY commands you can use." + " Any action you perform must be possible through one of these commands:\n" "{commands}\n" "\n" "## Best practices\n" @@ -62,6 +63,13 @@ class OneShotAgentPromptConfiguration(SystemConfiguration): type=JSONSchema.Type.OBJECT, required=True, properties={ + "observations": JSONSchema( + description=( + "Relevant observations from your last action (if any)" + ), + type=JSONSchema.Type.STRING, + required=False, + ), "text": JSONSchema( description="Thoughts", type=JSONSchema.Type.STRING, @@ -71,13 +79,13 @@ class OneShotAgentPromptConfiguration(SystemConfiguration): type=JSONSchema.Type.STRING, required=True, ), - "plan": JSONSchema( - description="Short markdown-style bullet list that conveys the long-term plan", + "self_criticism": JSONSchema( + description="Constructive self-criticism", type=JSONSchema.Type.STRING, required=True, ), - "criticism": JSONSchema( - description="Constructive self-criticism", + "plan": JSONSchema( + description="Short markdown-style bullet list that conveys the long-term plan", type=JSONSchema.Type.STRING, required=True, ), diff --git a/autogpts/autogpt/autogpt/app/agent_protocol_server.py b/autogpts/autogpt/autogpt/app/agent_protocol_server.py index 1426178f..d59b7962 100644 --- a/autogpts/autogpt/autogpt/app/agent_protocol_server.py +++ b/autogpts/autogpt/autogpt/app/agent_protocol_server.py @@ -264,7 +264,8 @@ class AgentProtocolServer: output = ( ( f"Command `{execute_command}({fmt_kwargs(execute_command_args)})` returned:" - f" {execute_result}\n\n" + + ("\n\n" if "\n" in str(execute_result) else " ") + + f"{execute_result}\n\n" ) if execute_command_args and execute_command != "ask_user" else "" diff --git a/autogpts/autogpt/autogpt/app/main.py b/autogpts/autogpt/autogpt/app/main.py index ff454e4d..683793a7 100644 --- a/autogpts/autogpt/autogpt/app/main.py +++ b/autogpts/autogpt/autogpt/app/main.py @@ -692,7 +692,7 @@ def print_assistant_thoughts( ) assistant_thoughts_plan = remove_ansi_escape(assistant_thoughts.get("plan", "")) assistant_thoughts_criticism = remove_ansi_escape( - assistant_thoughts.get("criticism", "") + assistant_thoughts.get("self_criticism", "") ) assistant_thoughts_speak = remove_ansi_escape( assistant_thoughts.get("speak", "") diff --git a/autogpts/autogpt/autogpt/commands/web_search.py b/autogpts/autogpt/autogpt/commands/web_search.py index 8c9a9334..c4411d93 100644 --- a/autogpts/autogpt/autogpt/commands/web_search.py +++ b/autogpts/autogpt/autogpt/commands/web_search.py @@ -61,12 +61,23 @@ def web_search(query: str, agent: Agent, num_results: int = 8) -> str: { "title": r["title"], "url": r["href"], - **({"description": r["body"]} if r.get("body") else {}), + **({"exerpt": r["body"]} if r.get("body") else {}), } for r in search_results ] - results = json.dumps(search_results, ensure_ascii=False, indent=4) + results = ( + "## Search results\n" + # "Read these results carefully." + # " Extract the information you need for your task from the list of results" + # " if possible. Otherwise, choose a webpage from the list to read entirely." + # "\n\n" + ) + "\n\n".join( + f"### \"{r['title']}\"\n" + f"**URL:** {r['url']} \n" + "**Excerpt:** " + (f'"{exerpt}"' if (exerpt := r.get("exerpt")) else "N/A") + for r in search_results + ) return safe_google_results(results)