(core): support duplicate tool policy specification - #6610
Conversation
|
|
||
| on_duplicate: DuplicateMode | ||
| """Behavior when a tool is called multiple times in the same context.""" | ||
| on_duplicate: DuplicateMode | DuplicatePolicy |
There was a problem hiding this comment.
should we add a separate arg like
@function_tool(on_duplicate="reject", duplicate_scope="name_and_args")to not break user code if they are doing info.on_duplicate == "reject" ?
| # argument, and a confirming re-call must key identically to the call it | ||
| # confirms — otherwise `confirm` + `name_and_args` would never match. | ||
| dup_key = _duplicate_key( | ||
| fnc_name=fnc_name, scope=duplicate_policy.scope, raw_arguments=raw_arguments |
There was a problem hiding this comment.
keying on raw_arguments may miss omitted / default parameters? like check_order(order_id="5") and check_order(order_id="5", locale=None) can be the same call with two different keys if locale has a default value and LLM may or may not include locale in the raw arguments. also, 1 vs 1.0?
maybe check duplicates after _prepare_function_arguments?
| # the confirm flag is harness state, not an argument: a confirming re-call has to | ||
| # key identically to the call it confirms | ||
| arguments = {k: v for k, v in arguments.items() if k != CONFIRM_DUPLICATE_PARAM} | ||
| return (fnc_name, _canonical_args(arguments)) |
There was a problem hiding this comment.
_canonical_args is outside the try bock, is that expected to raise?
| # derived AFTER the pop: CONFIRM_DUPLICATE_PARAM is harness state, not a tool | ||
| # argument, and a confirming re-call must key identically to the call it | ||
| # confirms — otherwise `confirm` + `name_and_args` would never match. | ||
| dup_key = _duplicate_key( |
There was a problem hiding this comment.
nit: skip this when on_duplicate == "allow"
| exe_task: asyncio.Task[Any] | ||
| executor: _ToolExecutor | ||
| allow_cancellation: bool | ||
| duplicate_key: tuple[str, str | None] = ("", None) |
There was a problem hiding this comment.
nit: the default is not needed, and when on_duplicate == "allow" it can be None directly?
Comment-only: no behavior change.
No description provided.