agentscope icon indicating copy to clipboard operation
agentscope copied to clipboard

[Bug]: 400 Client Error: Bad Request for url: http://localhost:3000/trpc/pushMessage

Open codebuildforyou opened this issue 3 months ago • 7 comments

发生异常: HTTPError 400 Client Error: Bad Request for url: http://localhost:3000/trpc/pushMessage File "D:\XXX\files\agent_files\agentscope\src\agentscope\hooks_studio_hooks.py", line 47, in as_studio_forward_message_pre_print_hook raise e from None File "D:\XXX\files\agent_files\agentscope\src\agentscope\hooks_studio_hooks.py", line 47, in as_studio_forward_message_pre_print_hook raise e from None File "D:\XXX\files\agent_files\agentscope\src\agentscope_utils_common.py", line 103, in _execute_async_or_sync_func return func(*args, **kwargs) File "D:\XXX\files\agent_files\agentscope\src\agentscope\agent_agent_meta.py", line 98, in async_wrapper pre_hook,

...<3 lines>...
    deepcopy(current_normalized_kwargs),

File "D:\XXX\files\agent_files\agentscope\src\agentscope\agent_react_agent.py", line 311, in _reasoning await self.print(msg, False) File "D:\XXX\files\agent_files\agentscope\src\agentscope\agent_agent_meta.py", line 120, in async_wrapper self,

...<4 lines>...

File "D:\XXX\files\agent_files\agentscope\src\agentscope\agent_react_agent.py", line 246, in reply msg_reasoning = await self._reasoning() ^^^^^^^^^^^^^^^^^^^^^^^ File "D:\XXX\files\agent_files\agentscope\src\agentscope\tracing_trace.py", line 442, in wrapper raise e from None File "D:\XXX\files\agent_files\agentscope\src\agentscope\tracing_trace.py", line 442, in wrapper raise e from None File "D:\XXX\files\agent_files\agentscope\src\agentscope\agent_agent_meta.py", line 120, in async_wrapper self,

...<4 lines>...

File "D:\XXX\files\agent_files\agentscope\src\agentscope\agent_agent_base.py", line 235, in call reply_msg = await self.reply(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\XXX\files\agent_files\2025-10.08-ScopeDemo\scope_deepseek_mcp_demo.py", line 74, in main msg = await agent(msg) ^^^^^^^^^^^^^^^^ File "D:\XXX\files\agent_files\2025-10.08-ScopeDemo\scope_deepseek_mcp_demo.py", line 82, in asyncio.run(main()) ~~~~~~~~~~~^^^^^^^^ requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: http://localhost:3000/trpc/pushMessage

codebuildforyou avatar Oct 09 '25 12:10 codebuildforyou

Please provide the specific version of agentscope and agentscope-studio

DavdGao avatar Oct 12 '25 02:10 DavdGao

Please provide the specific version of agentscope and agentscope-studio

same issue, agentscope==1.0.5,@agentscope/[email protected]

mikck avatar Oct 13 '25 08:10 mikck

This issue is marked as stale because there has been no activity for 21 days. Remove stale label or add new comments or this issue will be closed in 3 day.

github-actions[bot] avatar Nov 03 '25 09:11 github-actions[bot]

Close this stale issue.

github-actions[bot] avatar Nov 07 '25 09:11 github-actions[bot]

我遇到了同样的问题。

运行的代码如下:

from agentscope.agent import ReActAgent, UserAgent
from agentscope.model import DashScopeChatModel, OpenAIChatModel
from agentscope.formatter import DashScopeChatFormatter, OpenAIChatFormatter, DeepSeekChatFormatter
from agentscope.memory import InMemoryMemory
from agentscope.tool import Toolkit, execute_python_code, execute_shell_command
import os, asyncio

import agentscope

agentscope.init(studio_url="http://localhost:3000")

async def main():
    toolkit = Toolkit()
    toolkit.register_tool_function(execute_python_code)
    toolkit.register_tool_function(execute_shell_command)

    agent = ReActAgent( # react agent来解决问题
        name="Friday",
        sys_prompt="You're a helpful assistant named Friday.",
        model=OpenAIChatModel(
            model_name="deepseek-chat",
            api_key=os.environ["DEEPSEEK_API_KEY"],
            stream=True,
            client_args={
                "base_url": "https://api.deepseek.com/v1",
            },
        ),
        memory=InMemoryMemory(),
        formatter=DeepSeekChatFormatter(),
        toolkit=toolkit,
    )

    user = UserAgent(name="user")

    msg = None
    while True:
        msg = await agent(msg)
        msg = await user(msg)
        if msg.get_text_content() == "exit":
            break

asyncio.run(main())

agentscope的版本:

1.0.8.dev0

报错的流程为:

  1. 运行agentscope studio
  2. 执行以上代码
  3. 在不调用工具时,studio正常输出。如下图:
Image
  1. 在studio的输入框输入:帮我写一个shell命令行输出hello world!
  2. studio在生成工具调用过程中,后台报错信息如下:
Friday: I'll help you with Python code execution or shell commands. What would you like me to do?
user: 帮我写一个shell命令行输出hello world!
Friday: 我来帮你写一个输出"hello world"的shell命令:Traceback (most recent call last):
  File "xxx/agentscope/examples/test_code/chat_friday.py", line 42, in <module>
    asyncio.run(main())
  File "xxx/miniconda3/envs/agentscope/lib/python3.10/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "xxx/miniconda3/envs/agentscope/lib/python3.10/asyncio/base_events.py", line 641, in run_until_complete
    return future.result()
  File "xxx/agentscope/examples/test_code/chat_friday.py", line 37, in main
    msg = await agent(msg)
  File "xxx/agentscope/src/agentscope/agent/_agent_base.py", line 422, in __call__
    reply_msg = await self.reply(*args, **kwargs)
  File "xxx/agentscope/src/agentscope/agent/_agent_meta.py", line 120, in async_wrapper
    current_output = await original_func(
  File "xxx/agentscope/src/agentscope/tracing/_trace.py", line 442, in wrapper
    raise e from None
  File "xxx/agentscope/src/agentscope/tracing/_trace.py", line 425, in wrapper
    res = await func(self, *args, **kwargs)
  File "xxx/agentscope/src/agentscope/agent/_react_agent.py", line 294, in reply
    msg_reasoning = await self._reasoning(tool_choice)
  File "xxx/agentscope/src/agentscope/agent/_agent_meta.py", line 120, in async_wrapper
    current_output = await original_func(
  File "xxx/agentscope/src/agentscope/agent/_react_agent.py", line 427, in _reasoning
    await self.print(msg, False)
  File "xxx/agentscope/src/agentscope/agent/_agent_meta.py", line 98, in async_wrapper
    modified_keywords = await _execute_async_or_sync_func(
  File "xxx/agentscope/src/agentscope/_utils/_common.py", line 106, in _execute_async_or_sync_func
    return func(*args, **kwargs)
  File "xxx/agentscope/src/agentscope/hooks/_studio_hooks.py", line 49, in as_studio_forward_message_pre_print_hook
    raise e from None
  File "xxx/agentscope/src/agentscope/hooks/_studio_hooks.py", line 42, in as_studio_forward_message_pre_print_hook
    res.raise_for_status()
  File "xxx/miniconda3/envs/agentscope/lib/python3.10/site-packages/requests/models.py", line 1026, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: http://localhost:3000/trpc/pushMessage
  1. studio显示看起来正常,实际工具参数是不对的:
Image

liweizhen111 avatar Nov 20 '25 06:11 liweizhen111

主要问题发生在当大模型流式返回工具调用的时候,会得到比如 '{"command'这样的字符串,但是,这个字符串经过_json_loads_with_repair函数里的repair_json之后,得到的是一个list ["command"],所以导致出错。一个解法是在_json_loads_with_repair这里做一下类型判断,因为当前agentscope里用到这个函数的地方期望得到的都是dict,所以可以先判断json.loads(repaired)的结果,如果不是dict,就返回一个空的dict{}

qbc2016 avatar Nov 20 '25 08:11 qbc2016

@qbc2016 感谢!问题解决了!

liweizhen111 avatar Nov 20 '25 09:11 liweizhen111

@qbc2016 这个会在 框架侧修复吗. 目前还会遇到这个问题.

ssloth avatar Dec 04 '25 08:12 ssloth

@qbc2016 这个会在 框架侧修复吗. 目前还会遇到这个问题.

是的,我们准备让其强制返回字典,可以参考pr #1002

qbc2016 avatar Dec 04 '25 12:12 qbc2016