Skip to content

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

Fix the bug use stream_printing_messages will print the generate_response tool_use message (#831)

Young198902224e8a3097e3
diff --git a/src/agentscope/agent/_react_agent.py b/src/agentscope/agent/_react_agent.py
index 8f44dd798..17ffc3134 100644
--- a/src/agentscope/agent/_react_agent.py
+++ b/src/agentscope/agent/_react_agent.py
@@ -391,8 +391,6 @@ class ReActAgent(ReActAgentBase):
msg = Msg(self.name, list(res.content), "assistant")
await self.print(msg, True)
- return msg
-
except asyncio.CancelledError as e:
interrupted_by_user = True
raise e from None
@@ -401,6 +399,7 @@ class ReActAgent(ReActAgentBase):
if msg and not msg.has_content_blocks("tool_use"):
# Turn plain text response into a tool call of the finish
# function
+ msg = Msg.from_dict(msg.to_dict())
msg.content = [
ToolUseBlock(
id=shortuuid.uuid(),
@@ -435,6 +434,7 @@ class ReActAgent(ReActAgentBase):
)
await self.memory.add(msg_res)
await self.print(msg_res, True)
+ return msg
async def _acting(self, tool_call: ToolUseBlock) -> Msg | None:
"""Perform the acting process.
diff --git a/tests/token_huggingface_test.py b/tests/token_huggingface_test.py
deleted file mode 100644
index 3fcf60625..000000000
--- a/tests/token_huggingface_test.py
+++ /dev/null
@@ -1,33 +0,0 @@
-# -*- coding: utf-8 -*-
-"""The unittests for huggingface token counter."""
-from unittest.async_case import IsolatedAsyncioTestCase
-
-from agentscope.token import HuggingFaceTokenCounter
-
-
-class TokenCounterTest(IsolatedAsyncioTestCase):
- """The unittests for the HuggingFace token counter."""
-
- async def asyncSetUp(self) -> None:
- """Set up the test case."""
- self.common_messages = [
- {"role": "user", "content": "Hi!"},
- {"role": "assistant", "content": "Hi! How can I help you today?"},
- {"role": "user", "content": "What is the capital of France?"},
- {
- "role": "assistant",
- "content": "The capital of France is Paris.",
- },
- ]
-
- async def test_huggingface_token_counter(self) -> None:
- """Test the HuggingFace token counter."""
- counter = HuggingFaceTokenCounter(
- pretrained_model_name_or_path="Qwen/Qwen3-8B",
- use_mirror=False,
- )
-
- res = await counter.count(
- self.common_messages,
- )
- self.assertEqual(res, 49)