Class ResultWithAgenticScope<T>

java.lang.Object
dev.langchain4j.agentic.scope.ResultWithAgenticScope<T>
Type Parameters:
T - The type of the result.

public final class ResultWithAgenticScope<T> extends Object
Holds the result of an agent invocation along with its associated AgenticScope. This is useful for returning results from agents while also providing access to the cognitive scope through which that result has been generated.

When the invocation is suspended (suspended() returns true), the caller can provide the human response and resume in a single call via completePendingResponse(Object).

  • Constructor Details

    • ResultWithAgenticScope

      public ResultWithAgenticScope(AgenticScope agenticScope, T result)
    • ResultWithAgenticScope

      public ResultWithAgenticScope(AgenticScope agenticScope, T result, boolean suspended)
    • ResultWithAgenticScope

      public ResultWithAgenticScope(AgenticScope agenticScope, T result, boolean suspended, Supplier<ResultWithAgenticScope<T>> resumeCallback)
  • Method Details

    • agenticScope

      public AgenticScope agenticScope()
    • result

      public T result()
    • suspended

      public boolean suspended()
    • completePendingResponse

      public ResultWithAgenticScope<T> completePendingResponse(Object value)
      Completes the single pending response and re-invokes the agentic system to resume execution. The returned result may itself be suspended if the workflow has further human-in-the-loop steps.
      Parameters:
      value - the human response value
      Returns:
      the result of the resumed invocation
      Throws:
      IllegalStateException - if this result is not suspended, if there is not exactly one pending response, or if no resume callback is available (e.g. after a crash/restart)
    • completePendingResponse

      public ResultWithAgenticScope<T> completePendingResponse(String responseId, Object value)
      Completes the pending response with the given ID and re-invokes the agentic system to resume execution. The returned result may itself be suspended if the workflow has further human-in-the-loop steps.
      Parameters:
      responseId - the identifier of the pending response to complete
      value - the human response value
      Returns:
      the result of the resumed invocation
      Throws:
      IllegalStateException - if this result is not suspended or if no resume callback is available (e.g. after a crash/restart)
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object