agentscope icon indicating copy to clipboard operation
agentscope copied to clipboard

[Bug]:在jupyter中运行报错

Open fushunwmj opened this issue 1 month ago • 4 comments

Error reported when calling the execute_python_code tool in Jupyter

from agentscope.agent import ReActAgent, AgentBase from agentscope.formatter import DashScopeChatFormatter from agentscope.memory import InMemoryMemory from agentscope.message import Msg from agentscope.model import DashScopeChatModel import asyncio import os

from agentscope.tool import Toolkit, execute_python_code

async def creating_react_agent() -> None: """创建一个 ReAct 智能体并运行一个简单任务。""" # 准备工具 toolkit = Toolkit() toolkit.register_tool_function(execute_python_code)

jarvis = ReActAgent(
    name="Jarvis",
    sys_prompt="你是一个名为 Jarvis 的助手",
    model=DashScopeChatModel(
        model_name="qwen-max",
        api_key='sk-xxx',
        stream=True,
        enable_thinking=False,
    ),
    formatter=DashScopeChatFormatter(),
    toolkit=toolkit,
    memory=InMemoryMemory(),
)

msg = Msg(
    name="user",
    content="你好!Jarvis,用 Python 运行 Hello World。",
    role="user",
)

await jarvis(msg)

await creating_react_agent()

agentscope版本1.0.8

Image

fushunwmj avatar Nov 25 '25 01:11 fushunwmj

单独调用代码工具执行也是报错的 Image

fushunwmj avatar Nov 25 '25 01:11 fushunwmj

你暴露了你的api_key,这样没事儿吗?

SilenceGoo avatar Nov 25 '25 02:11 SilenceGoo

@fushunwmj I have a test in jupyter notebook, and the toolkit works normally. Please provide more information about your running os (windows or mac or linux), the juypter notebook version

Image

DavdGao avatar Nov 25 '25 02:11 DavdGao

这个是windows上运行的,版本如下

Image

fushunwmj avatar Nov 25 '25 07:11 fushunwmj

原因可能是execute_python_code的实现在 Windows 上调用 asyncio.create_subprocess_exec 时失败,抛出的异常消息为空。 可以尝试一下自定义一个简单的工具,比如

def add(a: int, b: int) -> ToolResponse:
    """
    Add two numbers.

    Args:
        a(`int`):
            An integer.
        b(`int`):
            An integer.
    Returns:
        ToolResponse
    """
    return ToolResponse(
        content=[
            TextBlock(
                type="text",
                text=str(a + b),
            ),
        ],
    )

运行一下,看会不会报错,

qbc2016 avatar Dec 03 '25 09:12 qbc2016

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 Dec 24 '25 09:12 github-actions[bot]