Class GenkitBeta

java.lang.Object
com.google.genkit.GenkitBeta

public final class GenkitBeta extends Object
Beta (experimental) API surface for Genkit.

This is the ergonomic, user-facing API for defining agents that run as bidi agent actions (so they appear and run in the Dev UI). It mirrors the JavaScript GenkitBeta (defineAgent / definePromptAgent / defineCustomAgent) and the Go WithExperimental gating.

All methods are gated behind the experimental flag (see GenkitOptions.Builder.experimental or the GENKIT_EXPERIMENTAL environment variable). When the flag is not enabled they throw a GenkitException.

Obtain an instance via Genkit.beta().

  • Method Details

    • defineCustomAgent

      public <S> Agent<S> defineCustomAgent(CustomAgentConfig<S> config, AgentFn<S> fn)
      Defines a custom agent from an explicit CustomAgentConfig and AgentFn.

      This is the lowest-level beta agent factory: the caller supplies the per-turn logic directly. The agent is registered as a bidi /agent/<name> action (plus companion snapshot/abort actions when a store is configured).

      Type Parameters:
      S - the custom session state type
      Parameters:
      config - the custom agent configuration
      fn - the per-turn agent function
      Returns:
      the registered agent
      Throws:
      GenkitException - if experimental features are not enabled
    • defineAgent

      public <S> Agent<S> defineAgent(AgentConfig<S> config)
      Defines an ergonomic, prompt-backed agent.

      This is the ai.defineAgent({name, system, tools, model, store}) entry point. It builds a CustomAgentConfig from the facade config and synthesizes an AgentFn that, for each turn, calls generateStream with the configured system prompt + tools and the session history (which already includes the just-added user message), streams model chunks back to the caller, and returns the model's response message as the turn result.

      Type Parameters:
      S - the custom session state type
      Parameters:
      config - the agent configuration (name required)
      Returns:
      the registered agent
      Throws:
      GenkitException - if experimental features are not enabled
    • definePromptAgent

      public <S> Agent<S> definePromptAgent(AgentConfig<S> config)
      Defines an agent backed by a registered prompt.

      The agent's system instructions are produced by rendering the named prompt's Handlebars template on every turn: the prompt named by config.getPromptName() (falling back to config.getName()) is loaded once via Genkit.prompt(String), and each turn its template is rendered with config.getPromptInput() merged with the current session state (see renderPromptSystem(com.google.genkit.prompt.ExecutablePrompt<java.util.Map<java.lang.String, java.lang.Object>>, com.google.genkit.agent.AgentConfig<?>, com.google.genkit.ai.agent.SessionRunner<?>)). This means template variables such as {{topic}} interpolate the live promptInput/state values for that turn rather than leaking through as raw {{...}} placeholders.

      If no matching prompt can be loaded (or its template is blank), this falls back to config.getSystem(), behaving like defineAgent(com.google.genkit.agent.AgentConfig).

      Type Parameters:
      S - the custom session state type
      Parameters:
      config - the agent configuration (name required)
      Returns:
      the registered agent
      Throws:
      GenkitException - if experimental features are not enabled