BlockingConfirmationStrategy ignores an empty argument replacement

Đang mở Phù hợp với người mới
#13,863 2 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@Aarkin7 đang làm issue này rồi.

Từ ngày 22/11/2026.

Đánh giá

Độ khó
1/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
82/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
python
Lĩnh vực
ai

Hướng nghiên cứu

Lỗi nằm trong haystack/hooks/human_in_the_loop/strategies.py, quanh dòng 124, nơi nhánh modify kiểm tra new_tool_params theo giá trị đúng/sai nên một dict rỗng bị bỏ qua. Hãy đọc khối đó, rồi chạy script tái hiện offline trong issue dưới cả Agent.run() và Agent.run_async(). Công việc hoàn tất khi công cụ nhận giá trị mặc định 'dry_run' và lịch sử tin nhắn hiển thị arguments {} ở cả hai chế độ, kèm một test hồi quy bao phủ trường hợp thay thế rỗng.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Describe the bug

When a confirmation UI returns ConfirmationUIResult(action="modify", new_tool_params={}), BlockingConfirmationStrategy keeps the original tool arguments instead of applying the empty replacement.

For a tool with optional parameters, removing all arguments should let it use its defaults. In the example below, the model requests record_scope(scope="production"), and the UI replaces the arguments with {}. The tool should use its default "dry_run", but it receives "production" instead.

No exception or warning is raised. The original arguments also remain in the conversation history, with no modification feedback.

Expected behavior

An explicit {} should replace the original arguments. The tool should run with its defaults, and the conversation should reflect the change.

To reproduce

This runs offline and only records a string in a local list. No API key or external action is involved. Save as repro_empty_hitl_replacement.py and run from the repository:

hatch --version
HAYSTACK_TELEMETRY_ENABLED=false hatch -e test run python repro_empty_hitl_replacement.py
import asyncio

from haystack.components.agents import Agent
from haystack.components.generators.chat import MockChatGenerator
from haystack.dataclasses import ChatMessage, ToolCall
from haystack.hooks.human_in_the_loop import (
    AlwaysAskPolicy,
    BlockingConfirmationStrategy,
    ConfirmationHook,
    ConfirmationUIResult,
)
from haystack.tools import Tool


class EmptyReplacementUI:
    def get_user_confirmation(self, tool_name, tool_description, tool_params):
        return ConfirmationUIResult(action="modify", new_tool_params={})


def make_agent():
    observed = []

    def record_scope(scope: str = "dry_run") -> str:
        observed.append(scope)
        return scope

    tool = Tool(
        name="record_scope",
        description="Record the scope locally; perform no external action.",
        parameters={"type": "object", "properties": {"scope": {"type": "string"}}},
        function=record_scope,
    )
    generator = MockChatGenerator(
        responses=[
            ChatMessage.from_assistant(
                tool_calls=[ToolCall(tool_name="record_scope", arguments={"scope": "production"}, id="call-1")]
            ),
            "done",
        ]
    )
    strategy = BlockingConfirmationStrategy(
        confirmation_policy=AlwaysAskPolicy(), confirmation_ui=EmptyReplacementUI()
    )
    agent = Agent(
        chat_generator=generator,
        tools=[tool],
        hooks={"before_tool": [ConfirmationHook(confirmation_strategies={"record_scope": strategy})]},
    )
    return agent, observed


async def main():
    for mode in ("sync", "async"):
        agent, observed = make_agent()
        messages = [ChatMessage.from_user("Record the scope.")]
        result = agent.run(messages=messages) if mode == "sync" else await agent.run_async(messages=messages)
        arguments = [tc.arguments for message in result["messages"] for tc in (message.tool_calls or [])]
        print(f"{mode}: tool received {observed}; tool-call arguments {arguments}")


asyncio.run(main())

Actual output:

sync: tool received ['production']; tool-call arguments [{'scope': 'production'}]
async: tool received ['production']; tool-call arguments [{'scope': 'production'}]

Expected output:

sync: tool received ['dry_run']; tool-call arguments [{}]
async: tool received ['dry_run']; tool-call arguments [{}]

Cause and suggested fix

The check at strategies.py:124 treats {} as if no replacement was supplied:

if confirmation_ui_result.action == "modify" and confirmation_ui_result.new_tool_params:

Checking new_tool_params is not None would honor empty replacements while preserving the current handling of None.

I also verified that a custom strategy returning ToolExecutionDecision(..., final_tool_params={}) correctly uses the tool's defaults. The executor already supports empty arguments; the problem is in the built-in strategy.

Related issue

#13046 concerns a custom strategy that omits final_tool_params. Here, the UI explicitly supplies {}, and the built-in strategy ignores it.

FAQ Check

System

  • OS: macOS
  • Haystack: latest pull of main
  • Reproduced with both Agent.run() and Agent.run_async() through Hatch
Ngôn ngữ chính
Python
Star
27.1k
Fork
3.5k
Merge trung bình
1 ngày 8 giờ
Pull request đã merge (30 ngày)
239

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của deepset-ai/haystack

Tất cả issue của deepset-ai/haystack

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.