mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-05-21 14:05:17 +02:00
将quick think prompt改为system prompt,减少request离结尾的距离
This commit is contained in:
parent
5b3f84e597
commit
b8f05f5827
4 changed files with 43 additions and 24 deletions
|
|
@ -125,32 +125,45 @@ If no issues are detected, the original json data should be returned unchanged.
|
|||
Output the JSON data in a format that can be loaded by the json.loads() function.
|
||||
"""
|
||||
|
||||
QUICK_THINK_PROMPT = """
|
||||
QUICK_THINK_SYSTEM_PROMPT = """
|
||||
Your role is to determine the appropriate response category for the given request.
|
||||
|
||||
# Response Categories
|
||||
## QUICK:
|
||||
For straightforward questions or requests that can be answered directly. This includes common-sense inquiries, legal or logical questions, basic math, short coding tasks, multiple-choice questions, greetings, casual chat, and inquiries about you or your team.
|
||||
For straightforward questions or requests that can be answered directly. This includes common-sense inquiries, legal or logical questions, basic math, short coding tasks, multiple-choice questions, greetings, casual chat, schedule planning, and inquiries about you or your team.
|
||||
|
||||
## SEARCH
|
||||
For queries that require retrieving up-to-date or detailed information. This includes time-sensitive or location-specific questions like current events or weather. Use this only if the information isn't readily available.
|
||||
|
||||
## TASK
|
||||
For complex requests that involve multiple steps or detailed instructions. Examples include software development, project planning, or any task that requires a sequence of actions.
|
||||
For complex requests that involve tool utilizations, multiple steps or detailed instructions. Examples include software development, project planning, or any task that requires tool usage.
|
||||
|
||||
## AMBIGUOUS
|
||||
For requests that are unclear, lack sufficient detail, or are outside the system's capabilities. Common characteristics of AMBIGUOUS requests:
|
||||
|
||||
- Incomplete Information: Requests that imply complex tasks but lack critical details (e.g., "Redesign this logo" without providing the original logo or specifying design requirements).
|
||||
- Incomplete Information: Requests that imply complex tasks but lack critical details (e.g., "Redesign this logo" without specifying design requirements).
|
||||
- Vagueness: Broad, unspecified, or unclear requests that make it difficult to provide a precise answer.
|
||||
- Out of Expertise: Requests for specialized advice (e.g., medical or legal advice) or highly technical tasks beyond the model's scope.
|
||||
- Unrealistic Scope: Overly broad requests that are impossible to address meaningfully in a single response (e.g., "Tell me everything about...").
|
||||
- Missing files: Requests that refer to specific documents, images, or data without providing them for reference. (when providing a file, website, or data, either the content, link, or path **must** be included)
|
||||
|
||||
**Note:** Before categorizing a request as TASK, consider whether the user has provided sufficient information to proceed with the task. If the request is complex but lacks essential details or the mentioned files, it should fall under AMBIGUOUS.
|
||||
**Note:** Before categorizing a request as TASK:
|
||||
1. Consider whether the user has provided sufficient information to proceed with the task. If the request is complex but lacks essential details or the mentioned files' content or path, it should fall under AMBIGUOUS.
|
||||
2. If the request is a "how-to" question that asks for a general approach or strategy, it should be categorized as QUICK.
|
||||
3. Writing a travel/learning plan or providing a general outline should be categorized as **QUICK* because it doesn't involve detailed instructions or tool usage.
|
||||
|
||||
{examples}
|
||||
"""
|
||||
|
||||
QUICK_THINK_PROMPT = """
|
||||
# Instruction
|
||||
Determine the previous message's intent.
|
||||
Respond with a concise thought, then provide the appropriate response category: QUICK, SEARCH, TASK, or AMBIGUOUS.
|
||||
Important: You should **only** provide the thought, response category, and nothing else.
|
||||
Your response:
|
||||
|
||||
# Format
|
||||
Thought: [Your thought here]
|
||||
Response Category: [QUICK/SEARCH/TASK/AMBIGUOUS]
|
||||
|
||||
# Response:
|
||||
"""
|
||||
|
||||
|
||||
|
|
@ -166,7 +179,7 @@ Thought: This is a general knowledge question that can be answered concisely.
|
|||
Response Category: QUICK.
|
||||
|
||||
3. Request: "Can you help me plan a healthy diet for a week?"
|
||||
Thought: The user is requesting a simple plan that can be provided immediately.
|
||||
Thought: Writing a diet plan is a general task that can be answered directly.
|
||||
Response Category: QUICK.
|
||||
|
||||
4. Request: "Can you help me find the latest research papers on deep learning?"
|
||||
|
|
@ -178,18 +191,16 @@ Thought: This is a detailed software development task that requires multiple ste
|
|||
Response Category: TASK.
|
||||
|
||||
6. Request: "Summarize this document for me."
|
||||
Thought: The request mentions summarizing a document but doesn't provide the document itself, making it impossible to fulfill.
|
||||
Thought: The request mentions summarizing a document but doesn't provide the path or content of the document, making it impossible to fulfill.
|
||||
Response Category: AMBIGUOUS.
|
||||
|
||||
7. Request: "Optimize this process."
|
||||
7. Request: "Summarize this document for me '/data/path/docmument.pdf'."
|
||||
Thought: The request mentions summarizing a document and has provided the path to the document. It can be done by reading the document using a tool then summarizing it.
|
||||
Response Category: TASK.
|
||||
|
||||
8. Request: "Optimize this process."
|
||||
Thought: The request is vague and lacks specifics, requiring clarification on the process to optimize.
|
||||
Response Category: AMBIGUOUS.
|
||||
|
||||
8. Request: "Create a poster for our upcoming event."
|
||||
Thought: Critical details like event theme, date, and location are missing, making it impossible to complete the task.
|
||||
Response Category: AMBIGUOUS.
|
||||
|
||||
# Instruction
|
||||
"""
|
||||
|
||||
QUICK_THINK_PROMPT = QUICK_THINK_PROMPT.format(examples=QUICK_THINK_EXAMPLES)
|
||||
# QUICK_THINK_EXAMPLES = ""
|
||||
|
|
@ -30,7 +30,7 @@ class DataAnalyst(RoleZero):
|
|||
instruction: str = ROLE_INSTRUCTION + EXTRA_INSTRUCTION
|
||||
task_type_desc: str = TASK_TYPE_DESC
|
||||
|
||||
tools: list[str] = ["Plan", "DataAnalyst", "RoleZero", "Browser"]
|
||||
tools: list[str] = ["Plan", "DataAnalyst", "RoleZero", "Browser", "Editor:write,read"]
|
||||
custom_tools: list[str] = ["web scraping", "Terminal"]
|
||||
custom_tool_recommender: ToolRecommender = None
|
||||
experience_retriever: Annotated[ExpRetriever, Field(exclude=True)] = KeywordExpRetriever()
|
||||
|
|
|
|||
|
|
@ -21,6 +21,8 @@ from metagpt.prompts.di.role_zero import (
|
|||
CMD_PROMPT,
|
||||
JSON_REPAIR_PROMPT,
|
||||
QUICK_THINK_PROMPT,
|
||||
QUICK_THINK_EXAMPLES,
|
||||
QUICK_THINK_SYSTEM_PROMPT,
|
||||
REGENERATE_PROMPT,
|
||||
ROLE_INSTRUCTION,
|
||||
SYSTEM_PROMPT,
|
||||
|
|
@ -249,6 +251,10 @@ class RoleZero(Role):
|
|||
rsp = await self._act()
|
||||
actions_taken += 1
|
||||
return rsp # return output from the last action
|
||||
|
||||
def format_quick_system_prompt(self) -> str:
|
||||
"""Format the system prompt for quick thinking."""
|
||||
return QUICK_THINK_SYSTEM_PROMPT.format(examples=QUICK_THINK_EXAMPLES)
|
||||
|
||||
async def _quick_think(self) -> Tuple[Message, str]:
|
||||
answer = ""
|
||||
|
|
@ -260,7 +266,7 @@ class RoleZero(Role):
|
|||
# routing
|
||||
memory = self.get_memories(k=4) # FIXME: A magic number for two rounds of Q&A
|
||||
context = self.llm.format_msg(memory + [UserMessage(content=QUICK_THINK_PROMPT)])
|
||||
intent_result = await self.llm.aask(context)
|
||||
intent_result = await self.llm.aask(context, system_msgs=self.format_quick_system_prompt())
|
||||
|
||||
if "QUICK" in intent_result or "AMBIGUOUS " in intent_result: # llm call with the original context
|
||||
async with ThoughtReporter(enable_llm_stream=True) as reporter:
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ class TeamLeader(RoleZero):
|
|||
# TeamLeader only reacts once each time, but may encounter errors or need to ask human, thus allowing 2 more turns
|
||||
max_react_loop: int = 3
|
||||
|
||||
tools: list[str] = ["Plan", "RoleZero", "TeamLeader"]
|
||||
tools: list[str] = ["Plan", "RoleZero", "TeamLeader", "Editor:write,read"]
|
||||
|
||||
experience_retriever: Annotated[ExpRetriever, Field(exclude=True)] = SimpleExpRetriever()
|
||||
|
||||
|
|
@ -48,12 +48,14 @@ class TeamLeader(RoleZero):
|
|||
team_info += f"{role.name}: {role.profile}, {role.goal}\n"
|
||||
return team_info
|
||||
|
||||
async def _quick_think(self) -> Message:
|
||||
# insert team info for quick question
|
||||
self.llm.system_prompt = QUICK_THINK_SYSTEM_PROMPT.format(
|
||||
def format_quick_system_prompt(self) -> str:
|
||||
qt_system_prompt = super().format_quick_system_prompt()
|
||||
return qt_system_prompt + QUICK_THINK_SYSTEM_PROMPT.format(
|
||||
role_info=super()._get_prefix(),
|
||||
team_info=self._get_team_info(),
|
||||
)
|
||||
|
||||
async def _quick_think(self) -> Message:
|
||||
return await super()._quick_think()
|
||||
|
||||
async def _think(self) -> bool:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue