mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-05-05 22:02:38 +02:00
update reflect on previous plan
This commit is contained in:
parent
d3d08fe5f3
commit
8d7657f347
5 changed files with 44 additions and 27 deletions
|
|
@ -3,6 +3,7 @@ from typing import Dict, List, Union
|
|||
|
||||
from metagpt.actions import Action
|
||||
from metagpt.schema import Message, Plan
|
||||
from metagpt.utils.common import CodeParser
|
||||
from metagpt.logs import logger
|
||||
|
||||
|
||||
|
|
@ -98,22 +99,30 @@ class SummarizeAnalysis(Action):
|
|||
|
||||
class Reflect(Action):
|
||||
PROMPT_TEMPLATE = """
|
||||
# User Requirement
|
||||
{user_requirement}
|
||||
# Context
|
||||
{context}
|
||||
__context__
|
||||
# Latest User Requirement
|
||||
__user_requirement__
|
||||
# Summary
|
||||
Above is all your attempts to tackle the user requirement. You plan, act, submit your output, and get the result and feedback.
|
||||
First, summarize each of your previous trial in a triple of (your methods, the corresponding result, potential improvement), list them out.
|
||||
# Takeaways
|
||||
Second, carefully find key takeaways from your summarization in a step-by-step thinking process
|
||||
# Guidance
|
||||
Finally, make a concise one-sentence guidance for improving your future plan.
|
||||
Your response:
|
||||
Output a json following the format:
|
||||
```json
|
||||
{
|
||||
"summary": str = "summarize each of your previous trial in a triple of (your methods, the corresponding result, potential improvement), list them out",
|
||||
"takeaways": str = "carefully find key takeaways from your summarization in a step-by-step thinking process",
|
||||
"reflection": "in one sentence, state executable actions for improving your future plan",
|
||||
}
|
||||
```
|
||||
"""
|
||||
REWRITE_PLAN_INSTRUCTION = """When taking this reflection for rewriting plan, modify the current plan in place, replace, add, or delete tasks in the plan,
|
||||
only make necessary change to the current plan, keep reusable tasks unchanged, provide the complete new plan."""
|
||||
|
||||
async def run(self, context: str) -> str:
|
||||
user_requirement = "Score as high as possible in a data modeling competition"
|
||||
prompt = self.PROMPT_TEMPLATE.format(context=context, user_requirement=user_requirement)
|
||||
rsp = await self._aask(prompt)
|
||||
return rsp
|
||||
async def run(self, context: str, user_requirement: str = "") -> str:
|
||||
user_requirement = user_requirement or "Score as high as possible in a data modeling competition"
|
||||
# prompt = self.PROMPT_TEMPLATE.format(context=context, user_requirement=user_requirement)
|
||||
prompt = self.PROMPT_TEMPLATE.replace("__context__", context).replace("__user_requirement__", user_requirement)
|
||||
rsp_json = await self._aask(prompt)
|
||||
rsp = CodeParser.parse_code(block=None, text=rsp_json)
|
||||
reflection = json.loads(rsp)["reflection"]
|
||||
reflection += self.REWRITE_PLAN_INSTRUCTION
|
||||
return reflection
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue