[BUG] Agent.kickoff() history omits tool arguments applied by before_tool_call hooks

Abierto
#9,775 1 comentario 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

@oOtiti ya está trabajando en esto.

Desde el 25/11/2026.

  • #9778 de @oOtiti — abierto
  • #9782 de @Kidkender — abierto
  • #9812 de @Mansi2221 — abierto
  • #9828 de @Luckyou-d — abierto

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
63/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
python

Línea de trabajo

Start by tracing how Agent.kickoff() records native tool calls in first.messages, then follow the before_tool_call hook path to see where the changed context.tool_input is passed to the tool. Check the relevant tests for tool hooks and kickoff history, and add coverage for a hook that changes an argument. Done means the returned history contains the effective arguments used by the tool, so a later kickoff can answer with 45 minutes.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

bug
Description

When a before_tool_call hook changes a native tool call’s arguments, Agent.kickoff() returns the model’s original arguments in messages. The call record omits the arguments that reached the tool.

I was using a meeting coordinator to reserve a room. Our calendar uses 15-minute blocks, so I called register_before_tool_call_hook(use_calendar_blocks) to round up context.tool_input["duration_minutes"]. I requested 35 minutes, and the reserve_room tool saved a 45-minute booking and returned a confirmation number. I passed first.messages into a second assistant.kickoff() and asked how long the reservation was. The Agent answered 35 minutes, matching the original arguments in the returned history.

Steps to Reproduce

Run the following python code with a LLM model:


import os
from pathlib import Path

from crewai import Agent, LLM
from crewai.hooks.tool_hooks import register_before_tool_call_hook
from crewai.tools import tool

booking = Path("/tmp/meeting-room-reservation.txt")
booking.unlink(missing_ok=True)


@tool
def reserve_room(duration_minutes: int) -> str:
    """Reserve our meeting room for the requested number of minutes."""
    booking.write_text(str(duration_minutes))
    return "Room reserved. Reference: MEETING-24."


def use_calendar_blocks(context):
    if context.tool_name == "reserve_room":
        context.tool_input["duration_minutes"] = ((context.tool_input["duration_minutes"] + 14) // 15) * 15


register_before_tool_call_hook(use_calendar_blocks)
llm = LLM(model="openai/deepseek-flash", custom_openai=True,
          api_key=os.environ["DEEPSEEK_API_KEY"], base_url="https://api.deepseek.com",
          temperature=0, extra_body={"thinking": {"type": "disabled"}})
assistant = Agent(role="Meeting coordinator", goal="Book rooms and answer reservation questions",
                  backstory="You remember completed bookings from the conversation.",
                  llm=llm, tools=[reserve_room], verbose=True)
first = assistant.kickoff("Reserve our meeting room for 35 minutes. After booking it, reply only Booked.")
print(first.raw)
answer = assistant.kickoff([*first.messages, {"role": "user", "content":
    "For how many minutes did you book the room? Reply with only the number. Do not change the booking."}])
print(answer.raw)
print("Booked duration:", booking.read_text())
assert answer.raw.strip() == booking.read_text(), "The continued conversation remembers a different duration from the completed reservation"

Expected behavior

A later turn should have access to the effective 45-minute duration associated with the completed reservation, and answer 45.

Screenshots/Code snippets

N/A

Operating System

Ubuntu 20.04

Python Version

3.11

crewAI Version

1.15.45

crewAI Tools Version

N/A — crewai-tools is not installed. The script uses crewai.tools from CrewAI itself.

Virtual Environment

Conda

Evidence

╭──────────────────────────── 🤖 LiteAgent Started ────────────────────────────╮
│                                                                              │
│  LiteAgent Started                                                           │
│  Role: Meeting coordinator                                                   │
│  Status: In Progress                                                         │
│                                                                              │
│                                                                              │
╰──────────────────────────────────────────────────────────────────────────────╯

╭──────────────────────────── 🤖 LiteAgent Started ────────────────────────────╮
│                                                                              │
│  LiteAgent Session Started                                                   │
│  Name: Meeting coordinator                                                   │
│  id: bdfa7042-ed00-43b7-9490-2c895f918c26                                    │
│  role: Meeting coordinator                                                   │
│  goal: Book rooms and answer reservation questions                           │
│  backstory: You remember completed bookings from the conversation.           │
│  tools: reserve_room                                                         │
│  verbose: True                                                               │
│                                                                              │
│                                                                              │
╰──────────────────────────────────────────────────────────────────────────────╯

Using an approximate input token count for model 'deepseek-flash': assuming one token per four characters because a native token count is unavailable.
╭─────────────────────── 🔧 Tool Execution Started (#1) ───────────────────────╮
│                                                                              │
│  Tool: reserve_room                                                          │
│  Args: {'duration_minutes': 35}                                              │
│                                                                              │
│                                                                              │
╰──────────────────────────────────────────────────────────────────────────────╯

WARNING:crewai.llms.base_llm:Using an approximate input token count for model 'deepseek-flash': assuming one token per four characters because a native token count is unavailable.
╭────────────────────── ✅ Tool Execution Completed (#1) ──────────────────────╮
│                                                                              │
│  Tool Completed                                                              │
│  Tool: reserve_room                                                          │
│  Output: Room reserved. Reference: MEETING-24.                               │
│                                                                              │
│                                                                              │
╰──────────────────────────────────────────────────────────────────────────────╯

WARNING:crewai.llms.base_llm:Using an approximate input token count for model 'deepseek-flash': assuming one token per four characters because a native token count is unavailable.
[Finalize] todos_count=0, todos_with_results=0
╭─────────────────────────── ✅ Agent Final Answer ────────────────────────────╮
│                                                                              │
│  Agent: Meeting coordinator                                                  │
│                                                                              │
│  Final Answer:                                                               │
│  Booked.                                                                     │
│                                                                              │
╰──────────────────────────────────────────────────────────────────────────────╯

Booked.╭─────────────────────────── ✅ LiteAgent Completed ───────────────────────────╮
│                                                                              │
│  LiteAgent Completed                                                         │
│  Role: Meeting coordinator                                                   │
│  id: bdfa7042-ed00-43b7-9490-2c895f918c26                                    │
│  role: Meeting coordinator                                                   │
│  goal: Book rooms and answer reservation questions                           │
│  backstory: You remember completed bookings from the conversation.           │
│  tools: reserve_room                                                         │
│  verbose: True                                                               │
│                                                                              │
│                                                                              │
╰──────────────────────────────────────────────────────────────────────────────╯


╭──────────────────────────── 🤖 LiteAgent Started ────────────────────────────╮
│                                                                              │
│  LiteAgent Started                                                           │
│  Role: Meeting coordinator                                                   │
│  Status: In Progress                                                         │
│                                                                              │
│                                                                              │
╰──────────────────────────────────────────────────────────────────────────────╯

╭──────────────────────────── 🤖 LiteAgent Started ────────────────────────────╮
│                                                                              │
│  LiteAgent Session Started                                                   │
│  Name: Meeting coordinator                                                   │
│  id: bdfa7042-ed00-43b7-9490-2c895f918c26                                    │
│  role: Meeting coordinator                                                   │
│  goal: Book rooms and answer reservation questions                           │
│  backstory: You remember completed bookings from the conversation.           │
│  tools: reserve_room                                                         │
│  verbose: True                                                               │
│                                                                              │
│                                                                              │
╰──────────────────────────────────────────────────────────────────────────────╯

WARNING:crewai.llms.base_llm:Using an approximate input token count for model 'deepseek-flash': assuming one token per four characters because a native token count is unavailable.
[Finalize] todos_count=0, todos_with_results=0
╭─────────────────────────── ✅ Agent Final Answer ────────────────────────────╮
│                                                                              │
│  Agent: Meeting coordinator                                                  │
│                                                                              │
│  Final Answer:                                                               │
│  35                                                                          │
│                                                                              │
╰──────────────────────────────────────────────────────────────────────────────╯

35╭─────────────────────────── ✅ LiteAgent Completed ───────────────────────────╮
│                                                                              │
│  LiteAgent Completed                                                         │
│  Role: Meeting coordinator                                                   │
│  id: bdfa7042-ed00-43b7-9490-2c895f918c26                                    │
│  role: Meeting coordinator                                                   │
│  goal: Book rooms and answer reservation questions                           │
│  backstory: You remember completed bookings from the conversation.           │
│  tools: reserve_room                                                         │
│  verbose: True                                                               │
│                                                                              │
│                                                                              │
╰──────────────────────────────────────────────────────────────────────────────╯


Booked duration: 45
Traceback (most recent call last):
  File "/tmp/crewai-room-reservation/main.py", line 37, in <module>
    assert answer.raw.strip() == booking.read_text(), "The continued conversation remembers a different duration from the completed reservation"
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: The continued conversation remembers a different duration from the completed reservation

Possible Solution

None

Additional context

None

Lenguaje dominante
Python
Estrellas
61.2k
Forks
9.2k
Merge medio
1 d 14 h
PR fusionados (30 d)
180

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de crewAIInc/crewAI

Todos los issues de crewAIInc/crewAI

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.