Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
ec420d4
feat: middlewareV2
xavidop Mar 29, 2026
af6c77b
fix: code assist feedback
xavidop Mar 29, 2026
ef9de78
fix: use Part instead of ToolResponse
xavidop Apr 13, 2026
26034f2
chore(deps)(deps): bump com.google.cloud:google-cloud-trace
dependabot[bot] Mar 23, 2026
37266f1
chore(deps)(deps): bump aws.sdk.version from 2.42.13 to 2.42.18
dependabot[bot] Mar 23, 2026
8fd5c72
chore(deps)(deps): bump jackson.version from 2.21.1 to 2.21.2
dependabot[bot] Mar 23, 2026
f68a889
chore(deps)(deps): bump spring-boot.version from 4.0.3 to 4.0.4
dependabot[bot] Mar 23, 2026
3883284
chore(deps)(deps): bump com.google.genai:google-genai
dependabot[bot] Mar 23, 2026
3765fee
chore(deps)(deps): bump com.google.cloud:google-cloud-logging
dependabot[bot] Mar 23, 2026
b7cbb84
chore(deps)(deps): bump com.google.cloud:google-cloud-monitoring
dependabot[bot] Mar 23, 2026
dcde400
chore(deps)(deps): bump com.google.genai:google-genai
dependabot[bot] Mar 30, 2026
0a8a296
chore(deps)(deps): bump com.puppycrawl.tools:checkstyle
dependabot[bot] Mar 30, 2026
2d75769
chore(deps)(deps): bump google-cloud-firestore.version
dependabot[bot] Mar 30, 2026
f04958f
chore(deps)(deps): bump aws.sdk.version from 2.42.18 to 2.42.23
dependabot[bot] Mar 30, 2026
15567a4
chore(deps)(deps): bump spring-boot.version from 4.0.4 to 4.0.5
dependabot[bot] Mar 30, 2026
3df5dc9
chore(deps)(deps): bump io.modelcontextprotocol.sdk:mcp
dependabot[bot] Mar 30, 2026
6c9bb8e
feat: new main page
xavidop Mar 30, 2026
6f3572f
fix: build
xavidop Mar 30, 2026
3ecd7c5
fix: more docs fixes
xavidop Mar 30, 2026
f5baf84
feat: add configuration for maven
xavidop Mar 31, 2026
9d55f0c
feat: agent skills
xavidop Apr 2, 2026
2520df3
feat: add google search console
xavidop Apr 2, 2026
b3f41ad
feat: google analytics
xavidop Apr 2, 2026
4d52b40
fix: you dont need to call genkit.init()
xavidop Apr 3, 2026
70ef2cd
fix: update prints with correct paths
xavidop Apr 3, 2026
6a7ceaf
chore(deps): bump defu
dependabot[bot] Apr 4, 2026
7837585
chore(deps)(deps): bump io.pinecone:pinecone-client from 6.1.0 to 6.2.0
dependabot[bot] Apr 6, 2026
dd62f81
chore(deps)(deps): bump aws.sdk.version from 2.42.23 to 2.42.28
dependabot[bot] Apr 6, 2026
e66193e
chore(ci): bump actions/upload-pages-artifact from 3 to 4
dependabot[bot] Apr 6, 2026
bbc30f7
chore(ci): bump actions/setup-node from 4 to 6
dependabot[bot] Apr 6, 2026
cedab1d
chore(ci): bump actions/deploy-pages from 4 to 5
dependabot[bot] Apr 6, 2026
5e5ce64
chore(deps)(deps): bump com.google.genai:google-genai
dependabot[bot] Apr 6, 2026
7bc87e1
chore(ci): bump actions/checkout from 4 to 6
dependabot[bot] Apr 6, 2026
af000c6
chore(ci): bump actions/setup-java from 4 to 5
dependabot[bot] Apr 6, 2026
ccb6188
chore(deps): bump vite
dependabot[bot] Apr 7, 2026
0583a0f
chore(deps)(deps): bump opentelemetry.version from 1.60.1 to 1.61.0
dependabot[bot] Apr 13, 2026
733485f
chore(deps)(deps): bump com.google.genai:google-genai
dependabot[bot] Apr 13, 2026
247120f
chore(deps)(deps): bump aws.sdk.version from 2.42.28 to 2.42.33
dependabot[bot] Apr 13, 2026
de8fb11
chore(deps)(deps): bump com.google.cloud:google-cloud-logging
dependabot[bot] Apr 13, 2026
f0b9b1c
chore(deps)(deps): bump com.google.cloud.functions:functions-framewor…
dependabot[bot] Apr 13, 2026
26893b3
chore(deps)(deps-dev): bump com.google.cloud.functions:function-maven…
dependabot[bot] Apr 13, 2026
e7b1ea5
chore(deps)(deps): bump com.google.cloud:google-cloud-trace
dependabot[bot] Apr 13, 2026
d1722c0
chore(deps)(deps): bump com.google.cloud:google-cloud-monitoring
dependabot[bot] Apr 13, 2026
97cbb24
fix: V2 feedback
xavidop Mar 29, 2026
11d70c3
fix: ffedback and refactored the code to work with both
xavidop Apr 13, 2026
897749a
fix: refleciton v1 fix
xavidop Apr 13, 2026
d95d65c
fix: deps
xavidop Apr 13, 2026
20f1893
fix: license
xavidop Apr 13, 2026
b88a7d4
fix: continue lifecycle after an interrupts
xavidop Apr 13, 2026
63d4181
Merge branch 'main' into xavier/middleware-v2
xavidop Apr 13, 2026
52a9441
feat: udpated docs
xavidop Apr 13, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ node_modules
*.log
hs_err_pid*
samples/google-genai/generated_media/
.astro
42 changes: 40 additions & 2 deletions ai/src/main/java/com/google/genkit/ai/GenerateOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

package com.google.genkit.ai;

import com.google.genkit.ai.middleware.GenerationMiddleware;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand All @@ -43,6 +44,7 @@ public class GenerateOptions<T> {
private final Integer maxTurns;
private final ResumeOptions resume;
private final Class<T> outputClass;
private final List<GenerationMiddleware> use;

/**
* Creates new GenerateOptions.
Expand Down Expand Up @@ -74,7 +76,8 @@ public GenerateOptions(
Map<String, Object> context,
Integer maxTurns,
ResumeOptions resume,
Class<T> outputClass) {
Class<T> outputClass,
List<GenerationMiddleware> use) {
this.model = model;
this.prompt = prompt;
this.messages = messages;
Expand All @@ -88,6 +91,7 @@ public GenerateOptions(
this.maxTurns = maxTurns;
this.resume = resume;
this.outputClass = outputClass;
this.use = use;
}

/**
Expand Down Expand Up @@ -286,6 +290,15 @@ public Class<T> getOutputClass() {
return outputClass;
}

/**
* Gets the V2 middleware to apply to this generation.
*
* @return the middleware list, or null if not set
*/
public List<GenerationMiddleware> getUse() {
return use;
}

/**
* Builder for GenerateOptions.
*
Expand All @@ -305,6 +318,7 @@ public static class Builder<T> {
private Integer maxTurns;
private ResumeOptions resume;
private Class<T> outputClass;
private List<GenerationMiddleware> use;

public Builder<T> model(String model) {
this.model = model;
Expand Down Expand Up @@ -407,6 +421,29 @@ public Builder<T> resume(ResumeOptions resume) {
return this;
}

/**
* Sets V2 middleware to apply to this generation. Middleware hooks wrap the generate loop,
* model calls, and tool executions.
*
* @param use the middleware to apply
* @return this builder
*/
public Builder<T> use(List<GenerationMiddleware> use) {
this.use = use;
return this;
}

/**
* Sets V2 middleware to apply to this generation.
*
* @param middleware the middleware to apply
* @return this builder
*/
public Builder<T> use(GenerationMiddleware... middleware) {
this.use = List.of(middleware);
return this;
}

public GenerateOptions<T> build() {
return new GenerateOptions<>(
model,
Expand All @@ -421,7 +458,8 @@ public GenerateOptions<T> build() {
context,
maxTurns,
resume,
outputClass);
outputClass,
use);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* Copyright 2025 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/

package com.google.genkit.ai.middleware;

import com.google.genkit.ai.ModelResponse;
import com.google.genkit.ai.Part;
import com.google.genkit.ai.Tool;
import com.google.genkit.core.ActionContext;
import com.google.genkit.core.GenkitException;
import java.util.Collections;
import java.util.List;

/**
* BaseGenerationMiddleware provides default pass-through implementations for all three hooks.
* Extend this class and override only the hooks you need.
*
* <p>Example:
*
* <pre>{@code
* public class TimingMiddleware extends BaseGenerationMiddleware {
* @Override
* public String name() { return "timing"; }
*
* @Override
* public GenerationMiddleware newInstance() { return new TimingMiddleware(); }
*
* @Override
* public ModelResponse wrapModel(ActionContext ctx, ModelParams params, ModelNext next)
* throws GenkitException {
* long start = System.currentTimeMillis();
* ModelResponse resp = next.apply(ctx, params);
* System.out.println("Model call took " + (System.currentTimeMillis() - start) + "ms");
* return resp;
* }
* }
* }</pre>
*/
public abstract class BaseGenerationMiddleware implements GenerationMiddleware {

@Override
public ModelResponse wrapGenerate(ActionContext ctx, GenerateParams params, GenerateNext next)
throws GenkitException {
return next.apply(ctx, params);
}

@Override
public ModelResponse wrapModel(ActionContext ctx, ModelParams params, ModelNext next)
throws GenkitException {
return next.apply(ctx, params);
}

@Override
public Part wrapTool(ActionContext ctx, ToolParams params, ToolNext next) throws GenkitException {
return next.apply(ctx, params);
}

@Override
public List<Tool<?, ?>> tools() {
return Collections.emptyList();
}
}
38 changes: 38 additions & 0 deletions ai/src/main/java/com/google/genkit/ai/middleware/GenerateNext.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright 2025 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/

package com.google.genkit.ai.middleware;

import com.google.genkit.ai.ModelResponse;
import com.google.genkit.core.ActionContext;
import com.google.genkit.core.GenkitException;

/** Next function in the {@link GenerationMiddleware#wrapGenerate} hook chain. */
@FunctionalInterface
public interface GenerateNext {

/**
* Calls the next handler in the generate chain.
*
* @param ctx the action context
* @param params the generate parameters
* @return the model response
* @throws GenkitException if processing fails
*/
ModelResponse apply(ActionContext ctx, GenerateParams params) throws GenkitException;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright 2025 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/

package com.google.genkit.ai.middleware;

import com.google.genkit.ai.ModelRequest;

/** Holds parameters for the {@link GenerationMiddleware#wrapGenerate} hook. */
public class GenerateParams {

private final ModelRequest request;
private final int iteration;

/**
* Creates GenerateParams.
*
* @param request the current model request for this iteration
* @param iteration the current tool-loop iteration (0-indexed)
*/
public GenerateParams(ModelRequest request, int iteration) {
this.request = request;
this.iteration = iteration;
}

/** Returns the current model request with accumulated messages. */
public ModelRequest getRequest() {
return request;
}

/** Returns the current tool-loop iteration (0-indexed). */
public int getIteration() {
return iteration;
}

/** Returns a new GenerateParams with the given request, preserving the iteration. */
public GenerateParams withRequest(ModelRequest request) {
return new GenerateParams(request, this.iteration);
}
}
Loading
Loading