Add AI SDK data chunk ID and tool approval types - #3760
Conversation
| tool_call_id: str | ||
|
|
||
|
|
||
| class ToolOutputDeniedChunk(BaseChunk): |
There was a problem hiding this comment.
Do we ever receive (the part version) of this, and should we handle it? We'll likely need it for https://ai.pydantic.dev/deferred-tools/#human-in-the-loop-tool-approval
0f50321 to
6c6e56f
Compare
When agent run result contains DeferredToolRequests with approvals, emit ToolApprovalRequestChunk for each tool call requiring human approval. Uses tool_call_id as both approval_id and tool_call_id.
|
Forgot to post this comment, splitting off deferred tool <> approval integration definitely makes sense based on my epxloration. I will slim this down to types + finish reason and then kick off a draft for tool approval logic. Dug into denials a bit, approvals are closer to being easily supported. When a user denies a tool execution, Pydantic AI doesn't have a distinct event type for it. Denied tool results flow as regular So we'd need something like:
|
- Use event.result.response instead of all_messages() - Set finish_reason to error in on_error - Remove tool approval emission (defer to separate PR) - Update test snapshots for finishReason field
@bendrucker Hmm, Pydantic AI doesn't have an event for denials because denials never originate in Pydantic AI itself, they come from the user in the form of |
|
Yeah you're right, I need to keep reading. The only thing I can think of is that the client is expecting an acknowledgement from the server of the denial. I've opened #3772 with half-working code and some notes for discussion. Really an issue with illustrative code attached right now, not close to reviewable/mergeable. If you want to dig further/comment, I'm certainly interested, but otherwise will spend some more time validating the client-side behavior and getting the PR to a reviewable state. |
Adds missing fields to Vercel AI adapter types for full AI SDK compatibility, addressing data part reconciliation and other protocol gaps.
Changes
DataChunk: Adds optionalidfield for data part reconciliation andtransientfield for non-persistent dataFinishChunk: Addsfinish_reasonfield with standard stop reasons (stop,length,content-filter,tool-calls,error,other,unknown)ModelResponse.finish_reasoninhandle_run_resulterrorinon_errorhandlerToolApprovalRequestChunkandToolOutputDeniedChunktypes for human-in-the-loop tool approval workflowsFuture Work
Tool approval integration will be addressed in a separate PR. This requires:
ToolApprovalRequestChunkwhen agent output isDeferredToolRequestsDeferredToolResultsToolOutputDeniedChunk— currently Pydantic AI doesn't distinguish denied tool results from normal results at the event stream level (denied results flow asFunctionToolResultEventwithToolReturnPart)Testing
DataChunkwithidfield to verify reconciliation IDs serialize correctly in the SSE streamDataChunkwithtransient: trueto verify non-persistent data chunks are encoded properlyfinishReason: 'error'is set correctly