Merge branch 'fixbug/tasktype_tools' into 'mgx_ops'

update the tools based on intention

See merge request pub/MetaGPT!34
This commit is contained in:
洪思睿 2024-04-10 09:23:10 +00:00
commit 04f9919f3e
4 changed files with 17 additions and 8 deletions

View file

@ -16,9 +16,7 @@ from metagpt.schema import Message, Plan, Task
from metagpt.strategy.task_type import TaskType
from metagpt.utils.common import CodeParser
class WritePlan(Action):
PROMPT_TEMPLATE: str = """
PROMPT_TEMPLATE: str = """
# Context:
{context}
# Available Task Types:
@ -39,11 +37,13 @@ Output a list of jsons following the format:
...
]
```
"""
"""
class WritePlan(Action):
async def run(self, context: list[Message], max_tasks: int = 5) -> str:
task_type_desc = "\n".join([f"- **{tt.type_name}**: {tt.value.desc}" for tt in TaskType])
prompt = self.PROMPT_TEMPLATE.format(
prompt = PROMPT_TEMPLATE.format(
context="\n".join([str(ct) for ct in context]), max_tasks=max_tasks, task_type_desc=task_type_desc
)
rsp = await self._aask(prompt)

View file

@ -4,10 +4,11 @@
import asyncio
from typing import Dict
from metagpt.actions.di.detect_intent import DetectIntent
from metagpt.actions.di.detect_intent import DetectIntent, SOPItem
from metagpt.logs import logger
from metagpt.roles.di.data_interpreter import DataInterpreter
from metagpt.schema import Message
from metagpt.tools.tool_recommend import BM25ToolRecommender
class MGX(DataInterpreter):
@ -18,6 +19,10 @@ class MGX(DataInterpreter):
todo = DetectIntent(context=self.context)
request_with_sop, sop_type = await todo.run(user_msg)
logger.info(f"{sop_type} {request_with_sop}")
if sop_type == SOPItem.SOFTWARE_DEVELOPMENT.type_name:
self.tool_recommender = BM25ToolRecommender(tools=["software development"])
else:
self.tool_recommender = BM25ToolRecommender(tools=["<all>"])
return request_with_sop
async def _plan_and_act(self) -> Message:

View file

@ -67,7 +67,10 @@ class TaskType(Enum):
name="email login",
desc="For logging to an email.",
)
DEVELOP_SOFTWARE = TaskTypeDef(name="develop software", desc="Develop software.")
DEVELOP_SOFTWARE = TaskTypeDef(
name="develop software",
desc="SOP related to develop software such as Writes a PRD, Writes a design, Writes a project plan and Writes code to implement designed features according to the project plan",
)
@property
def type_name(self):