agentscope
agentscope copied to clipboard
[Bug]: When structured output is required, the model fails to properly execute the step of calling the generate_response tool.
Describe the bug When structured output is required, the model fails to properly execute the step of calling the generate_response tool.
To Reproduce Steps to reproduce the behavior:
from pydantic import BaseModel, Field
from agentscope.agent import ReActAgent, UserAgent
from agentscope.message import Msg
from agentscope.model import DashScopeChatModel
from agentscope.formatter import DashScopeChatFormatter
from agentscope.memory import InMemoryMemory
from agentscope.tool import Toolkit, execute_python_code, execute_shell_command
import os, asyncio
import agentscope
class ResponseModel(BaseModel):
"""A simple response model for structured output."""
response: str = Field(description="The response")
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=DashScopeChatModel(
api_key=os.environ.get("DASHSCOPE_API_KEY"),
model_name="qwen-max",
enable_thinking=False,
stream=True,
),
formatter=DashScopeChatFormatter(),
memory=InMemoryMemory(),
toolkit=toolkit,
)
msg = Msg(
"user",
"hello",
"user",
)
await agent(msg, structured_model=ResponseModel)
asyncio.run(main())
Expected behavior
use generate_response tool
Friday: {
"type": "tool_use",
"id": "call_746fc681dcdc433abdf61e",
"name": "generate_response",
"input": {
"response": "Hello! How can I assist you today?"
}
}
system: {
"type": "tool_result",
"id": "call_746fc681dcdc433abdf61e",
"name": "generate_response",
"output": [
{
"type": "text",
"text": "Successfully generated response."
}
]
}
Friday: Sure, I'm here to help! Could you please let me know what you need assistance with today?
Error messages The agent generated the text response first rather than calling generate_response.
Environment (please complete the following information):
- AgentScope Version: 1.0.8
- Python Version: 3.10
- OS: macos
Additional context Add any other context about the problem here.