Interface BidiAction<I,O,S,Init>
- Type Parameters:
I- per-turn input typeO- final output typeS- stream chunk typeInit- session-init type (passVoid/nullwhen not needed)
- All Superinterfaces:
Action<I,,O, S> Registerable
- All Known Implementing Classes:
Agent,BidiActionImpl
A BidiAction accepts a one-time session-init value (Init), a stream of
per-turn inputs (InputSource<I>), streams chunk values of type S via a
callback, and returns a final output of type O.
Callers that only need a single input can use the inherited Action.run(com.google.genkit.core.ActionContext, I) methods, which
wrap the single input in a BufferedInputSource and invoke the bidi handler transparently.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceFunctional interface that implements the bidirectional streaming logic. -
Method Summary
Modifier and TypeMethodDescriptionrunBidi(ActionContext ctx, Init init, InputSource<I> inputs, Consumer<S> streamCallback) Runs the action in bidirectional-streaming mode.com.fasterxml.jackson.databind.JsonNoderunBidiJson(ActionContext ctx, com.fasterxml.jackson.databind.JsonNode init, InputSource<com.fasterxml.jackson.databind.JsonNode> inputs, Consumer<com.fasterxml.jackson.databind.JsonNode> streamCallback) Runs the action in bidirectional-streaming mode with JSON-typed arguments.ActionRunResult<com.fasterxml.jackson.databind.JsonNode> runBidiJsonWithTelemetry(ActionContext ctx, com.fasterxml.jackson.databind.JsonNode init, InputSource<com.fasterxml.jackson.databind.JsonNode> inputs, Consumer<com.fasterxml.jackson.databind.JsonNode> streamCallback) Runs the action in bidirectional-streaming mode with JSON-typed arguments and telemetry.Methods inherited from interface com.google.genkit.core.Action
getDesc, getInputSchema, getMetadata, getName, getOutputSchema, getType, run, run, runJson, runJsonWithTelemetryMethods inherited from interface com.google.genkit.core.Registerable
register
-
Method Details
-
runBidi
O runBidi(ActionContext ctx, Init init, InputSource<I> inputs, Consumer<S> streamCallback) throws GenkitException Runs the action in bidirectional-streaming mode.- Parameters:
ctx- the action contextinit- the one-time session-init value; may benullinputs- the stream of per-turn inputsstreamCallback- callback invoked for each emitted chunk; may benull- Returns:
- the final output
- Throws:
GenkitException- if execution fails
-
runBidiJson
com.fasterxml.jackson.databind.JsonNode runBidiJson(ActionContext ctx, com.fasterxml.jackson.databind.JsonNode init, InputSource<com.fasterxml.jackson.databind.JsonNode> inputs, Consumer<com.fasterxml.jackson.databind.JsonNode> streamCallback) throws GenkitException Runs the action in bidirectional-streaming mode with JSON-typed arguments.Deserializes
initand each element frominputsbefore handing them to the typed handler, and serializes all chunks and the final result back toJsonNode.- Parameters:
ctx- the action contextinit- the one-time session-init as aJsonNode; may benullinputs- the stream of per-turn inputs asJsonNodevaluesstreamCallback- callback invoked for each emitted chunk serialized toJsonNode; may benull- Returns:
- the final output serialized to
JsonNode - Throws:
GenkitException- if execution fails
-
runBidiJsonWithTelemetry
ActionRunResult<com.fasterxml.jackson.databind.JsonNode> runBidiJsonWithTelemetry(ActionContext ctx, com.fasterxml.jackson.databind.JsonNode init, InputSource<com.fasterxml.jackson.databind.JsonNode> inputs, Consumer<com.fasterxml.jackson.databind.JsonNode> streamCallback) throws GenkitException Runs the action in bidirectional-streaming mode with JSON-typed arguments and telemetry.Behaves like
runBidiJson(com.google.genkit.core.ActionContext, com.fasterxml.jackson.databind.JsonNode, com.google.genkit.core.InputSource<com.fasterxml.jackson.databind.JsonNode>, java.util.function.Consumer<com.fasterxml.jackson.databind.JsonNode>)(deserializinginitand each element frominputs, serializing all chunks and the final result back toJsonNode) but additionally creates a new tracing span and captures the resulting trace/span IDs, returning them in anActionRunResult. Unlike the unaryAction.runJsonWithTelemetry(com.google.genkit.core.ActionContext, com.fasterxml.jackson.databind.JsonNode, java.util.function.Consumer<com.fasterxml.jackson.databind.JsonNode>), this threads the realinitand the full stream ofinputsthrough to the handler.- Parameters:
ctx- the action contextinit- the one-time session-init as aJsonNode; may benullinputs- the stream of per-turn inputs asJsonNodevaluesstreamCallback- callback invoked for each emitted chunk serialized toJsonNode; may benull- Returns:
- the final output serialized to
JsonNodetogether with the captured trace/span IDs - Throws:
GenkitException- if execution fails
-