Skip to content

Commit b8e8a68

Browse files
authored
Fix the KMP Support (#151)
1 parent 600757d commit b8e8a68

38 files changed

Lines changed: 459 additions & 288 deletions

File tree

agents/agent-koog/README.md

Lines changed: 43 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,72 @@
11
# agent-koog
22

3-
This is a Kotlin Multiplatform project targeting Android.
3+
これは Android をターゲットとした Kotlin Multiplatform プロジェクトです。
4+
Kotlin Multiplatform による Amazon Bedrock を使った Koog によるチャットボットエージェントライブラリと、そのフロントエンドとなる Android アプリです。
45

5-
- [/composeApp](./composeApp/src) is for code that will be shared across your Compose Multiplatform applications.
6-
It contains several subfolders:
6+
- [/app](./app/src)は、フロントエンドとなる Android アプリです。
7+
- [/share](./share/src) は Compose Multiplatformアプリケーション間で共有されるコード用です。
78

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.
9+
## 環境変数
1410

15-
## Build and Run Android Application
11+
サンプルアプリのため、AWSの一時的なクレデンシャルや OpenTelemetry Observer の設定はビルド時に環境変数から解決しています。
12+
Android Studio を使用する場合は、Android Studio の起動時に設定されている必要があります。
1613

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:
14+
| 環境変数名 | 必須か? | 設定する値の説明 | デフォルト値 |
15+
| -------- | ---- | -------------- | ---------- |
16+
| AWS_ACCESS_KEY_ID | 必須 | AWS のアクセスキーID (AWS IAM Identity Center の一時的なクレデンシャルの値で可) | (なし) |
17+
| AWS_SECRET_ACCESS_KEY | 必須 | AWS のシークレットキー (AWS IAM Identity Center の一時的なクレデンシャルの値で可) | (なし) |
18+
| AWS_SESSION_TOKEN | 条件次第 | AWS のセッショントークン (AWS IAM Identity Center の一時的なクレデンシャルの場合は必須) | (なし) |
19+
| AWS_REGION | 任意 | AWS のリージョン | us-west-2 |
20+
| OTLP_BACKEND | 条件次第 | 使用する Observer を指定。指定されない場合や不正値の場合は OpenTelemetry のトレーシングを送信しません。指定可能なObserver は現状、 jaeger または langfuse。※ langfuse は動作未確認 | (なし) |
21+
| OTLP_ENDPOINT | 任意 | OpenTelemetry Observer のエンドポイント URL。OTLP_BACKEND に jaeger または langfuse が指定されている場合にのみ使われます。 | <http://10.0.2.2:4318/v1/traces> |
22+
| OTLP_HEADERS | 任意 | Observer にテレメトリーを送信する際に付与する HTTP リクエストヘッダーを `ヘッダー名:値` 形式で指定できます。複数指定する場合は `,` 区切りとする想定ですが、現状は 1 つのみの指定しか対応していません。 | (なし) |
1923

20-
- on macOS/Linux
24+
### macOS で環境変数を設定して Android Studio を起動する方法
25+
26+
```shell
27+
# (環境変数を export で設定)
28+
export AWS_ACCESS_KEY_ID=XXXX
29+
# (環境変数の設定の記述を割愛)
30+
31+
# Android Studio を起動
32+
open -a "Android Studio"
33+
```
34+
35+
## Androidアプリケーションのビルドと実行
36+
37+
Androidアプリの開発バージョンをビルドして実行するには、IDEのツールバーにある実行ウィジェットから実行構成を使用するか、ターミナルから直接ビルドしてください:
38+
39+
- macOS/Linuxの場合
2140

2241
```shell
2342
./gradlew :composeApp:assembleDebug
2443
```
2544

26-
- on Windows
45+
- Windowsの場合
2746

2847
```shell
2948
.\gradlew.bat :composeApp:assembleDebug
3049
```
3150

3251
---
52+
[Kotlin Multiplatform](https://www.jetbrains.com/help/kotlin-multiplatform-dev/get-started.html)について詳しく学ぶ…
53+
54+
## 可観測性(Observability)
3355

34-
Learn more about [Kotlin Multiplatform](https://www.jetbrains.com/help/kotlin-multiplatform-dev/get-started.html)
56+
Langfuse などの SaaS を使用する前に、ローカルで Jaeger を使用して確認して、OpenTelemetry のトレースがきちんと登録できることを確認した上で SaaS を使うことで、アプリ側の計装や Android のネットワーク設定の問題か SaaS との連携固有の問題なのかを切り分けできます。
3557

36-
## Observability
58+
### Jaeger の起動方法
3759

3860
`$download_url`<https://www.jaegertracing.io/download/> からダウンロードURLを調べて取得したURLに置き換えてください。
3961

4062
```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
63+
# Jaeger を起動
64+
curl -sSL "$download_url" -o jaeger.tar.gz
65+
tar -xzf jaeger.tar.gz
66+
cd jaeger
4567
COLLECTOR_OTLP_ENABLED=true ./jaeger \
4668
--set=receivers.otlp.protocols.grpc.endpoint=0.0.0.0:4317 \
4769
--set=receivers.otlp.protocols.http.endpoint=0.0.0.0:4318
4870
```
4971

50-
Access to <http://localhost:16686/search>
72+
<http://localhost:16686/search> にアクセスしてください
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
plugins {
2+
alias(libs.plugins.androidApplication)
3+
alias(libs.plugins.kotlinAndroid)
4+
alias(libs.plugins.composeCompiler)
5+
alias(libs.plugins.composeMultiplatform)
6+
7+
// Add Kotlin serialization plugin for Koog API support
8+
kotlin("plugin.serialization") version "2.3.0"
9+
}
10+
11+
android {
12+
namespace = "com.example.koog_example"
13+
compileSdkVersion(libs.versions.android.compileSdk.get().toInt())
14+
15+
defaultConfig {
16+
applicationId = "com.example.koog_example"
17+
minSdk = libs.versions.android.minSdk.get().toInt()
18+
targetSdk = libs.versions.android.targetSdk.get().toInt()
19+
versionCode = 1
20+
versionName = "1.0"
21+
}
22+
23+
buildFeatures {
24+
buildConfig = true
25+
}
26+
27+
packaging {
28+
resources {
29+
excludes += "/META-INF/{AL2.0,LGPL2.1}"
30+
}
31+
dex {
32+
useLegacyPackaging = false
33+
}
34+
}
35+
36+
buildTypes {
37+
getByName("release") {
38+
isMinifyEnabled = true
39+
// 検証コードなのでproguard設定はしない
40+
}
41+
getByName("debug") {
42+
applicationIdSuffix = ".debug"
43+
isDebuggable = true
44+
}
45+
}
46+
compileOptions {
47+
sourceCompatibility = JavaVersion.VERSION_21
48+
targetCompatibility = JavaVersion.VERSION_21
49+
}
50+
51+
buildFeatures {
52+
buildConfig = true
53+
}
54+
}
55+
56+
dependencies {
57+
debugImplementation(compose.uiTooling)
58+
// KMP 共有ライブラリへの依存
59+
implementation(project(":shared"))
60+
61+
implementation(compose.preview)
62+
implementation(libs.androidx.activity.compose)
63+
implementation(compose.runtime)
64+
implementation(compose.foundation)
65+
implementation(compose.material3)
66+
implementation(compose.ui)
67+
implementation(libs.androidx.material.icons.core)
68+
implementation(compose.components.resources)
69+
implementation(compose.components.uiToolingPreview)
70+
implementation(libs.androidx.lifecycle.viewmodelCompose)
71+
implementation(libs.androidx.lifecycle.runtimeCompose)
72+
testImplementation(libs.kotlin.test)
73+
androidTestImplementation(libs.androidx.espresso.core)
74+
}
75+
76+
configurations.all {
77+
// FIXME exclude netty from Koog dependencies?
78+
exclude(group = "io.netty", module = "*")
79+
exclude(group = "org.apache.httpcomponents.httpclient5", module = "*")
80+
exclude(group = "org.apache.httpcomponents.core5", module = "*")
81+
}

agents/agent-koog/composeApp/src/debug/res/xml/network_security_config.xml renamed to agents/agent-koog/app/src/debug/res/xml/network_security_config.xml

File renamed without changes.

agents/agent-koog/composeApp/src/androidMain/AndroidManifest.xml renamed to agents/agent-koog/app/src/main/AndroidManifest.xml

File renamed without changes.

agents/agent-koog/composeApp/src/androidMain/composeResources/drawable/compose-multiplatform.xml renamed to agents/agent-koog/app/src/main/composeResources/drawable/compose-multiplatform.xml

File renamed without changes.

agents/agent-koog/composeApp/src/androidMain/kotlin/com/example/koog_example/ChatActivity.kt renamed to agents/agent-koog/app/src/main/kotlin/com/example/koog_example/App.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ import androidx.compose.ui.unit.sp
5252
import androidx.lifecycle.ViewModel
5353
import androidx.lifecycle.viewModelScope
5454
import androidx.lifecycle.viewmodel.compose.viewModel
55+
import com.example.shared.Agent
5556
import kotlinx.coroutines.flow.MutableStateFlow
5657
import kotlinx.coroutines.flow.StateFlow
5758
import kotlinx.coroutines.flow.asStateFlow
@@ -284,5 +285,5 @@ class ChatActivity : ComponentActivity() {
284285
@Preview
285286
@Composable
286287
fun AppAndroidPreview() {
287-
App()
288+
ChatActivity()
288289
}

agents/agent-koog/composeApp/src/androidMain/kotlin/com/example/koog_example/Platform.kt renamed to agents/agent-koog/app/src/main/kotlin/com/example/koog_example/Platform.kt

File renamed without changes.

agents/agent-koog/composeApp/src/androidMain/res/drawable-v24/ic_launcher_foreground.xml renamed to agents/agent-koog/app/src/main/res/drawable-v24/ic_launcher_foreground.xml

File renamed without changes.

agents/agent-koog/composeApp/src/androidMain/res/drawable/ic_launcher_background.xml renamed to agents/agent-koog/app/src/main/res/drawable/ic_launcher_background.xml

File renamed without changes.

agents/agent-koog/composeApp/src/androidMain/res/mipmap-anydpi-v26/ic_launcher.xml renamed to agents/agent-koog/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml

File renamed without changes.

0 commit comments

Comments
 (0)