Skip to content

Commit

Permalink
refactor: Tweak prompts & improve AutoGPT agent step output
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
Pwuts committed Nov 7, 2023
1 parent 0bd776d commit 7a7a144
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 9 deletions.
18 changes: 13 additions & 5 deletions autogpts/autogpt/autogpt/agents/prompt_strategies/one_shot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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,
Expand All @@ -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,
),
Expand Down
3 changes: 2 additions & 1 deletion autogpts/autogpt/autogpt/app/agent_protocol_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,8 @@ async def execute_step(self, task_id: str, step_request: StepRequestBody) -> Ste
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 ""
Expand Down
2 changes: 1 addition & 1 deletion autogpts/autogpt/autogpt/app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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", "")
Expand Down
15 changes: 13 additions & 2 deletions autogpts/autogpt/autogpt/commands/web_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down

0 comments on commit 7a7a144

Please sign in to comment.