mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-06-11 15:15:18 +02:00
Merge branch 'feat-intention-fs' into 'mgx_ops'
quick_think prompt增加few-shot examples,将意图分为QUICK, SEARCH, TASK, AMBIGUOUS See merge request pub/MetaGPT!292
This commit is contained in:
commit
f84fe76d28
2 changed files with 67 additions and 12 deletions
|
|
@ -126,11 +126,68 @@ Output the JSON data in a format that can be loaded by the json.loads() function
|
|||
"""
|
||||
|
||||
QUICK_THINK_PROMPT = """
|
||||
Decide if the latest user message previously is a quick question.
|
||||
Quick questions include common-sense, legal, logical, math, multiple-choice questions, greetings, or casual chat that you can answer directly.
|
||||
Questions about you or your team info are also quick questions.
|
||||
Time- or location-sensitive questions such as wheather or news inquiry are NOT quick questions. Moreover, you should output a keyword SEARCH to indicate the need for a google search.
|
||||
Software development tasks are NOT quick questions. Code execution, however trivial, is NOT a quick question.
|
||||
However, these programming-related tasks are quick questions: writing trivial code snippets (fewer than 30 lines), filling a single function or class, explaining concepts, writing tutorials and documentation.
|
||||
Respond with a concise thought then a YES if the question is a quick question, otherwise, a NO or a SEARCH. Your response:
|
||||
# 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.
|
||||
|
||||
## 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.
|
||||
|
||||
## 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).
|
||||
- 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...").
|
||||
|
||||
**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.
|
||||
|
||||
{examples}
|
||||
|
||||
Respond with a concise thought, then provide the appropriate response category: QUICK, SEARCH, TASK, or AMBIGUOUS. Your response:
|
||||
"""
|
||||
|
||||
|
||||
QUICK_THINK_EXAMPLES ="""
|
||||
# Example
|
||||
|
||||
1. Request: "How do I design an online document editing platform that supports real-time collaboration?"
|
||||
Thought: This is a direct query about platform design, answerable without additional resources.
|
||||
Response Category: QUICK.
|
||||
|
||||
2. Request: "What's the difference between supervised and unsupervised learning in machine learning?"
|
||||
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.
|
||||
Response Category: QUICK.
|
||||
|
||||
4. Request: "Can you help me find the latest research papers on deep learning?"
|
||||
Thought: The user needs current research, requiring a search for the most recent sources.
|
||||
Response Category: SEARCH.
|
||||
|
||||
5. Request: "Build a personal website that runs the Game of Life simulation."
|
||||
Thought: This is a detailed software development task that requires multiple steps.
|
||||
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.
|
||||
Response Category: AMBIGUOUS.
|
||||
|
||||
7. 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)
|
||||
|
|
@ -129,7 +129,7 @@ class RoleZero(Role):
|
|||
|
||||
def _update_tool_execution(self):
|
||||
pass
|
||||
|
||||
|
||||
async def _think(self) -> bool:
|
||||
"""Useful in 'react' mode. Use LLM to decide whether and what to do next."""
|
||||
# Compatibility
|
||||
|
|
@ -194,9 +194,8 @@ class RoleZero(Role):
|
|||
The `RoleZeroContextBuilder` attempts to add experiences to `req`.
|
||||
The `RoleZeroSerializer` extracts essential parts of `req` for the experience pool, trimming lengthy entries to retain only necessary parts.
|
||||
"""
|
||||
|
||||
return await self.llm.aask(req, system_msgs=system_msgs)
|
||||
|
||||
|
||||
async def parse_browser_actions(self, memory: List[Message]) -> List[Message]:
|
||||
if not self.browser.is_empty_page:
|
||||
pattern = re.compile(r"Command Browser\.(\w+) executed")
|
||||
|
|
@ -262,8 +261,7 @@ class RoleZero(Role):
|
|||
context = self.llm.format_msg(memory + [UserMessage(content=QUICK_THINK_PROMPT)])
|
||||
intent_result = await self.llm.aask(context)
|
||||
|
||||
if "YES" in intent_result:
|
||||
# llm call with the original context
|
||||
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:
|
||||
await reporter.async_report({"type": "quick"})
|
||||
answer = await self.llm.aask(self.llm.format_msg(memory))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue