Skip to content

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

feat: add metadata {"agent":xx} to assistant message

莘权 马e37aa8e5bf81
diff --git a/metagpt/roles/role.py b/metagpt/roles/role.py
index f3bf91dfa..210155e00 100644
--- a/metagpt/roles/role.py
+++ b/metagpt/roles/role.py
@@ -407,8 +407,10 @@ class Role(SerializationMixin, ContextMixin, BaseModel):
)
elif isinstance(response, Message):
msg = response
+ elif isinstance(response, AIMessage):
+ msg = response.with_agent(self._setting)
else:
- msg = AIMessage(content=response, cause_by=self.rc.todo, sent_from=self)
+ msg = AIMessage(content=response, cause_by=self.rc.todo, sent_from=self).with_agent(self._setting)
if self.enable_memory:
self.rc.memory.add(msg)
diff --git a/metagpt/schema.py b/metagpt/schema.py
index b3600ec98..847147c30 100644
--- a/metagpt/schema.py
+++ b/metagpt/schema.py
@@ -378,6 +378,7 @@ class AIMessage(Message):
def with_agent(self, name: str):
self.add_metadata(key=AGENT, value=name)
+ return self
@property
def agent(self) -> str: