Interface AgentTransport<S>

Type Parameters:
S - the type of custom session state
All Known Implementing Classes:
HttpAgentTransport, InProcessTransport

public interface AgentTransport<S>
AgentTransport abstracts how a single agent turn is executed. The in-process transport ( internal.InProcessTransport) drives a locally-defined Agent's bidi action; a remote transport (future) would issue HTTP/RPC calls. AgentChat is written against this interface so it can drive either.

The transport models the agent's one-turn-per-request contract: runTurn(com.google.genkit.ai.agent.AgentInput, com.google.genkit.ai.agent.AgentInit<S>, java.util.function.Consumer<com.google.genkit.ai.agent.AgentStreamChunk>) feeds exactly one AgentInput (with its AgentInit) and returns the turn's final AgentOutput, streaming AgentStreamChunks along the way.

  • Method Details

    • runTurn

      AgentOutput<S> runTurn(AgentInput input, AgentInit<S> init, Consumer<AgentStreamChunk> onChunk)
      Runs ONE turn: feeds input with init, collects stream chunks via onChunk, and returns the final output.
      Parameters:
      input - the turn input (user message, resume, or detach)
      init - the initialization carrying resume context (snapshotId / sessionId / inline state); may be null for the very first turn of a fresh session
      onChunk - consumer invoked for each streamed chunk; may be a no-op
      Returns:
      the final AgentOutput for the turn
    • getSnapshot

      Retrieves a session snapshot.
      Parameters:
      req - the request specifying which snapshot to retrieve
      Returns:
      the matching snapshot, or null if not found / not supported
    • abort

      SnapshotStatus abort(String snapshotId)
      Attempts to abort a pending snapshot.
      Parameters:
      snapshotId - the snapshot to abort
      Returns:
      the resulting status, or null if not found / not supported
    • serverManaged

      boolean serverManaged()
      Returns whether the underlying agent is server-managed (state persisted server-side) versus client-managed (state round-tripped by the caller).
      Returns:
      true if server-managed