Skip to content

🌟 The Multi-Agent Framework: First AI Software Company, Towards Natural Language Programming

feat: remove Context.options

莘权 马b858cc7d83cf
diff --git a/metagpt/actions/write_teaching_plan.py b/metagpt/actions/write_teaching_plan.py
index 834f07006..c5f70ae05 100644
--- a/metagpt/actions/write_teaching_plan.py
+++ b/metagpt/actions/write_teaching_plan.py
@@ -8,6 +8,7 @@
from typing import Optional
from metagpt.actions import Action
+from metagpt.context import Context
from metagpt.logs import logger
@@ -23,7 +24,7 @@ class WriteTeachingPlanPart(Action):
statement_patterns = TeachingPlanBlock.TOPIC_STATEMENTS.get(self.topic, [])
statements = []
for p in statement_patterns:
- s = self.format_value(p, options=self.context.options)
+ s = self.format_value(p, context=self.context)
statements.append(s)
formatter = (
TeachingPlanBlock.PROMPT_TITLE_TEMPLATE
@@ -67,13 +68,16 @@ class WriteTeachingPlanPart(Action):
return self.topic
@staticmethod
- def format_value(value, options):
+ def format_value(value, context: Context):
"""Fill parameters inside `value` with `options`."""
if not isinstance(value, str):
return value
if "{" not in value:
return value
+ options = context.config.model_dump()
+ for k, v in context.kwargs:
+ options[k] = v # None value is allowed to override and disable the value from config.
opts = {k: v for k, v in options.items() if v is not None}
try:
return value.format(**opts)
diff --git a/metagpt/context.py b/metagpt/context.py
index 75dc31ef2..1e0d91237 100644
--- a/metagpt/context.py
+++ b/metagpt/context.py
@@ -64,14 +64,6 @@ class Context(BaseModel):
_llm: Optional[BaseLLM] = None
- @property
- def options(self):
- """Return all key-values"""
- opts = self.config.model_dump()
- for k, v in self.kwargs:
- opts[k] = v # None value is allowed to override and disable the value from config.
- return opts
-
def new_environ(self):
"""Return a new os.environ object"""
env = os.environ.copy()
diff --git a/metagpt/roles/teacher.py b/metagpt/roles/teacher.py
index a40ba69fe..d6715dcd1 100644
--- a/metagpt/roles/teacher.py
+++ b/metagpt/roles/teacher.py
@@ -31,11 +31,11 @@ class Teacher(Role):
def __init__(self, **kwargs):
super().__init__(**kwargs)
- self.name = WriteTeachingPlanPart.format_value(self.name, self.context.options)
- self.profile = WriteTeachingPlanPart.format_value(self.profile, self.context.options)
- self.goal = WriteTeachingPlanPart.format_value(self.goal, self.context.options)
- self.constraints = WriteTeachingPlanPart.format_value(self.constraints, self.context.options)
- self.desc = WriteTeachingPlanPart.format_value(self.desc, self.context.options)
+ self.name = WriteTeachingPlanPart.format_value(self.name, self.context)
+ self.profile = WriteTeachingPlanPart.format_value(self.profile, self.context)
+ self.goal = WriteTeachingPlanPart.format_value(self.goal, self.context)
+ self.constraints = WriteTeachingPlanPart.format_value(self.constraints, self.context)
+ self.desc = WriteTeachingPlanPart.format_value(self.desc, self.context)
async def _think(self) -> bool:
"""Everything will be done part by part."""