Class AgentChunk<S>

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

public final class AgentChunk<S> extends Object
AgentChunk is the ergonomic wrapper AgentChat.sendStream(java.lang.String, java.util.function.Consumer<com.google.genkit.ai.agent.AgentChunk<S>>) hands to the per-chunk callback.

It exposes the common slices of an AgentStreamChunk: streamed model text, an artifact update, and the post-patch custom state (the running client-side custom state with this chunk's customPatch already applied). The raw chunk is available via raw().

  • Method Details

    • text

      public String text()
      Returns the streamed model text for this chunk.
      Returns:
      the chunk text, or null if this chunk carried no model content
    • modelChunk

      public ModelResponseChunk modelChunk()
      Returns the model response chunk.
      Returns:
      the model chunk, or null
    • artifact

      public Artifact artifact()
      Returns the artifact carried by this chunk.
      Returns:
      the artifact, or null
    • custom

      public S custom()
      Returns the custom state after this chunk's customPatch was applied to the running client-side state.
      Returns:
      the post-patch custom state, or null if this chunk carried no custom patch
    • raw

      public AgentStreamChunk raw()
      Returns the underlying raw stream chunk.
      Returns:
      the raw chunk