Skip to content

Build and run agents you can see, understand and trust.

fix(stream_printing_messages): fix the bug in stream_printing_messages pipeline (#866)

DavdGao9d4cefaeba5f
diff --git a/src/agentscope/agent/_agent_base.py b/src/agentscope/agent/_agent_base.py
index 6a8481231..0ac03550d 100644
--- a/src/agentscope/agent/_agent_base.py
+++ b/src/agentscope/agent/_agent_base.py
@@ -5,6 +5,7 @@ import io
import json
from asyncio import Task, Queue
from collections import OrderedDict
+from copy import deepcopy
from typing import Callable, Any
import base64
import shortuuid
@@ -205,7 +206,7 @@ class AgentBase(StateModule, metaclass=_AgentMeta):
non-streaming message, this should always be `True`.
"""
if not self._disable_msg_queue:
- await self.msg_queue.put((msg, last))
+ await self.msg_queue.put((deepcopy(msg), last))
if self._disable_console_output:
return
diff --git a/src/agentscope/agent/_react_agent.py b/src/agentscope/agent/_react_agent.py
index 17ffc3134..39d8831f7 100644
--- a/src/agentscope/agent/_react_agent.py
+++ b/src/agentscope/agent/_react_agent.py
@@ -387,6 +387,10 @@ class ReActAgent(ReActAgentBase):
await self.print(msg, False)
await self.print(msg, True)
+ # Add a tiny sleep to yield the last message object in the
+ # message queue
+ await asyncio.sleep(0.001)
+
else:
msg = Msg(self.name, list(res.content), "assistant")
await self.print(msg, True)