Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 11 additions & 0 deletions contrib/kotlin/llm-auditor/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Copy this file to .env and fill it in. Real environment variables take
# precedence over .env.

# Gemini via Vertex AI. Set GOOGLE_GENAI_USE_VERTEXAI=False and GOOGLE_API_KEY
# instead to use the Gemini API.
GOOGLE_GENAI_USE_VERTEXAI=True
GOOGLE_CLOUD_PROJECT=<TODO: update-this-value>
GOOGLE_CLOUD_LOCATION=global
GOOGLE_API_KEY=<TODO: update-this-value>

MODEL_NAME=gemini-flash-latest

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[MAJOR] Perhaps we should use the default gemini-3.7-flash instead of gemini-flash-latest here and in two other places, as recommended in AGENTS.md:40?

Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ not paste confidential content into it.

## Where to run things

All commands run from this directory (`core/kotlin/llm-auditor`). Requires
All commands run from this directory (`contrib/kotlin/llm-auditor`). Requires
JDK 17+ and `GOOGLE_API_KEY`.

| Task | Command |
Expand Down
50 changes: 50 additions & 0 deletions contrib/kotlin/llm-auditor/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Copyright 2026 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
#
# https://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.

# Build: compile the agent and collect its runtime dependencies.
FROM gradle:9.5.1-jdk17 AS build

WORKDIR /build

COPY settings.gradle.kts build.gradle.kts ./
COPY src ./src
RUN gradle installDist --no-daemon --quiet

# Run: JRE only, no Gradle.
FROM eclipse-temurin:17-jre

WORKDIR /app

COPY --from=build /build/build/install/llm-auditor/lib ./lib

# Operators supply .env or environment variables at deploy time. The agent reads
# them lazily via Models.fromEnvironment(), so the server starts without creds
# and surfaces missing config on the first request instead of at boot.

RUN useradd --create-home --uid 10001 appuser && \
chown -R appuser:appuser /app

USER appuser

# WebMain binds HOST:PORT. 0.0.0.0 makes the dev server reachable from
# outside the container; it defaults to 127.0.0.1 otherwise.
ENV HOST=0.0.0.0
ENV PORT=8080
# MODEL_NAME is required at startup. Not a credential — just the recipe's
# default model identifier (matches .env.example). Operators override with
# `-e MODEL_NAME=...` at deploy time.
ENV MODEL_NAME=gemini-flash-latest
EXPOSE 8080

CMD ["java", "-cp", "lib/*", "com.google.adk.samples.agents.llmauditor.WebMainKt"]
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ llm-auditor/
1. Clone the repository and navigate to the agent directory:

```bash
cd core/kotlin/llm-auditor
cd contrib/kotlin/llm-auditor
```

2. Set your Gemini API key as an environment variable:
Expand Down
52 changes: 52 additions & 0 deletions contrib/kotlin/llm-auditor/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import org.jetbrains.kotlin.gradle.dsl.JvmTarget

plugins {
kotlin("jvm") version "2.3.20"
application
}

repositories {
mavenCentral()
}

// Both adk-kotlin artifacts must resolve to the same version, so they are
// pinned together.
val adkVersion = "1.2.0"

dependencies {
implementation("com.google.adk:google-adk-kotlin-core:$adkVersion")
implementation("com.google.adk:google-adk-kotlin-webserver:$adkVersion")

testImplementation(kotlin("test"))
}

// Target Java 17 bytecode without pinning a toolchain, so the build runs on
// any JDK 17 or later.
java {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}

kotlin {
compilerOptions {
jvmTarget.set(JvmTarget.JVM_17)
}
}

application {
mainClass.set(
project.findProperty("mainClass") as? String
?: "com.google.adk.samples.agents.llmauditor.MainKt",
)
}

tasks.test {
useJUnitPlatform()
// The test never calls the model; it only needs MODEL_NAME to build the
// agent graph.
environment("MODEL_NAME", "gemini-flash-latest")

Check notice on line 47 in contrib/kotlin/llm-auditor/build.gradle.kts

View workflow job for this annotation

GitHub Actions / Check recipe structure and content

Possible hardcoded model name "gemini-flash-latest" detected. If this is a model identifier, consider using an environment variable instead.
}

tasks.named<JavaExec>("run") {
standardInput = System.`in`
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
type: "standalone" # Options: [standalone | module]
status: "active" # Options: [active | inactive]
language: "kotlin" # Options: [python | java | go | kotlin | typescript]
deployable: true
description: "A sequential multi-agent pipeline that fact-checks LLM-generated answers: a critic verifies each claim with Google Search, then a reviser minimally edits the answer to correct inaccuracies."

architecture:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ package com.google.adk.samples.agents.llmauditor

import com.google.adk.kt.agents.Instruction
import com.google.adk.kt.agents.LlmAgent
import com.google.adk.kt.models.Gemini
import com.google.adk.kt.models.Model
import com.google.adk.kt.tools.GoogleSearchTool

/**
* Creates the critic sub-agent that fact-checks LLM responses using Google
* Search. It identifies claims, verifies them against external sources, and
* produces a structured audit report with verdicts for each claim.
*/
fun createCriticAgent(model: Gemini): LlmAgent =
fun createCriticAgent(model: Model): LlmAgent =
LlmAgent(
name = "critic_agent",
description = "Fact-checks claims in an answer using Google Search.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package com.google.adk.samples.agents.llmauditor

import com.google.adk.kt.agents.SequentialAgent
import com.google.adk.kt.models.Gemini

/**
* The LLM Auditor is a sequential multi-agent pipeline that fact-checks
Expand All @@ -29,7 +28,7 @@ import com.google.adk.kt.models.Gemini
* minimally edits the answer to correct any inaccuracies.
*/
object LlmAuditorAgent {
private val model = Gemini(name = "gemini-flash-latest")
private val model = Models.fromEnvironment()

@JvmField
val rootAgent =
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* Copyright 2026 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
*
* https://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.
*/

package com.google.adk.samples.agents.llmauditor

import com.google.adk.kt.models.Gemini
import com.google.adk.kt.models.LlmRequest
import com.google.adk.kt.models.LlmResponse
import com.google.adk.kt.models.Model
import com.google.adk.kt.models.VertexCredentials
import kotlinx.coroutines.flow.Flow
import java.io.File

/** Resolves the Gemini model shared by every agent from the environment or `.env`. */
internal object Models {
/**
* Returns the model named by `MODEL_NAME`. Its client is created on first use: creating a
* Vertex AI client looks up credentials, so doing it while the agent loads would fail the whole
* server when credentials are missing, instead of the first request.
*/
fun fromEnvironment(): Model {
val name =
env("MODEL_NAME")
?: error("MODEL_NAME is not set. Copy .env.example to .env and fill it in, or export MODEL_NAME.")
return LazyModel(name) {
if (env("GOOGLE_GENAI_USE_VERTEXAI").toBoolean()) {
val project =
env("GOOGLE_CLOUD_PROJECT")
?: error("GOOGLE_CLOUD_PROJECT is not set. Set it in .env or the environment to use Vertex AI.")
// A null location lets the SDK use its default, "global".
Gemini(name, VertexCredentials(project, env("GOOGLE_CLOUD_LOCATION")))
} else {
Gemini(name, env("GOOGLE_API_KEY"))
}
}
}

// Reads .env from the working directory. Real environment variables take
// precedence, and a missing .env is fine (e.g. on Cloud Run).
private val dotenv: Map<String, String> by lazy {
val file = File(".env")
if (!file.isFile) return@lazy emptyMap()
file
.readLines()
.map { it.substringBefore(" #").trim() }
.filter { it.isNotEmpty() && !it.startsWith("#") && "=" in it }
.associate { it.substringBefore("=").trim() to it.substringAfter("=").trim() }
}

/**
* Returns a variable from the environment or `.env`, or null if it is unset, blank, or still an
* unfilled `.env.example` placeholder.
*/
private fun env(key: String): String? =
(System.getenv(key) ?: dotenv[key])?.trim()?.takeUnless { it.isEmpty() || it.startsWith("<TODO") }

private class LazyModel(
override val name: String,
create: () -> Model,
) : Model {
private val delegate by lazy(create)

override fun generateContent(
request: LlmRequest,
stream: Boolean,
): Flow<LlmResponse> = delegate.generateContent(request, stream)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ package com.google.adk.samples.agents.llmauditor
import com.google.adk.kt.agents.Instruction
import com.google.adk.kt.agents.LlmAgent
import com.google.adk.kt.callbacks.AfterModelCallback
import com.google.adk.kt.models.Gemini
import com.google.adk.kt.models.LlmResponse
import com.google.adk.kt.models.Model
import com.google.adk.kt.types.Part

/**
Expand Down Expand Up @@ -50,7 +50,7 @@ private val removeEndOfEditMark =
* critic's findings. It minimally edits the original text to correct errors
* while preserving structure and style.
*/
fun createReviserAgent(model: Gemini): LlmAgent =
fun createReviserAgent(model: Model): LlmAgent =
LlmAgent(
name = "reviser_agent",
description = "Revises answers based on the critic's fact-check findings.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,19 @@ import com.google.adk.kt.webserver.AdkServerConfig
import com.google.adk.kt.webserver.dev.AdkDevServer

fun main() {
// inMemory() supplies the agent loader and the session and artifact
// services, holding their state in the process.
val config = AdkServerConfig.inMemory(LlmAuditorAgent.rootAgent)

val config = devServerConfig()
println("Starting ADK dev server on http://${config.host}:${config.port}")
AdkDevServer(config).start(wait = true)
}

/**
* Config for serving the agent. inMemory() supplies the agent loader and the session and artifact
* services, holding their state in the process. It binds 127.0.0.1:8080; HOST and PORT override
* that, so a container can bind 0.0.0.0 on the port it is given.
*/
fun devServerConfig(env: (String) -> String? = System::getenv): AdkServerConfig {
var config = AdkServerConfig.inMemory(LlmAuditorAgent.rootAgent)
env("HOST")?.let { config = config.copy(host = it) }
env("PORT")?.let { config = config.copy(port = it.toInt()) }
return config
}
16 changes: 0 additions & 16 deletions contrib/python/attenu-guard-customer-service/.env.example

This file was deleted.

Loading
Loading