Class AgentResponse<S>

java.lang.Object
com.google.genkit.ai.agent.AgentResponse<S>
Type Parameters:
S - the type of custom session state

public final class AgentResponse<S> extends Object
AgentResponse is the ergonomic wrapper AgentChat.send(java.lang.String) returns for one completed turn.

It surfaces the assistant Message and convenience views derived from it (text, tool-request parts, interrupts) alongside the turn's identifiers, custom state, artifacts, finish reason, and the raw AgentOutput.

  • Method Details

    • message

      public Message message()
      Returns the assistant message produced by the turn.
      Returns:
      the message, or null if the turn produced none
    • text

      public String text()
      Returns the concatenated text of the assistant message's text parts.
      Returns:
      the text (empty string if there is no message / no text parts)
    • toolRequests

      public List<Part> toolRequests()
      Returns the tool-request parts of the assistant message.
      Returns:
      an unmodifiable list of tool-request parts (possibly empty)
    • interrupts

      public List<AgentInterrupt> interrupts()
      Returns the interrupts for this turn.

      Best-effort: when the turn finished with AgentFinishReason.INTERRUPTED, every tool-request part of the assistant message is reported as an interrupt. The wire Part does not currently carry an explicit interrupt flag, so all pending tool requests are treated as interrupts. When the turn did not finish interrupted, this returns an empty list.

      Returns:
      an unmodifiable list of interrupts (possibly empty)
    • finishReason

      public AgentFinishReason finishReason()
      Returns the turn's finish reason.
      Returns:
      the finish reason, or null
    • snapshotId

      public String snapshotId()
      Returns the snapshot ID produced by the turn (server-managed agents).
      Returns:
      the snapshot ID, or null
    • sessionId

      public String sessionId()
      Returns the session ID.
      Returns:
      the session ID, or null
    • custom

      public S custom()
      Returns the custom session state after the turn.
      Returns:
      the custom state, or null
    • state

      public SessionState<S> state()
      Returns the full session state at the end of the turn.

      For client-managed agents this is the inline state echoed by the agent. For server-managed agents the agent does not echo full state inline, so this returns null; use snapshotId() with AgentChat / getSnapshotData to read server-side state.

      Returns:
      the session state, or null
    • artifacts

      public List<Artifact> artifacts()
      Returns the turn's artifacts.
      Returns:
      an unmodifiable list of artifacts (possibly empty)
    • raw

      public AgentOutput<S> raw()
      Returns the underlying raw agent output.
      Returns:
      the raw output