Class HttpAgentTransport<S>

java.lang.Object
com.google.genkit.client.HttpAgentTransport<S>
Type Parameters:
S - the type of custom session state
All Implemented Interfaces:
AgentTransport<S>

public final class HttpAgentTransport<S> extends Object implements AgentTransport<S>
HTTP implementation of AgentTransport that speaks the Jetty AgentHandler wire format.

Wire format:

  • Turn: POST url with body {"data":<AgentInput>,"init":<AgentInit>} and Accept: text/event-stream. SSE frames are data: {"message":<chunk>} then data: {"result":<AgentOutput>}. Error frames are data: {"error":{...}}.
  • getSnapshot: POST url/getSnapshot with body {"data":<req>} {"result":<snapshot>}.
  • abort: POST url/abort with body {"data":{"snapshotId":...}} {"result":{"status":...}}.
  • Constructor Details

    • HttpAgentTransport

      public HttpAgentTransport(RemoteAgentOptions opts)
      Constructs an HttpAgentTransport.
      Parameters:
      opts - the options specifying the endpoint URLs, headers, and serverManaged flag
  • Method Details

    • runTurn

      public AgentOutput<S> runTurn(AgentInput input, AgentInit<S> init, Consumer<AgentStreamChunk> onChunk)
      Description copied from interface: AgentTransport
      Runs ONE turn: feeds input with init, collects stream chunks via onChunk, and returns the final output.
      Specified by:
      runTurn in interface AgentTransport<S>
      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

      public SessionSnapshot<S> getSnapshot(GetSnapshotRequest req)
      Description copied from interface: AgentTransport
      Retrieves a session snapshot.
      Specified by:
      getSnapshot in interface AgentTransport<S>
      Parameters:
      req - the request specifying which snapshot to retrieve
      Returns:
      the matching snapshot, or null if not found / not supported
    • abort

      public SnapshotStatus abort(String snapshotId)
      Description copied from interface: AgentTransport
      Attempts to abort a pending snapshot.
      Specified by:
      abort in interface AgentTransport<S>
      Parameters:
      snapshotId - the snapshot to abort
      Returns:
      the resulting status, or null if not found / not supported
    • serverManaged

      public boolean serverManaged()
      Description copied from interface: AgentTransport
      Returns whether the underlying agent is server-managed (state persisted server-side) versus client-managed (state round-tripped by the caller).
      Specified by:
      serverManaged in interface AgentTransport<S>
      Returns:
      true if server-managed