feat: Add a ToolBudgetHook to cap per-tool calls in an Agent run
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 1/100
- issue の種類
- 機能追加
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- python
調査の方向性
The issue names ToolBudgetHook, ConfirmationHook, Agent, and the before_tool hook point, but says the work will be handled internally and is not open to external contributions. If you are authorized to work on it, first read the existing hook and tool call count handling; done means per-tool budgets reject excess calls, including parallel calls, and serialization works.
索引モデルが issue の本文から書いたものです。
説明
Is your feature request related to a problem? Please describe.
An Agent can keep calling the same tool (e.g. a search tool) far past what the task needs. The only limits today are max_agent_steps and TokenBudgetHook, which both end the whole run rather than capping one tool. The harness evaluator in deepset-ai/haystack-core-integrations#3932 already scores a run as 0 when it goes over a per-tool budget, but there is no way to enforce that budget at runtime.
Describe the solution you'd like
A ToolBudgetHook that runs at before_tool and caps how often each tool can be called in one run.
from haystack.hooks import ToolBudgetHook
agent = Agent(
chat_generator=OpenAIResponsesChatGenerator(),
tools=[search, fetch_page, write_report],
hooks={"before_tool": [ToolBudgetHook(budgets={"search": 5, ("fetch_page", "read_file"): 10, "*": 20})]},
)
- Budgets are keyed by tool name, a tuple of names sharing one allowance, or
"*"for every other tool. This is the same key convention asConfirmationHook'sconfirmation_strategiesandresolve_tool_budgetsin #3932. - Counts come from the
tool_call_countsalready inState. Calls requested in the same step count against the remaining allowance in order, so 3 parallelsearchcalls with 1 remaining run the first and reject the other two. - A call over budget is not executed. It gets a tool result like
"Tool budget for 'search' is used up (5/5). Continue with the results you already have.", the same wayConfirmationHookhandles a rejected call, so the model can adapt and finish. allowed_hook_points = ("before_tool",)andto_dict/from_dictfor serialization.- Record each rejected call as tags on the hook's span, like
CompactionHookdoes (haystack.agent.hook.compaction.*): which tool went over budget and its count against the allowance, so budget decisions can be audited from the trace.
Describe alternatives you've considered
- A
max_tool_callsparameter onAgent. A hook keeps it opt-in and composable with other hooks. - Ending the run with an
exit_reasonlike"tool_budget_exceeded"instead of rejecting the call. Open question whether we want this as an option.
Additional context
Open questions:
- Should an exhausted tool also be hidden from the model for the rest of the run, so it stops trying and its schema stops costing tokens?
👋 Hello there! This issue will be handled internally and isn't open for external contributions. If you'd like to contribute, please take a look at issues labeled contributions welcome or good first issue. We'd really appreciate it!
- 主要言語
- Python
- スター
- 27.2k
- フォーク
- 3.5k
- 平均マージ
- 1日 18時間
- マージ済み PR(30日)
- 254
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
deepset-ai/haystack のほかの issue
-
feat: `ByteStream.from_file_path` should keep the file path in `meta`対応中かも @pinjun99 が 2 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
deepset-ai/haystack#14081 · コメント 3 件 ·
メンテナーはふだん 1 日以内に返信
-
BlockingConfirmationStrategy ignores an empty argument replacement対応中かも @sjrl が 6 日前に担当しました。 オープンP1
難易度 1/5 1〜3時間 初心者へのやさしさ 82/100
deepset-ai/haystack#13863 · コメント 2 件 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
CSVToDocument row mode fails on CR-separated CSV input対応中かも @julian-risch が 66 日前に担当しました。 オープンP3
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
deepset-ai/haystack#13022 · コメント 1 件 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
CSVToDocument row mode drops a real extra_columns field on ragged rows再び着手できるかも このイシューのプルリクエストはマージされずにクローズされました。 オープンhandled internally P3
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
deepset-ai/haystack#12994 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
CSVDocumentCleaner deletes a row that says N/A, and both CSV components empty those cells対応中かも @michaelkillgta が 72 日前に担当しました。 オープンP3
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
deepset-ai/haystack#12784 · コメント 3 件 ·
メンテナーはふだん 1 日以内に返信
deepset-ai/haystack の issue をすべて見る
似ている issue
-
Test: to_hijri() accepts datetime.datetime and uses only the date part対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープンgood first issue
難易度 1/5 1時間未満 初心者へのやさしさ 95/100
omarelshamy25x/shamy-hijri#63 · コメント 3 件 ·
メンテナーはふだん 1 日以内に返信
-
polish
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
521xueweihan/HelloGitHub#4729 ·
-
[Bug]: Score parser reads parts of scientific notation as valid scores対応中かも @AshutoshSingh840 が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
UKGovernmentBEIS/control-arena#992 ·
メンテナーはふだん 3 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 92/100
mvalentsev/awesome-free-ai-coding#70 ·
メンテナーはふだん 1 日以内に返信