Package com.google.genkit.client
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>
HTTP implementation of
AgentTransport that speaks the Jetty AgentHandler wire
format.
Wire format:
- Turn:
POST urlwith body{"data":<AgentInput>,"init":<AgentInit>}andAccept: text/event-stream. SSE frames aredata: {"message":<chunk>}thendata: {"result":<AgentOutput>}. Error frames aredata: {"error":{...}}. - getSnapshot:
POST url/getSnapshotwith body{"data":<req>}→{"result":<snapshot>}. - abort:
POST url/abortwith body{"data":{"snapshotId":...}}→{"result":{"status":...}}.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAttempts to abort a pending snapshot.Retrieves a session snapshot.runTurn(AgentInput input, AgentInit<S> init, Consumer<AgentStreamChunk> onChunk) Runs ONE turn: feedsinputwithinit, collects stream chunks viaonChunk, and returns the final output.booleanReturns whether the underlying agent is server-managed (state persisted server-side) versus client-managed (state round-tripped by the caller).
-
Constructor Details
-
HttpAgentTransport
Constructs anHttpAgentTransport.- 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:AgentTransportRuns ONE turn: feedsinputwithinit, collects stream chunks viaonChunk, and returns the final output.- Specified by:
runTurnin interfaceAgentTransport<S>- Parameters:
input- the turn input (user message, resume, or detach)init- the initialization carrying resume context (snapshotId / sessionId / inline state); may benullfor the very first turn of a fresh sessiononChunk- consumer invoked for each streamed chunk; may be a no-op- Returns:
- the final
AgentOutputfor the turn
-
getSnapshot
Description copied from interface:AgentTransportRetrieves a session snapshot.- Specified by:
getSnapshotin interfaceAgentTransport<S>- Parameters:
req- the request specifying which snapshot to retrieve- Returns:
- the matching snapshot, or
nullif not found / not supported
-
abort
Description copied from interface:AgentTransportAttempts to abort a pending snapshot.- Specified by:
abortin interfaceAgentTransport<S>- Parameters:
snapshotId- the snapshot to abort- Returns:
- the resulting status, or
nullif not found / not supported
-
serverManaged
public boolean serverManaged()Description copied from interface:AgentTransportReturns whether the underlying agent is server-managed (state persisted server-side) versus client-managed (state round-tripped by the caller).- Specified by:
serverManagedin interfaceAgentTransport<S>- Returns:
trueif server-managed
-