Skip to content

Commit 31e3640

Browse files
authored
Merge pull request #148 from joreilly/adk_web
support for ADK Web dev UI
2 parents af787dd + 801e0f1 commit 31e3640

File tree

3 files changed

+56
-31
lines changed

3 files changed

+56
-31
lines changed

agents/build.gradle.kts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
plugins {
22
alias(libs.plugins.kotlinJvm)
3-
application
43
}
54

65
dependencies {
76
implementation(libs.mcp.kotlin)
87
implementation(libs.koin.core)
98
implementation("ai.koog:koog-agents:0.2.1")
10-
implementation("org.slf4j:slf4j-simple:2.0.17")
9+
//implementation("org.slf4j:slf4j-simple:2.0.17")
1110
implementation("com.google.adk:google-adk:0.1.0")
11+
implementation("com.google.adk:google-adk-dev:0.1.0")
12+
13+
// following needed for AdkWebServer (dev UI)
14+
implementation("org.apache.httpcomponents.client5:httpclient5:5.4.3")
15+
1216
implementation(projects.composeApp)
1317
}
1418

@@ -18,8 +22,11 @@ java {
1822
}
1923
}
2024

21-
application {
22-
mainClass = "MainKt"
25+
tasks.register<JavaExec>("devUi") {
26+
group = "application"
27+
description = "Start the ADK Dev UI server"
28+
mainClass.set("com.google.adk.web.AdkWebServer")
29+
classpath = sourceSets["main"].runtimeClasspath
30+
args = listOf("--adk.agents.source-dir=src/main/java")
2331
}
2432

25-

agents/src/main/java/Agent.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import com.google.adk.agents.BaseAgent;
2+
3+
import static adk.ClimateTraceAgent.initAgent;
4+
5+
6+
public class Agent {
7+
public static BaseAgent ROOT_AGENT = initAgent();
8+
}
9+
Lines changed: 35 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package adk
22

3+
import adk.ClimateTraceAgent.Companion.initAgent
34
import com.google.adk.agents.BaseAgent
45
import com.google.adk.agents.LlmAgent
56
import com.google.adk.events.Event
@@ -17,45 +18,52 @@ import kotlin.jvm.optionals.getOrNull
1718
const val USER_ID = "MainUser"
1819
const val NAME = "ClimateTrace Agent"
1920

20-
val ROOT_AGENT: BaseAgent = initAgent()
2121

22-
fun initAgent(): BaseAgent {
23-
val apiKeyGoogle = ""
22+
class ClimateTraceAgent {
23+
companion object {
24+
@JvmStatic
25+
fun initAgent(): BaseAgent {
26+
val apiKeyGoogle = ""
2427

25-
val mcpTools = McpToolset(
26-
ServerParameters
27-
.builder("java")
28-
.args("-jar", "./mcp-server/build/libs/serverAll.jar", "--stdio")
29-
.build()
30-
).loadTools().join()
28+
val mcpTools = McpToolset(
29+
ServerParameters
30+
.builder("java")
31+
.args("-jar", "/Users/joreilly/dev/github/ClimateTraceKMP/mcp-server/build/libs/serverAll.jar", "--stdio")
32+
.build()
33+
).loadTools().join()
3134

32-
val model = Gemini(
33-
"gemini-1.5-pro",
34-
Client.builder()
35-
.apiKey(apiKeyGoogle)
36-
.build()
37-
)
35+
val model = Gemini(
36+
"gemini-1.5-pro",
37+
Client.builder()
38+
.apiKey(apiKeyGoogle)
39+
.build()
40+
)
3841

39-
return LlmAgent.builder()
40-
.name(NAME)
41-
.model(model)
42-
.description("Agent to answer climate emissions related questions.")
43-
.tools(mcpTools)
44-
.build()
42+
return LlmAgent.builder()
43+
.name(NAME)
44+
.model(model)
45+
.description("Agent to answer climate emissions related questions.")
46+
.instruction("You are an agent that provides climate emissions related information. Use 3 letter country codes.")
47+
.tools(mcpTools)
48+
.build()
49+
}
50+
51+
}
4552
}
4653

54+
4755
fun main() {
48-
val runner = InMemoryRunner(ROOT_AGENT)
56+
val runner = InMemoryRunner(initAgent())
4957
val session = runner
5058
.sessionService()
5159
.createSession(NAME, USER_ID)
5260
.blockingGet()
5361

5462
val prompt =
5563
"""
56-
Get emission data for France and Germany for 2023 and 2024.
57-
Use units of millions for the emissions data.
58-
""".trimIndent()
64+
Get emission data for France and Germany for 2023 and 2024.
65+
Use units of millions for the emissions data.
66+
""".trimIndent()
5967

6068
val userMsg = Content.fromParts(Part.fromText(prompt))
6169
val events = runner.runAsync(USER_ID, session.id(), userMsg)
@@ -70,4 +78,5 @@ fun main() {
7078
println("error: ${event.errorCode().get()}, ${event.errorMessage().get()}")
7179
}
7280
})
73-
}
81+
}
82+

0 commit comments

Comments
 (0)