mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-06-08 15:05:17 +02:00
将角色定义,角色instruction和工具加入开始的system_prompt中
This commit is contained in:
parent
fa06a67a64
commit
075a82e6f4
2 changed files with 42 additions and 19 deletions
|
|
@ -11,9 +11,14 @@ Note:
|
|||
5. Avoid repeating tasks you have already completed. And end loop when all requirements are met.
|
||||
"""
|
||||
# To ensure compatibility with hard-coded experience, do not add any other content between "# Example" and "# Instruction".
|
||||
CMD_PROMPT = """
|
||||
|
||||
####################
|
||||
# Latest Observation
|
||||
{latest_observation}
|
||||
# {latest_observation}
|
||||
|
||||
|
||||
###########################
|
||||
INSTRUCTION_GUIDANCE = """
|
||||
|
||||
# Data Structure
|
||||
class Task(BaseModel):
|
||||
|
|
@ -30,11 +35,6 @@ class Task(BaseModel):
|
|||
{available_commands}
|
||||
Special Command: Use {{"command_name": "end"}} to do nothing or indicate completion of all requirements and the end of actions.
|
||||
|
||||
# Current Plan
|
||||
{plan_status}
|
||||
|
||||
# Current Task
|
||||
{current_task}
|
||||
|
||||
# Example
|
||||
{example}
|
||||
|
|
@ -42,6 +42,22 @@ Special Command: Use {{"command_name": "end"}} to do nothing or indicate complet
|
|||
|
||||
# Instruction
|
||||
{instruction}
|
||||
"""
|
||||
|
||||
|
||||
# {thought_guidance}
|
||||
# Finally, combine your thoughts, describe what you want to do conscisely in 20 words, including which process you will taked and whether you will end, then follow your thoughts to list the commands, adhering closely to the instructions provided.
|
||||
|
||||
CMD_PROMPT = """
|
||||
# Current Plan
|
||||
{plan_status}
|
||||
|
||||
# Current Task
|
||||
{current_task}
|
||||
|
||||
# Restrictions
|
||||
{requirements_constraints}
|
||||
|
||||
|
||||
Pay close attention to the Example provided, you can reuse the example for your current situation if it fits.
|
||||
You may use any of the available commands to create a plan or update the plan. You may output mutiple commands, they will be executed sequentially.
|
||||
|
|
@ -49,14 +65,9 @@ If you finish current task, you will automatically take the next task in the exi
|
|||
Review the latest plan's outcome, focusing on achievements. If your completed task matches the current, consider it finished.
|
||||
In your response, include at least one command.
|
||||
|
||||
# Restrictions
|
||||
{requirements_constraints}
|
||||
|
||||
# Your commands in a json array, in the following output format with correct command_name and args. If there is nothing to do, use the pass or end command:
|
||||
Some text indicating your thoughts before JSON is required, such as what tasks have been completed, what tasks are next, how you should update the plan status, respond to inquiry, or seek for help. Then a json array of commands. You must output ONE and ONLY ONE json array. DON'T output multiple json arrays with thoughts between them.
|
||||
Output should adhere to the following format.
|
||||
{thought_guidance}
|
||||
Finally, combine your thoughts, describe what you want to do conscisely in 20 words, including which process you will taked and whether you will end, then follow your thoughts to list the commands, adhering closely to the instructions provided.
|
||||
```json
|
||||
[
|
||||
{{
|
||||
|
|
@ -68,6 +79,7 @@ Finally, combine your thoughts, describe what you want to do conscisely in 20 wo
|
|||
```
|
||||
Notice: your output JSON data section must start with **```json [**
|
||||
"""
|
||||
|
||||
THOUGHT_GUIDANCE = """
|
||||
First, describe the actions you have taken recently.
|
||||
Second, describe the messages you have received recently, with a particular emphasis on messages from users. If necessary, develop a plan to address the new user requirements.
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ from metagpt.logs import logger
|
|||
from metagpt.prompts.di.role_zero import (
|
||||
ASK_HUMAN_COMMAND,
|
||||
CMD_PROMPT,
|
||||
INSTRUCTION_GUIDANCE,
|
||||
JSON_REPAIR_PROMPT,
|
||||
QUICK_THINK_PROMPT,
|
||||
REGENERATE_PROMPT,
|
||||
|
|
@ -47,6 +48,7 @@ class RoleZero(Role):
|
|||
profile: str = "RoleZero"
|
||||
goal: str = ""
|
||||
system_msg: list[str] = None # Use None to conform to the default value at llm.aask
|
||||
instruction_system_prpomt: str = INSTRUCTION_GUIDANCE
|
||||
cmd_prompt: str = CMD_PROMPT
|
||||
thought_guidance: str = THOUGHT_GUIDANCE
|
||||
instruction: str = ROLE_INSTRUCTION
|
||||
|
|
@ -152,18 +154,25 @@ class RoleZero(Role):
|
|||
tools = await self.tool_recommender.recommend_tools()
|
||||
tool_info = json.dumps({tool.name: tool.schemas for tool in tools})
|
||||
|
||||
### Make Decision Dynamically ###
|
||||
memory = self.rc.memory.get(self.memory_k)
|
||||
instruction = self.instruction.strip()
|
||||
prompt = self.cmd_prompt.format(
|
||||
instruction_system_prpomt = self.instruction_system_prpomt.format(
|
||||
example=example,
|
||||
available_commands=tool_info,
|
||||
instruction=instruction,
|
||||
task_type_desc=self.task_type_desc,
|
||||
)
|
||||
guidance_system_msgs = [instruction_system_prpomt]
|
||||
if self.system_msg:
|
||||
guidance_system_msgs = self.system_msg + guidance_system_msgs
|
||||
|
||||
# print(("\n"+"="*10+"\n").join(guidance_system_msgs))
|
||||
### Make Decision Dynamically ###
|
||||
memory = self.rc.memory.get(self.memory_k)
|
||||
prompt = self.cmd_prompt.format(
|
||||
plan_status=plan_status,
|
||||
current_task=current_task,
|
||||
instruction=instruction,
|
||||
thought_guidance=self.thought_guidance,
|
||||
latest_observation=memory[-1].content,
|
||||
# thought_guidance=self.thought_guidance,
|
||||
# latest_observation=memory[-1].content,
|
||||
requirements_constraints=self.requirements_constraints,
|
||||
)
|
||||
memory = await self.parse_browser_actions(memory)
|
||||
|
|
@ -175,7 +184,9 @@ class RoleZero(Role):
|
|||
current_task=current_task,
|
||||
instruction=instruction,
|
||||
)
|
||||
self.command_rsp = await self.llm_cached_aask(req=req, system_msgs=self.system_msg, state_data=state_data)
|
||||
self.command_rsp = await self.llm_cached_aask(
|
||||
req=req, system_msgs=guidance_system_msgs, state_data=state_data
|
||||
)
|
||||
|
||||
self.command_rsp = await self._check_duplicates(req, self.command_rsp)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue