[BUG] Agent.kickoff() history omits tool arguments applied by before_tool_call hooks
维护者通常 1 天内回复
@oOtiti 已经在做这个了。
开始于 2026年11月25日。
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 63/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- python
调研方向
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.
由索引模型根据 Issue 内容生成。
描述
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
- 主要语言
- Python
- 星标
- 61.2k
- 派生
- 9.2k
- 平均合并
- 1 天 14 小时
- 30 天内合并 PR
- 180
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
crewAIInc/crewAI 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 1 天内回复
-
[FEATURE] Add Straitly as a native OpenAI-compatible LLM provider可能已有人在做 @HashimSyedUBC 于 2 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
[BUG] Native OpenAI sync streaming with response_model returns an empty string and emits no completed event when the parse is missing可能已有人在做 @basil-k-aji-dev 于 3 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 82/100
维护者通常 1 天内回复
-
[BUG] Native Azure provider ignores the seed setting可能已有人在做 @basil-k-aji-dev 于 3 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 82/100
crewAIInc/crewAI#9787 · 1 条评论 ·
维护者通常 1 天内回复
-
[BUG] LiteLLM path reports 0 cached and reasoning tokens in the usage summary可能已有人在做 @basil-k-aji-dev 于 3 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
相似的 Issue
-
bug harness
难度 2/5 1-3 小时 新手友好度 72/100
mruangutai/harness#2687 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 68/100
modal-labs/modal-client#4158 ·
-
good first issue
难度 1/5 1 小时以内 新手友好度 72/100
维护者通常 1 天内回复
-
难度 2/5 半天 新手友好度 72/100
The-Swarm-Corporation/swarms-rs#168 ·
维护者通常 1 天内回复
-
[BUG] SMTP listener now binds to EMAIL_PORT instead of 2525 since the gunicorn switch 5.0.3-ls373未关闭
难度 2/5 1-3 小时 新手友好度 72/100
linuxserver/docker-healthchecks#137 · 1 条评论 ·