Skip to content

Commit b6c3ab2

Browse files
authored
Add the Koog Android example (#148)
1 parent 0625ee7 commit b6c3ab2

38 files changed

Lines changed: 1441 additions & 1 deletion

.github/dependabot.yml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ updates:
2626
- '/agents/agent-voltagent/'
2727
- '/agents/agent-sdk/'
2828
- '/agents/agent-strands/'
29-
- './agents/agents-langchain/'
29+
- '/agents/agents-langchain/'
3030
- '/basic/cdk/'
3131
- '/basic/app/'
3232
- '/mcp/clients/mastra-mcp-client/'
@@ -55,3 +55,19 @@ updates:
5555
npm:
5656
patterns:
5757
- '*'
58+
59+
- package-ecosystem: gradle
60+
directories:
61+
- '/agents/agent-koog/'
62+
schedule:
63+
interval: daily
64+
timezone: Asia/Tokyo
65+
allow:
66+
- dependency-type: all
67+
rebase-strategy: auto
68+
assignees:
69+
- poad
70+
groups:
71+
gradle:
72+
patterns:
73+
- '*'

.github/workflows/ci.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,29 @@ jobs:
4545
- name: lint
4646
run: pnpm lint
4747

48+
build-android:
49+
50+
runs-on: ubuntu-latest
51+
52+
steps:
53+
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
54+
- name: Set up JDK 17
55+
uses: actions/setup-java@f2beeb24e141e01a676f977032f5a29d81c9e27e # v5.1.0
56+
with:
57+
java-version: 17
58+
distribution: zulu
59+
60+
- uses: actions/cache@9255dc7a253b0ccc959486e2bca901246202afeb # v5.0.1
61+
with:
62+
path: |
63+
~/.gradle/caches
64+
~/.gradle/wrapper
65+
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }}
66+
restore-keys: |
67+
${{ runner.os }}-gradle-
68+
69+
- name: Build with Gradle
70+
working-directory: agents/agent-koog
71+
run: |
72+
chmod +x gradlew
73+
./gradlew assembleDebug -x lint

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,3 +132,5 @@ dist
132132
.env
133133
!.env.local.template
134134
**/tsconfig.tsbuildinfo
135+
136+
.DS_Store

agents/agent-koog/.gitignore

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
*.iml
2+
.kotlin
3+
.gradle
4+
**/build/
5+
xcuserdata
6+
!src/**/build/
7+
local.properties
8+
.idea
9+
.DS_Store
10+
captures
11+
.externalNativeBuild
12+
.cxx
13+
*.xcodeproj/*
14+
!*.xcodeproj/project.pbxproj
15+
!*.xcodeproj/xcshareddata/
16+
!*.xcodeproj/project.xcworkspace/
17+
!*.xcworkspace/contents.xcworkspacedata
18+
**/xcshareddata/WorkspaceSettings.xcsettings
19+
node_modules/

agents/agent-koog/README.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# agent-koog
2+
3+
This is a Kotlin Multiplatform project targeting Android.
4+
5+
- [/composeApp](./composeApp/src) is for code that will be shared across your Compose Multiplatform applications.
6+
It contains several subfolders:
7+
8+
- [commonMain](./composeApp/src/commonMain/kotlin) is for code that’s common for all targets.
9+
- Other folders are for Kotlin code that will be compiled for only the platform indicated in the folder name.
10+
For example, if you want to use Apple’s CoreCrypto for the iOS part of your Kotlin app,
11+
the [iosMain](./composeApp/src/iosMain/kotlin) folder would be the right place for such calls.
12+
Similarly, if you want to edit the Desktop (JVM) specific part, the [jvmMain](./composeApp/src/jvmMain/kotlin)
13+
folder is the appropriate location.
14+
15+
## Build and Run Android Application
16+
17+
To build and run the development version of the Android app, use the run configuration from the run widget
18+
in your IDE’s toolbar or build it directly from the terminal:
19+
20+
- on macOS/Linux
21+
22+
```shell
23+
./gradlew :composeApp:assembleDebug
24+
```
25+
26+
- on Windows
27+
28+
```shell
29+
.\gradlew.bat :composeApp:assembleDebug
30+
```
31+
32+
---
33+
34+
Learn more about [Kotlin Multiplatform](https://www.jetbrains.com/help/kotlin-multiplatform-dev/get-started.html)
35+
36+
## Observability
37+
38+
`$download_url`<https://www.jaegertracing.io/download/> からダウンロードURLを調べて取得したURLに置き換えてください。
39+
40+
```shell
41+
# Jaegerを起動
42+
curl -sSL "$download_url" -o jaeger-2.13.0.tar.gz
43+
tar -xzf jaeger-2.13.0.tar.gz
44+
cd jaeger-2.13.0
45+
COLLECTOR_OTLP_ENABLED=true ./jaeger \
46+
--set=receivers.otlp.protocols.grpc.endpoint=0.0.0.0:4317 \
47+
--set=receivers.otlp.protocols.http.endpoint=0.0.0.0:4318
48+
```
49+
50+
Access to <http://localhost:16686/search>

agents/agent-koog/build.gradle.kts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
plugins {
2+
// this is necessary to avoid the plugins to be loaded multiple times
3+
// in each subproject's classloader
4+
alias(libs.plugins.androidApplication) apply false
5+
alias(libs.plugins.androidLibrary) apply false
6+
alias(libs.plugins.composeMultiplatform) apply false
7+
alias(libs.plugins.composeCompiler) apply false
8+
alias(libs.plugins.kotlinMultiplatform) apply false
9+
}
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
import org.jetbrains.compose.desktop.application.dsl.TargetFormat
2+
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
3+
4+
plugins {
5+
alias(libs.plugins.kotlinMultiplatform)
6+
alias(libs.plugins.androidApplication)
7+
alias(libs.plugins.composeMultiplatform)
8+
alias(libs.plugins.composeCompiler)
9+
10+
// Add Kotlin serialization plugin for Koog API support
11+
kotlin("plugin.serialization") version "2.2.0"
12+
}
13+
14+
kotlin {
15+
androidTarget {
16+
compilerOptions {
17+
jvmTarget.set(JvmTarget.JVM_17)
18+
}
19+
}
20+
21+
sourceSets {
22+
androidMain.dependencies {
23+
implementation(compose.preview)
24+
implementation(libs.androidx.activity.compose)
25+
}
26+
commonMain.dependencies {
27+
implementation(compose.runtime)
28+
implementation(compose.foundation)
29+
implementation(compose.material3)
30+
implementation(compose.ui)
31+
implementation(libs.androidx.material.icons.core)
32+
implementation(compose.components.resources)
33+
implementation(compose.components.uiToolingPreview)
34+
implementation(libs.androidx.lifecycle.viewmodelCompose)
35+
implementation(libs.androidx.lifecycle.runtimeCompose)
36+
implementation(libs.opentelemetry.logback.appender.x.x)
37+
implementation(libs.slf4j.api)
38+
implementation(libs.logback.android)
39+
}
40+
commonTest.dependencies {
41+
implementation(libs.kotlin.test)
42+
}
43+
}
44+
}
45+
46+
android {
47+
namespace = "com.example.koog_example"
48+
compileSdk = libs.versions.android.compileSdk.get().toInt()
49+
50+
defaultConfig {
51+
applicationId = "com.example.koog_example"
52+
minSdk = libs.versions.android.minSdk.get().toInt()
53+
targetSdk = libs.versions.android.targetSdk.get().toInt()
54+
versionCode = 1
55+
versionName = "1.0"
56+
57+
// 環境変数から読み込んでBuildConfigに埋め込む
58+
buildConfigField("String", "AWS_ACCESS_KEY_ID", "\"${System.getenv("AWS_ACCESS_KEY_ID") ?: ""}\"")
59+
buildConfigField("String", "AWS_SECRET_ACCESS_KEY", "\"${System.getenv("AWS_SECRET_ACCESS_KEY") ?: ""}\"")
60+
buildConfigField("String", "AWS_SESSION_TOKEN", "\"${System.getenv("AWS_SESSION_TOKEN") ?: ""}\"")
61+
buildConfigField("String", "AWS_REGION", "\"${System.getenv("AWS_REGION") ?: "us-west-2"}\"")
62+
63+
buildConfigField("String", "OTLP_BACKEND", "\"${System.getenv("OTLP_BACKEND") ?: ""}\"")
64+
buildConfigField("String", "OTLP_ENDPOINT", "\"${System.getenv("OTLP_ENDPOINT") ?: "http://10.0.2.2:4318/v1/traces"}\"")
65+
buildConfigField("String", "OTLP_HEADERS", "\"${System.getenv("LANGFUSE_API_KEY") ?: ""}\"")
66+
}
67+
packaging {
68+
resources {
69+
excludes += "/META-INF/{AL2.0,LGPL2.1}"
70+
}
71+
dex {
72+
useLegacyPackaging = false
73+
}
74+
}
75+
buildTypes {
76+
getByName("release") {
77+
isMinifyEnabled = true
78+
// 検証コードなのでproguard設定はしない
79+
}
80+
getByName("debug") {
81+
applicationIdSuffix = ".debug"
82+
isDebuggable = true
83+
}
84+
}
85+
compileOptions {
86+
sourceCompatibility = JavaVersion.VERSION_17
87+
targetCompatibility = JavaVersion.VERSION_17
88+
}
89+
90+
buildFeatures {
91+
buildConfig = true
92+
}
93+
}
94+
95+
dependencies {
96+
debugImplementation(compose.uiTooling)
97+
implementation(libs.koog.agents)
98+
implementation(libs.opentelemetry.exporter.otlp)
99+
implementation(libs.opentelemetry.exporter.logging)
100+
}
101+
102+
repositories {
103+
google()
104+
// Use Maven Central for resolving dependencies.
105+
mavenCentral()
106+
// Add JetBrains repository for Koog framework
107+
maven {
108+
url = uri("https://packages.jetbrains.team/maven/p/grazi/grazie-platform-public")
109+
}
110+
}
111+
112+
configurations.all {
113+
// FIXME exclude netty from Koog dependencies?
114+
exclude(group = "io.netty", module = "*")
115+
exclude(group = "org.apache.httpcomponents.httpclient5", module = "*")
116+
exclude(group = "org.apache.httpcomponents.core5", module = "*")
117+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
3+
<uses-permission android:name="android.permission.INTERNET" />
4+
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
5+
6+
<application
7+
android:allowBackup="true"
8+
android:icon="@mipmap/ic_launcher"
9+
android:label="@string/app_name"
10+
android:roundIcon="@mipmap/ic_launcher_round"
11+
android:supportsRtl="true"
12+
android:theme="@android:style/Theme.Material.Light.NoActionBar"
13+
android:networkSecurityConfig="@xml/network_security_config">
14+
<activity
15+
android:exported="true"
16+
android:name=".ChatActivity">
17+
<intent-filter>
18+
<action android:name="android.intent.action.MAIN" />
19+
20+
<category android:name="android.intent.category.LAUNCHER" />
21+
</intent-filter>
22+
</activity>
23+
</application>
24+
25+
</manifest>
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<vector
2+
xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:aapt="http://schemas.android.com/aapt"
4+
android:width="450dp"
5+
android:height="450dp"
6+
android:viewportWidth="64"
7+
android:viewportHeight="64">
8+
<path
9+
android:pathData="M56.25,18V46L32,60 7.75,46V18L32,4Z"
10+
android:fillColor="#6075f2"/>
11+
<path
12+
android:pathData="m41.5,26.5v11L32,43V60L56.25,46V18Z"
13+
android:fillColor="#6b57ff"/>
14+
<path
15+
android:pathData="m32,43 l-9.5,-5.5v-11L7.75,18V46L32,60Z">
16+
<aapt:attr name="android:fillColor">
17+
<gradient
18+
android:centerX="23.131"
19+
android:centerY="18.441"
20+
android:gradientRadius="42.132"
21+
android:type="radial">
22+
<item android:offset="0" android:color="#FF5383EC"/>
23+
<item android:offset="0.867" android:color="#FF7F52FF"/>
24+
</gradient>
25+
</aapt:attr>
26+
</path>
27+
<path
28+
android:pathData="M22.5,26.5 L32,21 41.5,26.5 56.25,18 32,4 7.75,18Z">
29+
<aapt:attr name="android:fillColor">
30+
<gradient
31+
android:startX="44.172"
32+
android:startY="4.377"
33+
android:endX="17.973"
34+
android:endY="34.035"
35+
android:type="linear">
36+
<item android:offset="0" android:color="#FF33C3FF"/>
37+
<item android:offset="0.878" android:color="#FF5383EC"/>
38+
</gradient>
39+
</aapt:attr>
40+
</path>
41+
<path
42+
android:pathData="m32,21 l9.526,5.5v11L32,43 22.474,37.5v-11z"
43+
android:fillColor="#000000"/>
44+
</vector>

0 commit comments

Comments
 (0)