Package com.google.genkit.core
Class ActionDef<I,O,S>
java.lang.Object
com.google.genkit.core.ActionDef<I,O,S>
- Type Parameters:
I- The input type for the actionO- The output type for the actionS- The streaming chunk type (use Void for non-streaming actions)
- All Implemented Interfaces:
Action<I,,O, S> Registerable
ActionDef is the default implementation of an Action. It provides a named,
observable operation that can be executed and traced.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceFunction interface for non-streaming actions.static interfaceFunction interface for streaming actions. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncreate(String name, ActionType type, Map<String, Object> metadata, Map<String, Object> inputSchema, Class<I> inputClass, Class<O> outputClass, ActionDef.ActionFunction<I, O> fn) Creates a non-streaming action.static <I,O, S> ActionDef <I, O, S> createStreaming(String name, ActionType type, Map<String, Object> metadata, Map<String, Object> inputSchema, Class<I> inputClass, Class<O> outputClass, ActionDef.StreamingFunction<I, O, S> fn) Creates a streaming action.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.Returns the registry this action is registered with.getType()Returns the type of the action.voidRegisters this primitive with the given registry.run(ActionContext ctx, I input) Runs the action with the given input.run(ActionContext ctx, I input, Consumer<S> streamCallback) Runs the action with the given input and streaming callback.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.
-
Constructor Details
-
ActionDef
public ActionDef(String name, ActionType type, Map<String, Object> metadata, Map<String, Object> inputSchema, Class<I> inputClass, Class<O> outputClass, ActionDef.StreamingFunction<I, O, S> fn) Creates a new ActionDef.- Parameters:
name- the action nametype- the action typemetadata- additional metadatainputSchema- the input JSON schemainputClass- the input classoutputClass- the output classfn- the action function
-
-
Method Details
-
create
public static <I,O> ActionDef<I,O, createVoid> (String name, ActionType type, Map<String, Object> metadata, Map<String, Object> inputSchema, Class<I> inputClass, Class<O> outputClass, ActionDef.ActionFunction<I, O> fn) Creates a non-streaming action.- Type Parameters:
I- input typeO- output type- Parameters:
name- the action nametype- the action typemetadata- additional metadatainputSchema- the input JSON schemainputClass- the input classoutputClass- the output classfn- the action function- Returns:
- a new ActionDef
-
createStreaming
public static <I,O, ActionDef<I,S> O, createStreamingS> (String name, ActionType type, Map<String, Object> metadata, Map<String, Object> inputSchema, Class<I> inputClass, Class<O> outputClass, ActionDef.StreamingFunction<I, O, S> fn) Creates a streaming action.- Type Parameters:
I- input typeO- output typeS- stream chunk type- Parameters:
name- the action nametype- the action typemetadata- additional metadatainputSchema- the input JSON schemainputClass- the input classoutputClass- the output classfn- the streaming function- Returns:
- a new ActionDef
-
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. -
run
Description copied from interface:ActionRuns the action with the given input. -
run
Description copied from interface:ActionRuns the action with the given input and streaming callback. -
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
-
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
-
register
Description copied from interface:RegisterableRegisters this primitive with the given registry.- Specified by:
registerin interfaceRegisterable- Parameters:
registry- the registry to register with
-
getRegistry
Returns the registry this action is registered with.- Returns:
- the registry, or null if not registered
-