Skip to content

[Bug] The metadata is null in /process API response #270

@wiston1988

Description

@wiston1988

Bug Description

The metadata is null in the /process API response using agentscope-runtime v1.0.0

Affected Component

  • Engine
  • Sandbox
  • Tools
  • Common
  • Documentation
  • Other:___________

Reproduction Steps

  1. Your code:

main.py

import asyncio
from agentscope_runtime.engine.deployers.local_deployer import LocalDeployManager
from agent_app_test import agent_app_test  
async def main():
    await agent_app_test.deploy(LocalDeployManager(host="127.0.0.1", port=8088))
if __name__ == "__main__":
    asyncio.run(main())
    input("按 Enter 键停止服务器...")

agent_app_test.py

import logging
import os

from agentscope.agent import ReActAgent
from agentscope.model import DashScopeChatModel
from agentscope.formatter import DashScopeChatFormatter
from agentscope.tool import Toolkit, execute_python_code
from agentscope.pipeline import stream_printing_messages

from agentscope_runtime.engine import AgentApp
from agentscope_runtime.engine.schemas.agent_schemas import AgentRequest
from agentscope_runtime.adapters.agentscope.memory import (
    AgentScopeSessionHistoryMemory,
)
from agentscope_runtime.engine.services.agent_state import (
    InMemoryStateService,
)
from agentscope_runtime.engine.services.session_history import (
    InMemorySessionHistoryService,
)
from agentscope.rag import SimpleKnowledge
from agentscope.embedding import DashScopeTextEmbedding
from milvus import MilvusStore
from dotenv import load_dotenv
from pydantic import BaseModel, Field

print("✅ 依赖导入成功")
load_dotenv()

print(f"api_key:{os.getenv('DASHSCOPE_API_KEY')}")

agent_app_test = AgentApp(
    app_name="Friday",
    app_description="A helpful assistant",
)

print("✅ AgentApp created successfully")
class RuleModel(BaseModel):
    left: str = Field(description="Left Field")
    operator: str = Field(
        description="operator, example:>,<,>=,<=,==,contains",
    )
    right: str = Field(description="Right Field")
    score: float = Field(description="rule score")
@agent_app_test.init
async def init_func(self):
    self.state_service = InMemoryStateService()
    self.session_service = InMemorySessionHistoryService()

    await self.state_service.start()
    await self.session_service.start()

@agent_app_test.shutdown
async def shutdown_func(self):
    await self.state_service.stop()
    await self.session_service.stop()

@agent_app_test.query(framework="agentscope")
async def query_func(
        self,
        msgs,
        request: AgentRequest = None,
        **kwargs,
):
    session_id = request.session_id
    user_id = request.user_id

    state = await self.state_service.export_state(
        session_id=session_id,
        user_id=user_id,
    )

    toolkit = Toolkit()

    agent = ReActAgent(
        name="Friday",
        model=DashScopeChatModel(
            "qwen-max",
            api_key=os.getenv("DASHSCOPE_API_KEY"),
        ),
        sys_prompt="# Identity And Core Mission"
    "You are a specialized rule generation assistant designed to create decision rules in a specific JSON format."
    "Your core function is to analyze user descriptions of business rules and convert them into standardized rule structures."
    "## Instructions"
                   "1. **Determine the Left Field:** Identify the left-hand parameter of the rule based on the user's input."
                   "2. **Determine the Operator:** Identify the operator based on the user's input. The operator must be one of the following list: >, <, >=, <=, ==, contains. Assign it to operator."
                   "3. **Determine the Right Field:** Identify the right-hand parameter of the rule based on the user's input and judge whether it is a constant:"
                   "* If it is a constant, directly assign it to right."
                   "* If it is not a constant, search the knowledge base for the most similar field name and assign it to right."
                   "4. **Determine the Score:** Determine the score based on the user's input:"
                   "* If the user explicitly specifies a score, set it to the specified value."
                   "* If the user describes a rejection intent, set the score to 60."
                   "## Output Specification"
                   "### Format Requirements"
                   "You should only output a JSON object in the following:"
                   "```json"
                   "{"
                   "\"left\": \"身份证关联手机号个数\","
                   "\"operator\": \">\","
                                  "\"right\": \"2\","
                                              "\"score\": 60"
                                                     "}"
                                                     "```"
                   "### Field Definitions"
                   "- **`left`**: Target field identifier (mapped from user description)"
                   "- **`operator`**: One of: `>`, `<`, `>=`, `<=`, `==`, `contains`"
                   "- **`right`**: Reference value (constant) or comparative field name"                                                                               
                   "- **`score`**: Action indicator → `60` for rejection, `40` for manual review",
        toolkit=toolkit,
        memory=AgentScopeSessionHistoryMemory(
            service=self.session_service,
            session_id=session_id,
            user_id=user_id,
        ),
        formatter=DashScopeChatFormatter(),
    )
    agent.set_console_output_enabled(enabled=True)

    if state:
        agent.load_state_dict(state)

    async for msg, last in stream_printing_messages(
            agents=[agent],
            coroutine_task=agent(msgs,structured_model=RuleModel),
            # coroutine_task=agent(msgs),
    ):
        yield msg, last

    state = agent.state_dict()

    await self.state_service.save_state(
        user_id=user_id,
        session_id=session_id,
        state=state,
    )
print("✅ 智能体和端点配置成功")
  1. How to run: python main.py
  2. Error occurs at:
    curl --location --request POST 'http://localhost:8088/process'
    --header 'Content-Type: application/json'
    --data-raw '{
    "input": [
    {
    "role": "user",
    "content": [
    {"type": "text", "text": "如果7天内关联的设备ID大于1个,那么就拒绝"}
    ]
    }
    ],
    "session_id": "test_session_001",
    "user_id": "test_user_001"
    }'

Expected vs Actual Behavior

Expected: the metadata in the response is not null
Actual: the metadata in the response is null

Error Messages

Environment

  • **AgentScope Runtime Version:v1.0.0
  • **Python Version:3.11
  • **OS:macOS 13.0.1
  • **Installation: pip

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions