Class SessionResolver.Resolution<S>

java.lang.Object
com.google.genkit.ai.agent.internal.SessionResolver.Resolution<S>
Type Parameters:
S - the type of custom session state
Enclosing class:
SessionResolver

public static final class SessionResolver.Resolution<S> extends Object
Result of session resolution: either a ready Session, or a graceful pre-turn failure.

A failure resolution lets the agent generator (Task 4.5) emit an AgentOutput with finishReason=FAILED instead of throwing.

  • Method Details

    • ok

      public static <S> SessionResolver.Resolution<S> ok(Session<S> session)
      Creates a successful resolution wrapping the given session.
      Type Parameters:
      S - the type of custom session state
      Parameters:
      session - the resolved session (must not be null)
      Returns:
      a successful Resolution
    • ok

      public static <S> SessionResolver.Resolution<S> ok(Session<S> session, String sourceSnapshotId)
      Creates a successful resolution wrapping the given session and the id of the snapshot it was resolved (resumed) from. The source snapshot id seeds the runner's lastSnapshotId so the first post-resume turn chains its parentId to it (see SessionRunner).
      Type Parameters:
      S - the type of custom session state
      Parameters:
      session - the resolved session (must not be null)
      sourceSnapshotId - the id of the snapshot this session was resumed from; may be null for a fresh session
      Returns:
      a successful Resolution carrying the source snapshot id
    • failure

      public static <S> SessionResolver.Resolution<S> failure(RuntimeError error)
      Creates a failure resolution carrying a RuntimeError.

      The agent generator should translate this into an AgentOutput with finishReason=FAILED rather than throwing.

      Type Parameters:
      S - the type of custom session state
      Parameters:
      error - the runtime error describing the failure
      Returns:
      a failure Resolution
    • isOk

      public boolean isOk()
      Returns true if this is a successful resolution with a ready session.
      Returns:
      true if ok
    • session

      public Session<S> session()
      Returns the resolved session, or null if this is a failure resolution.
      Returns:
      the session, or null
    • error

      public RuntimeError error()
      Returns the runtime error, or null if this is a successful resolution.
      Returns:
      the error, or null
    • sourceSnapshotId

      public String sourceSnapshotId()
      Returns the id of the snapshot this session was resolved (resumed) from, or null for a fresh session. Used to seed the runner's lastSnapshotId so the first post-resume turn chains its parentId to the resumed snapshot.
      Returns:
      the source snapshot id, or null