Class GenkitBeta
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 Summary
Modifier and TypeMethodDescription<S> Agent<S> defineAgent(AgentConfig<S> config) Defines an ergonomic, prompt-backed agent.<S> Agent<S> defineCustomAgent(CustomAgentConfig<S> config, AgentFn<S> fn) Defines a custom agent from an explicitCustomAgentConfigandAgentFn.<S> Agent<S> definePromptAgent(AgentConfig<S> config) Defines an agent backed by a registered prompt.
-
Method Details
-
defineCustomAgent
Defines a custom agent from an explicitCustomAgentConfigandAgentFn.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 configurationfn- the per-turn agent function- Returns:
- the registered agent
- Throws:
GenkitException- if experimental features are not enabled
-
defineAgent
Defines an ergonomic, prompt-backed agent.This is the
ai.defineAgent({name, system, tools, model, store})entry point. It builds aCustomAgentConfigfrom the facade config and synthesizes anAgentFnthat, for each turn, callsgenerateStreamwith 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 (namerequired)- Returns:
- the registered agent
- Throws:
GenkitException- if experimental features are not enabled
-
definePromptAgent
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 toconfig.getName()) is loaded once viaGenkit.prompt(String), and each turn its template is rendered withconfig.getPromptInput()merged with the current session state (seerenderPromptSystem(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 livepromptInput/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 likedefineAgent(com.google.genkit.agent.AgentConfig).- Type Parameters:
S- the custom session state type- Parameters:
config- the agent configuration (namerequired)- Returns:
- the registered agent
- Throws:
GenkitException- if experimental features are not enabled
-