Class GenerateParams
GenerationMiddleware.wrapGenerate(com.google.genkit.core.ActionContext, com.google.genkit.ai.middleware.GenerateParams, com.google.genkit.ai.middleware.GenerateNext) hook.
The request is a GenerateActionOptions — the high-level generate options that
have not yet been resolved to a ModelRequest. This
allows wrapGenerate middleware to modify values such as the model name, tool list, or
output format before resolution occurs.
This mirrors the JS SDK where the generate middleware hook receives
GenerateActionOptions (high-level), while the model middleware hook receives
GenerateRequest/ModelRequest (low-level, resolved).
-
Constructor Summary
ConstructorsConstructorDescriptionGenerateParams(GenerateActionOptions request, int iteration) Creates GenerateParams with messageIndex defaulting to the message count in the request.GenerateParams(GenerateActionOptions request, int iteration, int messageIndex) Creates GenerateParams.GenerateParams(GenerateActionOptions request, int iteration, int messageIndex, Consumer<ModelResponseChunk> onChunk) Creates GenerateParams with all fields including streaming callback. -
Method Summary
Modifier and TypeMethodDescriptionintReturns the current tool-loop iteration (0-indexed), equivalent to JScurrentTurn.intReturns the current message index — the position in the conversation that the next model response will occupy.Returns the streaming chunk callback, ornullif this is a non-streaming request.Returns the current high-level generate options.withMessageIndex(int messageIndex) Returns a new GenerateParams with the given messageIndex, preserving other fields.withOnChunk(Consumer<ModelResponseChunk> onChunk) Returns a new GenerateParams with the given onChunk callback, preserving other fields.withRequest(GenerateActionOptions request) Returns a new GenerateParams with the given request, preserving other fields.
-
Constructor Details
-
GenerateParams
Creates GenerateParams.- Parameters:
request- the current high-level generate options for this iterationiteration- the current tool-loop iteration (0-indexed)messageIndex- the current message index in the conversation (position the next model response will occupy). This mirrors the JS SDK'smessageIndexand is useful for streaming chunk attribution and middleware that tracks conversation position.
-
GenerateParams
public GenerateParams(GenerateActionOptions request, int iteration, int messageIndex, Consumer<ModelResponseChunk> onChunk) Creates GenerateParams with all fields including streaming callback.- Parameters:
request- the current high-level generate options for this iterationiteration- the current tool-loop iteration (0-indexed)messageIndex- the current message indexonChunk- the streaming chunk callback, or null if not streaming. Mirrors the JS SDK'sonChunkin the generate middleware hook, allowing middleware to observe or transform streaming chunks.
-
GenerateParams
Creates GenerateParams with messageIndex defaulting to the message count in the request.- Parameters:
request- the current high-level generate options for this iterationiteration- the current tool-loop iteration (0-indexed)
-
-
Method Details
-
getRequest
Returns the current high-level generate options.Unlike
ModelParams.getRequest(), which returns a resolvedModelRequest, this returns the unresolvedGenerateActionOptionscontaining the model name as a string, tool names as string references, etc. -
getIteration
public int getIteration()Returns the current tool-loop iteration (0-indexed), equivalent to JScurrentTurn. -
getMessageIndex
public int getMessageIndex()Returns the current message index — the position in the conversation that the next model response will occupy. Starts at 0 and increments as messages are added (model responses, tool responses, etc.). Equivalent to the JS SDK'smessageIndex. -
getOnChunk
Returns the streaming chunk callback, ornullif this is a non-streaming request.Mirrors the JS SDK's
onChunkin the generate middleware hook. When non-null, the model will be called with streaming enabled and each chunk will be forwarded through this callback. Middleware can wrap or replace the callback to observe/transform streaming chunks. -
withRequest
Returns a new GenerateParams with the given request, preserving other fields. -
withMessageIndex
Returns a new GenerateParams with the given messageIndex, preserving other fields. -
withOnChunk
Returns a new GenerateParams with the given onChunk callback, preserving other fields.
-