Driven by the needs of Datasette Agent's human-in-the-loop ask_user() feature, made the following improvements to how tool calls work:
- Tool implementations can declare a parameter named
llm_tool_callin order to be passed thellm.ToolCallobject for the current invocation. This allows them to access the currentllm_tool_call.tool_call_id. See Accessing the tool call from inside a tool. #1480 - Every tool call is now guaranteed a unique
tool_call_id- providers that do not supply one get a synthesizedtc_-prefixed ULID. #1481 - Tools can raise a
llm.PauseChainexception to cleanly pause the tool chain, useful for things like waiting for human approval. The exception propagates to the caller with.tool_calland.tool_results(completed sibling results) attached, and no model call is made with a placeholder result. See Pausing a chain from inside a tool. #1482 - Failure semantics for concurrent tool execution: async sibling tool calls always run to completion before a pause or hook exception propagates. #1482
- Chains can now resume from a
messages=history ending in unresolved tool calls: the calls are executed through the normalbefore_call/after_callmachinery before the first model call, skipping any that already have results. Theexecute_tool_calls()method also accepts a new optionaltool_calls_list=argument for executing an explicit list ofToolCallobjects in place of the calls requested by the response. See Resuming a chain with pending tool calls. #1482 - Fixed a bug where the async tool executor silently dropped calls to tools not present in
tools=- these now returnError: tool "..." does not existresults, matching the sync executor. #1483