Interface Action<I,O,S>

Type Parameters:
I - The input type for the action
O - The output type for the action
S - 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

public interface Action<I,O,S> extends Registerable
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 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

      O run(ActionContext ctx, I input) throws GenkitException
      Runs the action with the given input.
      Parameters:
      ctx - the action context
      input - the input to the action
      Returns:
      the output of the action
      Throws:
      GenkitException - if the action fails
    • run

      O run(ActionContext ctx, I input, Consumer<S> streamCallback) throws GenkitException
      Runs the action with the given input and streaming callback.
      Parameters:
      ctx - the action context
      input - the input to the action
      streamCallback - 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 context
      input - the JSON input
      streamCallback - 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 context
      input - the JSON input
      streamCallback - callback for receiving streaming JSON chunks, may be null
      Returns:
      the action result including telemetry data
      Throws:
      GenkitException - if the action fails
    • getInputSchema

      Map<String,Object> getInputSchema()
      Returns the JSON schema for the action's input type.
      Returns:
      the input schema as a map, or null if not defined
    • getOutputSchema

      Map<String,Object> getOutputSchema()
      Returns the JSON schema for the action's output type.
      Returns:
      the output schema as a map, or null if not defined
    • getMetadata

      Map<String,Object> getMetadata()
      Returns additional metadata for the action.
      Returns:
      the metadata map