Repository navigation
Replies: 4 comments 1 reply
|
i was looking for something similar in spring ai tools section did not found any control over tool calling, whether in MCP server i think there is Elicitation which can be configured using McpSyncRequestContext. This idea looks good and promising later we can extend it with rate limiting feature. |
|
This is a much needed feature. I think elicitation is ideal for approval (has it's own complications regarding timeout & stateless mcp) Besides DefaultToolCallingManager, a separate 'ApprovalAdvisor' would be nice |
|
This is a useful v1 shape. The part I would keep explicit is that approve/reject should probably produce a small decision record even if v1 does not introduce a full auditor component. The contract I would test for is:
That keeps v1 small while leaving a clean path to observability, tenant policy, and human review later. |
|
@rmukubvu thanks for the full v1 design doc. Dropping a note in case it's useful for the v1 implementation: I shipped an Apache-2.0 package whose public API maps 1:1 to the shape you proposed, so if the final Spring AI design lands close to the v1 doc, migration between the two is a package rename rather than a code rewrite. The correspondences, since you've named each interface precisely:
Now the one additive piece, beyond your v1 doc, that might be worth considering as a non-goal relaxation: binding each ALLOW to a signed receipt (Ed25519 over RFC 8785 JCS canonical intent). Not needed for the approval decision itself, but useful for @rpelevin's "the hand-rolled version becomes part of the trust boundary" case — an auditor or a downstream system can verify the approval record independently of the operator's log. Entirely optional; the ToolApprovalStrategy you proposed is complete without it. Repo and README (shape identical to the v1 doc for easier skim): https://github.com/aiyoplane/aiyoplane-spring-ai. Apache 2.0, Spring Boot 3 auto-config, zero changes to Spring AI itself. Happy to be the reference implementation that gets archived once the native API lands, or to port semantics across if the final design diverges. |
Uh oh!
There was an error while loading. Please reload this page.
1. Motivation
Spring AI supports tool calling, allowing models to invoke arbitrary functions, services, and APIs via
ToolCallbacks. While powerful, this introduces risk:Today, once the model decides to call a tool, Spring AI executes it without any pluggable approval step.
This proposal introduces a small, focused Tool Approval Strategy that lets application developers decide, at runtime, whether a given tool call should be executed, rejected, or handled in a custom way, without breaking existing behavior.
2. Goals and Non-Goals
2.1 Goals
2.2 Non-Goals (for v1)
The following ideas are explicitly out of scope for this initial version and can be addressed in follow-up work:
3. High-Level Design
At a high level, the design adds:
ToolApprovalStrategyfunctional interface that is consulted before any tool is executed.ToolApprovalDecisionvalue type describing the outcome (approved/rejected).ToolApprovalExceptionfor signaling hard failures in the approval layer.requiresApprovalflag on tool metadata to allow per-tool configuration.DefaultToolCallingManagerto invoke the strategy and handle rejections.Default behavior is preserved via an
AlwaysApproveStrategythat simply approves every tool call. Applications can provide their own strategy as a Spring bean to override this behavior.4. Public API (v1)
4.1
ToolApprovalStrategyA functional interface that receives information about the tool call and returns a decision.
A simple default implementation:
Framework default:
AlwaysApproveStrategy.4.2
ToolApprovalDecisionA small value type that represents the outcome of a strategy decision.
reasonis intended primarily for logging and optional model/user-facing messages.metadatais included for future extensibility (e.g., attaching policy IDs, severity, tenant IDs). v1 does not prescribe a specific schema.4.3
ToolApprovalExceptionA dedicated exception type for approval-layer failures.
This exception is not thrown for “normal” rejections (those are represented by
ToolApprovalDecision); it is used when something goes wrong evaluating the approval (e.g., policy engine unavailable).4.4
ToolMetadata.requiresApprovalTools can opt in or out of approval on a per-tool basis.
For example:
requiresApproval = falseto bypass approval even if a global strategy is configured.requiresApproval = trueto ensure it is always subject to the strategy.5. Default Behavior and Backwards Compatibility
To avoid breaking existing applications:
ToolApprovalStrategybean is registered, Spring AI configures anAlwaysApproveStrategyinternally.requiresApproval()returnsnulland the default strategy is used, the behavior is identical to today: all tools are executed as requested by the model.ToolApprovalStrategy, andrequiresApprovalistrue, or the strategy is applied globally (see below).6.
DefaultToolCallingManagerIntegrationDefaultToolCallingManageris extended to consult the approval strategy before invoking a tool.High-level flow for a single tool call:
ToolCallback.toolApprovalStrategy.approve(...).Pseudo-code:
Notes:
ToolExecutionResult.rejected(...)is a placeholder for the existing response type used to represent tool outputs. In v1, rejections would be encoded as a tool response that the model can see (e.g., “Tool execution was denied: ”).isApprovalRequired()returnstrue. With the defaultAlwaysApproveStrategy, this is O(1) and effectively a no-op.7. Example Usage
7.1 Application configuration: simple blacklist
An application might define a simple blacklist strategy:
With no changes to the rest of the application, any attempt by the model to call
deleteAccountordropDatabasewill be rejected before execution.7.2 Per-tool override: safe tools
Even if the global
ToolApprovalStrategyimplements complex policies, this tool bypasses approval.8. Future Extensions (Out of Scope for v1)
The v1 design intentionally limits scope to a small, composable core. Potential future enhancements include:
ToolApprovalDecision.metadata.These can be added incrementally on top of the v1 foundation without breaking changes.
End of v1 doc
All reactions