defineAgent<CustomOptions, Input, State> method

Agent<State> defineAgent<CustomOptions, Input, State>({
  1. required String name,
  2. String? variant,
  3. ModelRef<CustomOptions>? model,
  4. CustomOptions? config,
  5. String? description,
  6. SchemanticType<Input>? inputSchema,
  7. String? system,
  8. List<Part>? systemParts,
  9. String? prompt,
  10. List<Part>? promptParts,
  11. List<Message>? messages,
  12. String? messagesTemplate,
  13. GenerateActionOutputConfig? output,
  14. int? maxTurns,
  15. bool? returnToolRequests,
  16. Map<String, dynamic>? metadata,
  17. List<Tool>? tools,
  18. List<String>? toolNames,
  19. String? toolChoice,
  20. List<GenerateMiddlewareRef>? use,
  21. Map<String, dynamic>? promptInput,
  22. SchemanticType<State>? stateSchema,
  23. SessionStore? store,
  24. ClientTransform? clientTransform,
})

Defines and registers an agent by creating a prompt and wiring it into a multi-turn agent in one step.

This is a convenience shortcut for calling Genkit.definePrompt followed by definePromptAgent.

Implementation

Agent<State> defineAgent<CustomOptions, Input, State>({
  required String name,
  String? variant,
  ModelRef<CustomOptions>? model,
  CustomOptions? config,
  String? description,
  SchemanticType<Input>? inputSchema,
  String? system,
  List<Part>? systemParts,
  String? prompt,
  List<Part>? promptParts,
  List<Message>? messages,
  String? messagesTemplate,
  GenerateActionOutputConfig? output,
  int? maxTurns,
  bool? returnToolRequests,
  Map<String, dynamic>? metadata,
  List<Tool>? tools,
  List<String>? toolNames,
  String? toolChoice,
  List<GenerateMiddlewareRef>? use,

  /// Supplies values for the prompt's input variables, so a single prompt
  /// can be reused and customized by multiple agents.
  Map<String, dynamic>? promptInput,

  /// Optional schema describing the shape of the custom session state. When
  /// provided, `chat().state` / `res.state` return parsed `State` instances.
  SchemanticType<State>? stateSchema,
  SessionStore? store,
  ClientTransform? clientTransform,
}) {
  // Register the prompt.
  definePrompt<CustomOptions, Input>(
    name: name,
    variant: variant,
    model: model,
    config: config,
    description: description,
    inputSchema: inputSchema,
    system: system,
    systemParts: systemParts,
    prompt: prompt,
    promptParts: promptParts,
    messages: messages,
    messagesTemplate: messagesTemplate,
    output: output,
    maxTurns: maxTurns,
    returnToolRequests: returnToolRequests,
    metadata: metadata,
    tools: tools,
    toolNames: toolNames,
    toolChoice: toolChoice,
    use: use,
  );

  // Wire it into a prompt agent.
  return agent_lib.definePromptAgent<State>(
    registry,
    promptName: variant != null ? '$name.$variant' : name,
    promptInput: promptInput,
    stateSchema: stateSchema,
    store: store,
    clientTransform: clientTransform,
  );
}