Tool_call has a problem

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File “C:\Users\c-zhaoch04\projects\agno\product_development_team.py”, line 226, in
product_development_team.print_response(user_input)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^
File “C:\Users\c-zhaoch04\AppData\Local\anaconda3\envs\agno\Lib\site-packages\agno\team\team.py”, line 1634, in print_response
self._print_response(
~~~~~~~~~~~~~~~~~~~~^
message=message,
^^^^^^^^^^^^^^^^
…<10 lines>…
**kwargs,
^^^^^^^^^
)
^
File “C:\Users\c-zhaoch04\AppData\Local\anaconda3\envs\agno\Lib\site-packages\agno\team\team.py”, line 1699, in _print_response
run_response: TeamRunResponse = self.run( # type: ignore
~~~~~~~~^^^^^^^^^^^^^^^^^
message=message,
^^^^^^^^^^^^^^^^
…<5 lines>…
**kwargs,
^^^^^^^^^
)
^
File “C:\Users\c-zhaoch04\AppData\Local\anaconda3\envs\agno\Lib\site-packages\agno\team\team.py”, line 608, in run
raise last_exception
File “C:\Users\c-zhaoch04\AppData\Local\anaconda3\envs\agno\Lib\site-packages\agno\team\team.py”, line 580, in run
self._run(
~~~~~~~~~^
run_response=self.run_response,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
run_messages=run_messages,
^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File “C:\Users\c-zhaoch04\AppData\Local\anaconda3\envs\agno\Lib\site-packages\agno\team\team.py”, line 645, in _run
model_response = self.model.response(messages=run_messages.messages) # type: ignore
File “C:\Users\c-zhaoch04\AppData\Local\anaconda3\envs\agno\Lib\site-packages\agno\models\base.py”, line 193, in response
for function_call_response in self.run_function_calls(
~~~~~~~~~~~~~~~~~~~~~~~^
function_calls=function_calls_to_run, function_call_results=function_call_results
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
):
^
File “C:\Users\c-zhaoch04\AppData\Local\anaconda3\envs\agno\Lib\site-packages\agno\models\base.py”, line 874, in run_function_calls
for item in fc.result:
^^^^^^^^^
File “C:\Users\c-zhaoch04\AppData\Local\anaconda3\envs\agno\Lib\site-packages\agno\team\team.py”, line 4537, in transfer_task_to_member
member_agent_run_response = member_agent.run(
member_agent_task, images=images, videos=videos, audio=audio, files=files, stream=False
)
File “C:\Users\c-zhaoch04\AppData\Local\anaconda3\envs\agno\Lib\site-packages\agno\agent\agent.py”, line 1019, in run
raise last_exception
File “C:\Users\c-zhaoch04\AppData\Local\anaconda3\envs\agno\Lib\site-packages\agno\agent\agent.py”, line 989, in run
return next(resp)
File “C:\Users\c-zhaoch04\AppData\Local\anaconda3\envs\agno\Lib\site-packages\agno\agent\agent.py”, line 701, in _run
model_response = self.model.response(messages=run_messages.messages)
File “C:\Users\c-zhaoch04\AppData\Local\anaconda3\envs\agno\Lib\site-packages\agno\models\base.py”, line 177, in response
assistant_message, has_tool_calls = self._process_model_response(
~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
messages=messages,
^^^^^^^^^^^^^^^^^^
model_response=model_response,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File “C:\Users\c-zhaoch04\AppData\Local\anaconda3\envs\agno\Lib\site-packages\agno\models\base.py”, line 313, in _process_model_response
response = self.invoke(messages=messages)
File “C:\Users\c-zhaoch04\AppData\Local\anaconda3\envs\agno\Lib\site-packages\agno\models\openai\chat.py”, line 355, in invoke
raise ModelProviderError(
…<4 lines>…
) from e
agno.exceptions.ModelProviderError: An assistant message with ‘tool_calls’ must be followed by tool messages responding to each ‘tool_call_id’. The following tool_call_ids did not have response messages: call_zRyQIEKHvbG6Z4aVddwkTk5q

The problem didn’t appear every time. I didn’t change anything but the exceptions occured sometimes.

Hey @Dreamer

thanks for reaching out and supporting Agno. I’ve shared this with the team, we’re working through all requests one by one and will get back to you soon.
If it’s urgent, please let us know. We appreciate your patience!

Hi @Dreamer

Would you mind sharing a snippet of your whole team and how it is setup. We would like to replicate this on our side to be able to provide you with the correct info on how to correct this.

from agno.agent import Agent
#from agno.models.openai import OpenAIChat
from agno.models.azure import AzureOpenAI
from agno.team.team import Team
from agno.tools.python import PythonTools

import os
endpoint = os.getenv(“ENDPOINT_URL”, “https://gc-tenant-common.openai.azure.com/”)
deployment = os.getenv(“DEPLOYMENT_NAME”, “gpt-4o-common”)
api_version=“2024-12-01-preview”
key=“”
requirements_analyst = Agent(
name=“RequirementsAnalyst”,
role=“Extract and structure core user needs”,
model=AzureOpenAI(
azure_deployment=deployment,
azure_endpoint=endpoint,
api_version=api_version,
api_key=key,
temperature=0.1,
max_tokens=1000,
),
instructions=[
“Given user needs, generate a STRICT JSON with the following fields:”,
“{”,
" "functional_requirements": [核心功能列表, 例如["打印hello world"]],“,
" "acceptance_criteria": [验收标准, 例如["程序输出包含hello world"]]”,
“}”,
“Do NOT output any text outside the JSON format.” # 禁止自由文本
],
add_datetime_to_instructions=True,
)

product_designer = Agent(
name=“ProductDesigner”,
role=“Convert requirements to simple technical plan”,
model=AzureOpenAI(
azure_deployment=deployment,
azure_endpoint=endpoint,
api_version=api_version,
api_key=key,
temperature=0.1, # 原默认0.7,调低至0.1-0.3
max_tokens=1000, # 限制输出长度,避免生成冗余内容
),
instructions=[
“Describe how to implement the goal. Include the main programming language, key functions or methods, and a brief description of the data flow. For example: ‘Use Python and the print() function. The input is a static string, and the output is directly printed to the console.’”,
“If you encounter any issues or the requirements are unclear, return an error message indicating the problem.”
],
add_datetime_to_instructions=True,
)
from agno.tools.shell import ShellTools
developer = Agent(
name=“Developer”,
role=“Implement designs into production-ready code following engineering best practices”,
model=AzureOpenAI(
azure_deployment=deployment,
azure_endpoint=endpoint,
api_version=api_version,
api_key=key,
temperature=0.1, # 原默认0.7,调低至0.1-0.3
max_tokens=1000, # 限制输出长度,避免生成冗余内容
),
instructions=[
“Given a text-based design description,”,
“1. Use the ShellTools to install any necessary Python packages (e.g., ‘pip install pygame’).”,
“2. Use the PythonTools to write a Python code snippet that implements the core logic.”,
“3. Include comments explaining key steps (e.g., ‘Function to parse HTML for image tags’).”,
“4. Handle basic error cases (e.g., ‘Add a try-except block for invalid URLs’).”,
],
tools=[PythonTools(),ShellTools()],
add_datetime_to_instructions=True,
)

tester = Agent(
name=“Tester”,
role=“Ensure code quality through systematic testing and defect reporting”,
model=AzureOpenAI(
azure_deployment=deployment,
azure_endpoint=endpoint,
api_version=api_version,
api_key=key,
temperature=0.1, # 原默认0.7,调低至0.1-0.3
max_tokens=1000, # 限制输出长度,避免生成冗余内容
),
instructions=[
“Given a Python code snippet and requirements document,”,
“1. Use the PythonTools to write test cases in Python that validate the code against the requirements.”,
“2. List the test cases in the form of Python functions (e.g., ‘def test_download_images()’).”,
“3. Run the test cases using the PythonTools and return the test results.”,
“4. Identify edge cases (e.g., ‘Empty input’, ‘URL with no images’).”,
“5. Write a 1 - sentence summary of whether the code meets requirements.”,
],
tools=[PythonTools()],
add_datetime_to_instructions=True,
)
import json
from textwrap import dedent
from typing import Iterator, Dict
from agno.agent import Agent
from agno.exceptions import StopAgentRun
from agno.tools import FunctionCall, tool
from rich.console import Console
from rich.prompt import Prompt, Confirm

console = Console()

def pre_hook(fc: FunctionCall):
live = console._live
live.stop()
console.print(f"\nAbout to run [bold blue]{fc.function.name}[/]")
if Prompt.ask(“Do you want to continue?”, choices=[“y”, “n”], default=“y”).lower() != “y”:
raise StopAgentRun(“Tool call cancelled by user”)
live.start()

@tool
def request_human_acceptance(
project_name: str,
acceptance_materials: str,
validation_items: list[str],
) → str: # 返回类型改为 str
console.print(f"\n[bold green]=== 项目验收: {project_name} ===“)
console.print(”\n[bold blue]验收材料:\n", acceptance_materials)
console.print(“\n[bold blue]核心验证项:”)
for item in validation_items:
console.print(f" - {item}")

''' passed = Confirm.ask("\n是否通过所有核心功能验收?")
feedback = Prompt.ask("请输入反馈(不通过时必填)", default="")

if not passed and not feedback:
    raise ValueError("不通过时必须提供具体问题描述!")'''
while True:
    response = input("\n是否通过所有核心功能验收? (y/n): ").strip().lower()
    if response in ['y', 'yes']:
        passed = True
        break
    elif response in ['n', 'no']:
        passed = False
        break
    else:
        print("输入无效,请输入 'y' 或 'n'。")

if not passed:
    feedback = input("请输入反馈(不通过时必填): ").strip()
    if not feedback:
        raise ValueError("不通过时必须提供具体问题描述!")
else:
    feedback = ""  
result = {
    "status": "pass" if passed else "fail",
    "feedback": feedback
}
return json.dumps(result)  # 返回 JSON 字符串

acceptance_coordinator = Agent(
name=“AcceptanceCoordinator”,
role=“Human-in-the-loop Orchestrator”,
model=AzureOpenAI(
azure_deployment=deployment,
azure_endpoint=endpoint,
api_version=api_version,
api_key=key,
temperature=0.1, # 原默认0.7,调低至0.1-0.3
max_tokens=1000, # 限制输出长度,避免生成冗余内容
),
instructions=dedent(“”"
当收到Tester的通过报告后:
1. 从需求文档中提取project_name(如"ImageFetchr")
2. 整理验收材料(格式:“需求摘要\n测试摘要\n操作说明”)
3. 从需求文档的"acceptance_criteria"中提取validation_items,转换为以":white_check_mark: “开头的list
4. 调用request_human_acceptance工具,传入上述信息
5. 根据工具返回结果:
- 若通过:输出"项目已交付!“并结束流程
- 若不通过:解析反馈(如"未处理GIF图片”),生成任务@相关角色(如@Developer补充功能)
“””),
tools=[request_human_acceptance],
markdown=True,
)

product_development_team = Team(
name=“ProductDevelopmentTeam”,
mode=“coordinate”, # 核心模式:协调各角色按流程协作
model=AzureOpenAI(
azure_deployment=deployment,
azure_endpoint=endpoint,
api_version=api_version,
api_key=key,
temperature=0.1, # 原默认0.7,调低至0.1-0.3
max_tokens=1000, # 限制输出长度,避免生成冗余内容
),
members=[
requirements_analyst, # 需求分析师
product_designer, # 产品设计师
developer, # 开发工程师
tester, # 测试工程师
acceptance_coordinator, # 验收协调员
],
description=“You are a full-stack product development team. Your goal is to systematically transform raw user needs into a production-ready product through requirements analysis, design, development, testing, and acceptance.”,
instructions=[
“1. RequirementsAnalyst提取核心功能(强制触发)”,
“2. ProductDesigner描述实现方式(强制触发)”,
“3. Developer编写代码(强制触发)”,

    "4. **测试验证阶段(强制触发)**:",
    "   - `Tester` 必须基于`RequirementsAnalyst`的`acceptance_criteria`和`Developer`的代码,生成至少2个测试用例,否则测试报告不通过。",
    
    "5. **验收交付阶段(强制触发)**:",
    "   - `AcceptanceCoordinator` 必须收集前4个阶段的所有输出(需求文档/设计/代码/测试报告),缺一不可启动验收。",
],
add_datetime_to_instructions=True,
enable_agentic_context=True,  # 共享上下文(如需求文档、设计图、代码链接等贯穿全流程)
share_member_interactions=True,  # 各角色可查看历史对话(如测试工程师能看到需求澄清记录,理解功能边界)
show_members_responses=True,    # 可视化各智能体输出(便于调试和流程审计)
markdown=True,                  # 支持富文本输出(如架构图、表格、代码块)
debug_mode=True,
monitoring=True

)
if name == “main”:
user_input = “”"
Develop a Snake game based on Python. The game should adhere to basic rules such as direction control, food generation, collision detection, and a scoring system. It should not rely on external data and have concise and efficient code.
“”"
product_development_team.print_response(user_input)

Thanks for your guidance. The code has been uploaded. If you need further information during the analysis, please inform me. I’m awaiting your advice on the correction.

@WillemdeJongh1 I’m also facing same issue and seeing similar error messages. Please see screenshots over this thread