Class ToolResultApplier

java.lang.Object
com.agentforge4j.runtime.tool.ToolResultApplier

public final class ToolResultApplier extends Object
The single routine that applies a successful ToolResult to WorkflowState, used identically by the inline ALLOW path (ToolInvocationCommandHandler) and the approved-resume path (DefaultWorkflowRuntime#continueAfterToolApproval) so both produce the same state shape.

Tool output is runtime-produced, so it is written under a reserved tool.<capability> key tagged with the current step's execution uid and is not subject to agent outputKeys gating.

  • Field Details

    • TOOL_CONTEXT_KEY_PREFIX

      public static final String TOOL_CONTEXT_KEY_PREFIX
      Reserved context-key prefix for tool results.
      See Also:
    • TOOL_ERROR_KEY_SUFFIX

      public static final String TOOL_ERROR_KEY_SUFFIX
      Reserved context-key suffix for a tool error (denied or failed), written under tool.<capability>.error.
      See Also:
  • Constructor Details

    • ToolResultApplier

      public ToolResultApplier(EventRecorder eventRecorder)
      Creates the applier.
      Parameters:
      eventRecorder - sink for the CONTEXT_UPDATED event
  • Method Details

    • apply

      public void apply(String capability, ToolResult result, WorkflowState state, String actorId)
      Writes a successful tool result into workflow context.
      Parameters:
      capability - the logical capability whose result this is
      result - the successful tool result; ignored when null or without output
      state - the workflow state to update
      actorId - actor recorded on the context-update event
    • applyError

      public void applyError(String capability, String reason, WorkflowState state, String actorId)
      Writes a tool error (denial or failure detail) into workflow context under tool.<capability>.error, so a subsequent step or agent can branch on it. Used by the operator continue path and by a rejected approval.
      Parameters:
      capability - the logical capability whose error this is
      reason - human-readable denial or failure detail; null becomes an empty string
      state - the workflow state to update
      actorId - actor recorded on the context-update event