Class SimulateSystemPromptMiddleware
java.lang.Object
com.google.genkit.ai.middleware.BaseGenerationMiddleware
com.google.genkit.plugins.middleware.SimulateSystemPromptMiddleware
- All Implemented Interfaces:
GenerationMiddleware
Rewrites a
system message into a user/model exchange, for models that do not natively
support system prompts.
Wraps the wrapGenerate hook: each system message is replaced by a user
message (SimulateSystemPromptMiddleware.Options.preface followed by the original system content) and a model
message (SimulateSystemPromptMiddleware.Options.acknowledgement). Non-system messages are passed through unchanged.
Mirrors the JS simulateSystemPrompt model middleware.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classConfiguration parameters forSimulateSystemPromptMiddleware. -
Constructor Summary
ConstructorsConstructorDescription -
Method Summary
Modifier and TypeMethodDescriptionname()Returns the middleware's unique identifier.Returns a fresh instance for eachgenerate()call, enabling per-invocation state.wrapGenerate(ActionContext ctx, GenerateParams params, GenerateNext next) Wraps each iteration of the generate tool loop.Methods inherited from class com.google.genkit.ai.middleware.BaseGenerationMiddleware
tools, wrapModel, wrapTool
-
Constructor Details
-
SimulateSystemPromptMiddleware
-
-
Method Details
-
name
Description copied from interface:GenerationMiddlewareReturns the middleware's unique identifier. -
newInstance
Description copied from interface:GenerationMiddlewareReturns a fresh instance for eachgenerate()call, enabling per-invocation state.Stable state (e.g., API keys, configuration) should be preserved. Per-request state (e.g., counters) should be reset.
-
wrapGenerate
public ModelResponse wrapGenerate(ActionContext ctx, GenerateParams params, GenerateNext next) throws GenkitException Description copied from interface:GenerationMiddlewareWraps each iteration of the generate tool loop.- Specified by:
wrapGeneratein interfaceGenerationMiddleware- Overrides:
wrapGeneratein classBaseGenerationMiddleware- Parameters:
ctx- the action contextparams- the generate parameters including the current request and iterationnext- the next function in the chain- Returns:
- the model response
- Throws:
GenkitException- if processing fails
-