Skip to content

[Bug] Chatbot output nothing #49

@rayrayraykk

Description

@rayrayraykk

Bug Description

Due to the protocol update, the chatbot demo do not work with AgentScopeAgent.

Affected Component

  • Engine
  • Sandbox
  • Documentation
  • Other:___________

To reproduce:

# -*- coding: utf-8 -*-
import asyncio
import os


from agentscope_runtime.engine import Runner, LocalDeployManager
from agentscope_runtime.engine.agents.llm_agent import LLMAgent
from agentscope_runtime.engine.llms import QwenLLM
from agentscope_runtime.engine.services.context_manager import ContextManager
from agentscope_runtime.engine.services.session_history_service import (
    InMemorySessionHistoryService,
)


def local_deploy():
    asyncio.run(_local_deploy())


async def _local_deploy():
    from dotenv import load_dotenv

    load_dotenv()

    server_port = int(os.environ.get("SERVER_PORT", "8090"))
    server_endpoint = os.environ.get("SERVER_ENDPOINT", "agent")

    from agentscope.agent import ReActAgent
    from agentscope.model import DashScopeChatModel
    from agentscope_runtime.engine.agents.agentscope_agent import \
        AgentScopeAgent

    agent = AgentScopeAgent(
        name="Friday",
        model=DashScopeChatModel(
            "qwen-turbo",
            api_key=os.getenv("DASHSCOPE_API_KEY"),
        ),
        agent_config={
            "sys_prompt": "You're a helpful assistant named {name}.",
        },
        agent_builder=ReActAgent,
    )

    print("✅ AgentScope agent created successfully")

    session_history_service = InMemorySessionHistoryService()
    context_manager = ContextManager(
        session_history_service=session_history_service,
    )
    runner = Runner(
        agent=agent,
        context_manager=context_manager,
    )

    deploy_manager = LocalDeployManager(host="localhost", port=server_port)
    try:
        deployment_info = await runner.deploy(
            deploy_manager,
            endpoint_path=f"/{server_endpoint}",
        )

        print("✅ Service deployed successfully!")
        print(f"   URL: {deployment_info['url']}")
        print(f"   Endpoint: {deployment_info['url']}/{server_endpoint}")
        print("\nAgent Service is running in the background.")

        while True:
            await asyncio.sleep(1)

    except (KeyboardInterrupt, asyncio.CancelledError):
        # This block will be executed when you press Ctrl+C.
        print("\nShutdown signal received. Stopping the service...")
        if deploy_manager.is_running:
            await deploy_manager.stop()
        print("✅ Service stopped.")
    except Exception as e:
        print(f"An error occurred: {e}")
        if deploy_manager.is_running:
            await deploy_manager.stop()


if __name__ == "__main__":
    local_deploy()

Output on terminal:

Friday: Hello! How can I assist you today?
{"time": "2025-09-08 16:28:54.019", "step": "agent_step_end", "model": "", "user_id": "", "code": "", "message": "", "task_id": "", "request_id": "e85f3940-99d2-422b-8b1f-b6992ff85c05", "context": {"user_id": "6", "request": {"input": [{"sequence_number": null, "object": "message", "status": "created", "error": null, "id": "msg_c1e450b4-dc59-49a6-ad46-dc5ee805a3d9", "type": "message", "role": "user", "content": [{"sequence_number": null, "object": "content", "status": null, "error": null, "type": "text", "index": null, "delta": false, "msg_id": null, "text": "Hi"}], "code": null, "message": null}], "stream": true, "model": null, "top_p": null, "temperature": null, "frequency_penalty": null, "presence_penalty": null, "max_tokens": null, "stop": null, "n": 1, "seed": null, "tools": null, "session_id": "6", "response_id": null}, "request_id": "e85f3940-99d2-422b-8b1f-b6992ff85c05"}, "interval": {"type": "agent_step_end", "cost": "1.149"}, "ds_service_id": "test_id", "ds_service_name": "test_name"}

Screen shot:

Image

Metadata

Metadata

Assignees

Labels

invalidThis doesn't seem right

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions