mirror of
https://github.com/Significant-Gravitas/AutoGPT.git
synced 2026-04-08 03:00:28 -04:00
More prompt engineering
This commit is contained in:
@@ -58,10 +58,7 @@ from .base import (
|
||||
from .features.agent_file_manager import FileManagerComponent
|
||||
from .features.context import AgentContext, ContextComponent
|
||||
from .features.watchdog import WatchdogComponent
|
||||
from .prompt_strategies.code_flow import (
|
||||
CodeFlowAgentPromptStrategy,
|
||||
CodeFlowAgentActionProposal,
|
||||
)
|
||||
from .prompt_strategies.code_flow import CodeFlowAgentPromptStrategy
|
||||
from .protocols import (
|
||||
AfterExecute,
|
||||
AfterParse,
|
||||
|
||||
@@ -5,7 +5,7 @@ from logging import Logger
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
from autogpt.agents.base import BaseAgentActionProposal
|
||||
from autogpt.agents.prompt_strategies.one_shot import OneShotAgentPromptConfiguration
|
||||
from autogpt.agents.prompt_strategies.one_shot import OneShotAgentPromptConfiguration, AssistantThoughts
|
||||
from autogpt.config.ai_directives import AIDirectives
|
||||
from autogpt.config.ai_profile import AIProfile
|
||||
from autogpt.core.configuration.schema import SystemConfiguration
|
||||
@@ -25,22 +25,6 @@ from autogpt.utils.function.model import FunctionDef
|
||||
|
||||
_RESPONSE_INTERFACE_NAME = "AssistantResponse"
|
||||
|
||||
|
||||
class AssistantThoughts(ModelWithSummary):
|
||||
observations: str = Field(
|
||||
..., description="Relevant observations from your last action (if any)"
|
||||
)
|
||||
self_criticism: str = Field(..., description="Constructive self-criticism")
|
||||
reasoning: str = Field(..., description="Reasoning towards a new plan")
|
||||
plan: list[str] = Field(
|
||||
...,
|
||||
description="Short list that conveys your long-term plan. Parallelize where possible.",
|
||||
)
|
||||
|
||||
def summary(self) -> str:
|
||||
return self.reasoning
|
||||
|
||||
|
||||
class CodeFlowAgentActionProposal(BaseModel):
|
||||
thoughts: AssistantThoughts
|
||||
immediate_plan: str = Field(
|
||||
@@ -66,8 +50,8 @@ FINAL_INSTRUCTION: str = (
|
||||
# "Determine exactly one command to use next based on the given goals "
|
||||
# "and the progress you have made so far, "
|
||||
# "and respond using the JSON schema specified previously:"
|
||||
"You have to give the answer in the from of JSON schema specified previously."
|
||||
"For the `python_code` field, you have to write Python code to execute your plan as efficiently as possible."
|
||||
"You have to give the answer in the from of JSON schema specified previously. "
|
||||
"For the `python_code` field, you have to write Python code to execute your plan as efficiently as possible. "
|
||||
"Your code will be executed directly without any editing: "
|
||||
"if it doesn't work you will be held responsible. "
|
||||
"Use ONLY the listed available functions and built-in Python features. "
|
||||
@@ -217,10 +201,6 @@ class CodeFlowAgentPromptStrategy(PromptStrategy):
|
||||
)
|
||||
)
|
||||
assistant_reply_dict = extract_dict_from_json(response.content)
|
||||
self.logger.debug(
|
||||
"Parsing object extracted from LLM response:\n"
|
||||
f"{json.dumps(assistant_reply_dict, indent=4)}"
|
||||
)
|
||||
|
||||
parsed_response = CodeFlowAgentActionProposal.parse_obj(assistant_reply_dict)
|
||||
if not parsed_response.python_code:
|
||||
@@ -262,6 +242,7 @@ class CodeFlowAgentPromptStrategy(PromptStrategy):
|
||||
name="execute_code_flow",
|
||||
arguments={
|
||||
"python_code": code_validation.functionCode,
|
||||
"plan_text": parsed_response.immediate_plan,
|
||||
},
|
||||
),
|
||||
)
|
||||
|
||||
@@ -31,14 +31,17 @@ _RESPONSE_INTERFACE_NAME = "AssistantResponse"
|
||||
|
||||
|
||||
class AssistantThoughts(ModelWithSummary):
|
||||
past_action_summary: str = Field(
|
||||
..., description="Summary of the last action you took, if ther is none, you can leave it empty"
|
||||
)
|
||||
observations: str = Field(
|
||||
..., description="Relevant observations from your last action (if any)"
|
||||
..., description="Relevant observations from your last actions (if any)"
|
||||
)
|
||||
text: str = Field(..., description="Thoughts")
|
||||
reasoning: str = Field(..., description="Reasoning behind the thoughts")
|
||||
self_criticism: str = Field(..., description="Constructive self-criticism")
|
||||
plan: list[str] = Field(
|
||||
..., description="Short list that conveys the long-term plan"
|
||||
..., description="Short list that conveys the long-term plan considering the progress on your task so far"
|
||||
)
|
||||
speak: str = Field(..., description="Summary of thoughts, to say to user")
|
||||
|
||||
|
||||
@@ -33,9 +33,14 @@ class CodeFlowExecutionComponent(CommandProvider):
|
||||
description="The Python code to execute",
|
||||
required=True,
|
||||
),
|
||||
"plan_text": JSONSchema(
|
||||
type=JSONSchema.Type.STRING,
|
||||
description="The plan to written in a natural language",
|
||||
required=False,
|
||||
),
|
||||
},
|
||||
)
|
||||
async def execute_code_flow(self, python_code: str) -> str:
|
||||
async def execute_code_flow(self, python_code: str, plan_text: str) -> str:
|
||||
"""Execute the code flow.
|
||||
|
||||
Args:
|
||||
@@ -52,4 +57,4 @@ class CodeFlowExecutionComponent(CommandProvider):
|
||||
}
|
||||
exec(code, result)
|
||||
result = str(await result['exec_output'])
|
||||
return result
|
||||
return f"Execution Plan:\n{plan_text}\n\nExecution Output:\n{result}"
|
||||
|
||||
@@ -38,7 +38,7 @@ class EventHistoryComponent(MessageProvider, AfterParse, AfterExecute, Generic[A
|
||||
self.max_tokens,
|
||||
self.count_tokens,
|
||||
):
|
||||
yield ChatMessage.system(f"## Progress on your Task so far\n\n{progress}")
|
||||
yield ChatMessage.system(f"## Progress on your Task so far\nThis is the list of the steps that you have executed previously, use this as your consideration on considering the next action!\n{progress}")
|
||||
|
||||
def after_parse(self, result: AP) -> None:
|
||||
self.event_history.register_action(result)
|
||||
|
||||
4
autogpts/autogpt/poetry.lock
generated
4
autogpts/autogpt/poetry.lock
generated
@@ -4745,7 +4745,7 @@ files = [
|
||||
name = "ptyprocess"
|
||||
version = "0.7.0"
|
||||
description = "Run a subprocess in a pseudo terminal"
|
||||
optional = true
|
||||
optional = false
|
||||
python-versions = "*"
|
||||
files = [
|
||||
{file = "ptyprocess-0.7.0-py2.py3-none-any.whl", hash = "sha256:4b41f3967fce3af57cc7e94b888626c18bf37a083e3651ca8feeb66d492fef35"},
|
||||
@@ -7320,4 +7320,4 @@ benchmark = ["agbenchmark"]
|
||||
[metadata]
|
||||
lock-version = "2.0"
|
||||
python-versions = "^3.10"
|
||||
content-hash = "2ce5b3a7793bdc98bfe0bbb94ae153bbfe60d5767d9e5490420cc000c2959609"
|
||||
content-hash = "e4f170809cd2c0c6daaa3130393870ff1873efde0b5b5860ad60c25d9a64afb1"
|
||||
|
||||
@@ -77,6 +77,7 @@ google-cloud-storage = "^2.13.0"
|
||||
psycopg2-binary = "^2.9.9"
|
||||
ruff = "^0.4.4"
|
||||
pyright = "^1.1.362"
|
||||
ptyprocess = "^0.7.0"
|
||||
|
||||
[tool.poetry.extras]
|
||||
benchmark = ["agbenchmark"]
|
||||
|
||||
Reference in New Issue
Block a user