Package com.google.genkit.core
Interface Action<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 Superinterfaces:
Registerable
- All Known Subinterfaces:
Model
- All Known Implementing Classes:
ActionDef,AnthropicModel,AwsBedrockModel,CompatOAIModel,Embedder,Evaluator,Flow,GeminiEmbedder,GeminiModel,GenerateAction,ImagenModel,Indexer,OllamaModel,OpenAIEmbedder,OpenAIImageModel,OpenAIModel,Prompt,Retriever,Tool,TtsModel,VeoModel
Action is the interface that all Genkit primitives (e.g., flows, models,
tools) have in common. An Action represents a named, observable operation
that can be executed and traced.
Actions are the fundamental building blocks of Genkit applications. They provide:
- Named operations that can be discovered and invoked
- Input/output schema validation
- Automatic tracing and observability
- Registry integration for reflection API support
-
Method Summary
Modifier and TypeMethodDescriptiongetDesc()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.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.Methods inherited from interface com.google.genkit.core.Registerable
register
-
Method Details
-
getName
String getName()Returns the name of the action.- Returns:
- the action name
-
getType
ActionType getType()Returns the type of the action.- Returns:
- the action type
-
getDesc
ActionDesc getDesc()Returns the descriptor of the action containing metadata, schemas, etc.- Returns:
- the action descriptor
-
run
Runs the action with the given input.- Parameters:
ctx- the action contextinput- the input to the action- Returns:
- the output of the action
- Throws:
GenkitException- if the action fails
-
run
Runs the action with the given input and streaming callback.- Parameters:
ctx- the action contextinput- the input to the actionstreamCallback- callback for receiving streaming chunks, may be null- Returns:
- the output of the action
- Throws:
GenkitException- if the action fails
-
runJson
com.fasterxml.jackson.databind.JsonNode runJson(ActionContext ctx, com.fasterxml.jackson.databind.JsonNode input, Consumer<com.fasterxml.jackson.databind.JsonNode> streamCallback) throws GenkitException Runs the action with JSON input and returns JSON output.- Parameters:
ctx- the action contextinput- the JSON inputstreamCallback- callback for receiving streaming JSON chunks, may be null- Returns:
- the JSON output
- Throws:
GenkitException- if the action fails
-
runJsonWithTelemetry
ActionRunResult<com.fasterxml.jackson.databind.JsonNode> runJsonWithTelemetry(ActionContext ctx, com.fasterxml.jackson.databind.JsonNode input, Consumer<com.fasterxml.jackson.databind.JsonNode> streamCallback) throws GenkitException Runs the action with JSON input and returns the result with telemetry information.- 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
Returns the JSON schema for the action's input type.- Returns:
- the input schema as a map, or null if not defined
-
getOutputSchema
Returns the JSON schema for the action's output type.- Returns:
- the output schema as a map, or null if not defined
-
getMetadata
Returns additional metadata for the action.- Returns:
- the metadata map
-