Annotation Interface CompensateFor


@Experimental @Retention(RUNTIME) @Target(METHOD) public @interface CompensateFor
Marks a method as the compensating action for a Tool. When compensation is enabled with .compensateOnToolErrors(true), if a tool fails (also when its error ends the invocation) or the invocation is cancelled, the compensating actions of the tool calls that succeeded in the same invocation are called in reverse order to undo their effects. The annotated method must have the same parameter types as the tool it compensates for, or accept a single ToolExecution parameter. It usually returns void; when it returns a CompletableFuture, a CompletionStage or another asynchronous type that AI Services support for tools through an adapter, the rollback waits until it completes before it runs the next compensating action.

Only @Tool-annotated methods support compensating actions. Programmatically or dynamically defined tools (e.g. MCP tools, tools registered via ToolSpecification) are not supported.

Since:
1.17.0
  • Required Element Summary

    Required Elements
    Modifier and Type
    Required Element
    Description
    The name of the tool that this method compensates for, as it is exposed to the LLM.
  • Element Details

    • value

      String value
      The name of the tool that this method compensates for, as it is exposed to the LLM. This is the Tool.name() when it is explicitly set, otherwise the name of the @Tool-annotated method (which is used as the tool name by default).
      Returns:
      the name of the tool to compensate for.