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

This commit is contained in:
莘权 马 2024-04-30 12:24:30 +08:00
parent db34c6f458
commit e37aa8e5bf
2 changed files with 4 additions and 1 deletions

View file

@ -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)

View file

@ -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: