mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-06-05 14:55:18 +02:00
disentangle planner and tool module, optimize tool module, add react mode
This commit is contained in:
parent
0a2273c7a0
commit
0116de01b9
20 changed files with 554 additions and 354 deletions
|
|
@ -13,6 +13,8 @@ from metagpt.actions.mi.write_plan import (
|
|||
from metagpt.logs import logger
|
||||
from metagpt.memory import Memory
|
||||
from metagpt.schema import Message, Plan, Task, TaskResult
|
||||
from metagpt.strategy.task_type import TaskType
|
||||
from metagpt.utils.common import remove_comments
|
||||
|
||||
STRUCTURAL_CONTEXT = """
|
||||
## User Requirement
|
||||
|
|
@ -25,6 +27,24 @@ STRUCTURAL_CONTEXT = """
|
|||
{current_task}
|
||||
"""
|
||||
|
||||
PLAN_STATUS = """
|
||||
## Finished Tasks
|
||||
### code
|
||||
```python
|
||||
{code_written}
|
||||
```
|
||||
|
||||
### execution result
|
||||
{task_results}
|
||||
|
||||
## Current Task
|
||||
{current_task}
|
||||
|
||||
## Task Guidance
|
||||
Write complete code for 'Current Task'. And avoid duplicating code from 'Finished Tasks', such as repeated import of packages, reading data, etc.
|
||||
Specifically, {guidance}
|
||||
"""
|
||||
|
||||
|
||||
class Planner(BaseModel):
|
||||
plan: Plan
|
||||
|
|
@ -136,3 +156,23 @@ class Planner(BaseModel):
|
|||
context_msg = [Message(content=context, role="user")]
|
||||
|
||||
return context_msg + self.working_memory.get()
|
||||
|
||||
def get_plan_status(self) -> str:
|
||||
# prepare components of a plan status
|
||||
finished_tasks = self.plan.get_finished_tasks()
|
||||
code_written = [remove_comments(task.code) for task in finished_tasks]
|
||||
code_written = "\n\n".join(code_written)
|
||||
task_results = [task.result for task in finished_tasks]
|
||||
task_results = "\n\n".join(task_results)
|
||||
task_type_name = self.current_task.task_type.upper()
|
||||
guidance = TaskType[task_type_name].value.guidance if hasattr(TaskType, task_type_name) else ""
|
||||
|
||||
# combine components in a prompt
|
||||
prompt = PLAN_STATUS.format(
|
||||
code_written=code_written,
|
||||
task_results=task_results,
|
||||
current_task=self.current_task.instruction,
|
||||
guidance=guidance,
|
||||
)
|
||||
|
||||
return prompt
|
||||
|
|
|
|||
57
metagpt/strategy/task_type.py
Normal file
57
metagpt/strategy/task_type.py
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
from enum import Enum
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
from metagpt.prompts.task_type import (
|
||||
DATA_PREPROCESS_PROMPT,
|
||||
EDA_PROMPT,
|
||||
FEATURE_ENGINEERING_PROMPT,
|
||||
IMAGE2WEBPAGE_PROMPT,
|
||||
MODEL_EVALUATE_PROMPT,
|
||||
MODEL_TRAIN_PROMPT,
|
||||
)
|
||||
|
||||
|
||||
class TaskTypeDef(BaseModel):
|
||||
name: str
|
||||
desc: str = ""
|
||||
guidance: str = ""
|
||||
|
||||
|
||||
class TaskType(Enum):
|
||||
EDA = TaskTypeDef(
|
||||
name="eda",
|
||||
desc="For performing exploratory data analysis",
|
||||
guidance=EDA_PROMPT,
|
||||
)
|
||||
DATA_PREPROCESS = TaskTypeDef(
|
||||
name="data_preprocess",
|
||||
desc="For preprocessing dataset in a data analysis or machine learning task ONLY,"
|
||||
"general data operation doesn't fall into this type",
|
||||
guidance=DATA_PREPROCESS_PROMPT,
|
||||
)
|
||||
FEATURE_ENGINEERING = TaskTypeDef(
|
||||
name="feature_engineering",
|
||||
desc="Only for creating new columns for input data.",
|
||||
guidance=FEATURE_ENGINEERING_PROMPT,
|
||||
)
|
||||
MODEL_TRAIN = TaskTypeDef(
|
||||
name="model_train",
|
||||
desc="Only for training model.",
|
||||
guidance=MODEL_TRAIN_PROMPT,
|
||||
)
|
||||
MODEL_EVALUATE = TaskTypeDef(
|
||||
name="model_evaluate",
|
||||
desc="Only for evaluating model.",
|
||||
guidance=MODEL_EVALUATE_PROMPT,
|
||||
)
|
||||
IMAGE2WEBPAGE = TaskTypeDef(
|
||||
name="image2webpage",
|
||||
desc="For converting image into webpage code.",
|
||||
guidance=IMAGE2WEBPAGE_PROMPT,
|
||||
)
|
||||
OTHER = TaskTypeDef(name="other", desc="Any tasks not in the defined categories")
|
||||
|
||||
@property
|
||||
def type_name(self):
|
||||
return self.value.name
|
||||
Loading…
Add table
Add a link
Reference in a new issue