Help Needed: Public API for Tool Approval Request Lookup and Response Creation #7775
Replies: 1 comment
|
You may not need the lookup API you're describing, because the harness already refuses to trust the tool call that comes back. In if (surfaced.TryGetValue(response.RequestId, out var surfacedRequest))
{
surfaced.Remove(response.RequestId);
// Rebind to the surfaced request's tool call and record for injection.
state.CollectedApprovalResponses.Add(
new ToolApprovalResponseContent(response.RequestId, response.Approved, surfacedRequest.ToolCall)
{
Reason = response.Reason,
});
}Anything whose id was not surfaced is dropped rather than collected, and the surfaced entry is consumed on match, so a replayed response for the same id has no effect. So your backend can take the lightweight payload from the frontend, build a Two caveats. |
Uh oh!
There was an error while loading. Please reload this page.
We are integrating
ToolApprovalAgentinto a frontend/backend application and are trying to design a clean approval flow for tool calls.Our frontend is not a good place to send back a full
ToolApprovalRequestContent, because that object includes the originalToolCallwith the tool name and arguments. For security reasons, the backend should not trust a tool call object that comes back from the frontend. Ideally, the frontend should only send a lightweight approval decision, such as:{ "sessionId": "session-id", "requestId": "approval-request-id", "approved": true, "mode": "once" }The framework appears to keep approval requests in session state internally. For example,
ApprovalResponseBindingChatClientstores pending approval requests under an internal key, andToolApprovalAgentalso keeps its own internal approval state for queued requests, surfaced requests, collected responses, and standing approval rules. This is useful for framework internals, but the relevant state keys and state types are not exposed as public API.What we are missing is a public, supported mechanism to take a frontend-submitted
requestId, find the corresponding server-sideToolApprovalRequestContentfrom the activeAgentSession, and create the correct approval response. This matters especially for these cases:AlwaysApproveToolApprovalResponseContentfor "always approve this tool".AlwaysApproveToolApprovalResponseContentfor "always approve this tool with these arguments"._pendingApprovalRequestsortoolApprovalState.Today, the safest workaround seems to be for our backend to maintain its own approval store keyed by
(sessionId, requestId), populated fromToolApprovalRequestContentvalues found inAgentResponse.Messagesor streaming updates. The frontend only receives a safe display DTO and later sends back therequestIdplus the approval decision. The backend then uses its own storedToolApprovalRequestContentto callCreateResponse,CreateAlwaysApproveToolResponse, orCreateAlwaysApproveToolWithArgumentsResponse.Is this the intended integration pattern for frontend/backend applications? Or is there a supported API we should use to retrieve the pending approval request from
AgentSessionand construct the corresponding response from only arequestIdand an approval decision?All reactions