Class BidiActionImpl<I,O,S,Init>
- Type Parameters:
I- per-turn input typeO- final output typeS- stream chunk typeInit- session-init type
- All Implemented Interfaces:
Action<I,,O, S> BidiAction<I,,O, S, Init> Registerable
BidiAction built from a name, type parameters, optional
metadata, and a BidiAction.BidiHandler.
Key invariants:
getType()always returnsActionType.AGENT.getMetadata()always containsbidi=true; the caller's metadata map is never mutated.getDesc()returns anActionDescwith key/agent/<name>.- The inherited unary
Action.run(com.google.genkit.core.ActionContext, I)methods adapt to bidi by wrapping the single input in aBufferedInputSource.
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from interface com.google.genkit.core.BidiAction
BidiAction.BidiHandler<I,O, S, Init> -
Method Summary
Modifier and TypeMethodDescriptionstatic <I,O, S, Init>
BidiActionImpl.Builder<I, O, S, Init> builder()Creates a new builder forBidiActionImpl.getDesc()Returns the descriptor of the action containing metadata, schemas, etc.Returns the JSON schema for the action's input type.Returns additional metadata for the action.getName()Returns the name of the action.Returns the JSON schema for the action's output type.getType()Returns the type of the action.voidRegisters this primitive with the given registry.run(ActionContext ctx, I input) Unary adaptation: wrapsinputin aBufferedInputSource(withnullinit) and delegates to the bidi handler.run(ActionContext ctx, I input, Consumer<S> streamCallback) Unary adaptation with streaming: wrapsinputin aBufferedInputSource(withnullinit) and delegates to the bidi handler.runBidi(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.com.fasterxml.jackson.databind.JsonNoderunJson(ActionContext ctx, com.fasterxml.jackson.databind.JsonNode input, Consumer<com.fasterxml.jackson.databind.JsonNode> streamCallback) Runs the action with JSON input and returns JSON output.ActionRunResult<com.fasterxml.jackson.databind.JsonNode> runJsonWithTelemetry(ActionContext ctx, com.fasterxml.jackson.databind.JsonNode input, Consumer<com.fasterxml.jackson.databind.JsonNode> streamCallback) Runs the action with JSON input and returns the result with telemetry information.
-
Method Details
-
getName
Description copied from interface:ActionReturns the name of the action. -
getType
Description copied from interface:ActionReturns the type of the action. -
getDesc
Description copied from interface:ActionReturns the descriptor of the action containing metadata, schemas, etc. -
getInputSchema
Description copied from interface:ActionReturns the JSON schema for the action's input type.- Specified by:
getInputSchemain interfaceAction<I,O, S> - Returns:
- the input schema as a map, or null if not defined
-
getOutputSchema
Description copied from interface:ActionReturns the JSON schema for the action's output type.- Specified by:
getOutputSchemain interfaceAction<I,O, S> - Returns:
- the output schema as a map, or null if not defined
-
getMetadata
Description copied from interface:ActionReturns additional metadata for the action.- Specified by:
getMetadatain interfaceAction<I,O, S> - Returns:
- the metadata map
-
run
Unary adaptation: wrapsinputin aBufferedInputSource(withnullinit) and delegates to the bidi handler. -
run
Unary adaptation with streaming: wrapsinputin aBufferedInputSource(withnullinit) and delegates to the bidi handler. -
runJson
public com.fasterxml.jackson.databind.JsonNode runJson(ActionContext ctx, com.fasterxml.jackson.databind.JsonNode input, Consumer<com.fasterxml.jackson.databind.JsonNode> streamCallback) throws GenkitException Description copied from interface:ActionRuns the action with JSON input and returns JSON output. -
runJsonWithTelemetry
public ActionRunResult<com.fasterxml.jackson.databind.JsonNode> runJsonWithTelemetry(ActionContext ctx, com.fasterxml.jackson.databind.JsonNode input, Consumer<com.fasterxml.jackson.databind.JsonNode> streamCallback) throws GenkitException Description copied from interface:ActionRuns the action with JSON input and returns the result with telemetry information.- Specified by:
runJsonWithTelemetryin interfaceAction<I,O, S> - Parameters:
ctx- the action contextinput- the JSON inputstreamCallback- callback for receiving streaming JSON chunks, may be null- Returns:
- the action result including telemetry data
- Throws:
GenkitException- if the action fails
-
runBidi
public O runBidi(ActionContext ctx, Init init, InputSource<I> inputs, Consumer<S> streamCallback) throws GenkitException Description copied from interface:BidiActionRuns the action in bidirectional-streaming mode.- Specified by:
runBidiin interfaceBidiAction<I,O, S, Init> - 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
public 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 Description copied from interface:BidiActionRuns 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.- Specified by:
runBidiJsonin interfaceBidiAction<I,O, S, Init> - 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
public 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 Description copied from interface:BidiActionRuns the action in bidirectional-streaming mode with JSON-typed arguments and telemetry.Behaves like
BidiAction.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.- Specified by:
runBidiJsonWithTelemetryin interfaceBidiAction<I,O, S, Init> - 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
-
register
Description copied from interface:RegisterableRegisters this primitive with the given registry.- Specified by:
registerin interfaceRegisterable- Parameters:
registry- the registry to register with
-
builder
Creates a new builder forBidiActionImpl.- Type Parameters:
I- per-turn input typeO- final output typeS- stream chunk typeInit- session-init type- Returns:
- a new builder
-