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
64 changes: 43 additions & 21 deletions agents/agent-koog/README.md
Original file line number Diff line number Diff line change
@@ -1,50 +1,72 @@
# agent-koog

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

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

- [commonMain](./composeApp/src/commonMain/kotlin) is for code that’s common for all targets.
- Other folders are for Kotlin code that will be compiled for only the platform indicated in the folder name.
For example, if you want to use Apple’s CoreCrypto for the iOS part of your Kotlin app,
the [iosMain](./composeApp/src/iosMain/kotlin) folder would be the right place for such calls.
Similarly, if you want to edit the Desktop (JVM) specific part, the [jvmMain](./composeApp/src/jvmMain/kotlin)
folder is the appropriate location.
## 環境変数

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

To build and run the development version of the Android app, use the run configuration from the run widget
in your IDE’s toolbar or build it directly from the terminal:
| 環境変数名 | 必須か? | 設定する値の説明 | デフォルト値 |
| -------- | ---- | -------------- | ---------- |
| AWS_ACCESS_KEY_ID | 必須 | AWS のアクセスキーID (AWS IAM Identity Center の一時的なクレデンシャルの値で可) | (なし) |
| AWS_SECRET_ACCESS_KEY | 必須 | AWS のシークレットキー (AWS IAM Identity Center の一時的なクレデンシャルの値で可) | (なし) |
| AWS_SESSION_TOKEN | 条件次第 | AWS のセッショントークン (AWS IAM Identity Center の一時的なクレデンシャルの場合は必須) | (なし) |
| AWS_REGION | 任意 | AWS のリージョン | us-west-2 |
| OTLP_BACKEND | 条件次第 | 使用する Observer を指定。指定されない場合や不正値の場合は OpenTelemetry のトレーシングを送信しません。指定可能なObserver は現状、 jaeger または langfuse。※ langfuse は動作未確認 | (なし) |
| OTLP_ENDPOINT | 任意 | OpenTelemetry Observer のエンドポイント URL。OTLP_BACKEND に jaeger または langfuse が指定されている場合にのみ使われます。 | <http://10.0.2.2:4318/v1/traces> |
| OTLP_HEADERS | 任意 | Observer にテレメトリーを送信する際に付与する HTTP リクエストヘッダーを `ヘッダー名:値` 形式で指定できます。複数指定する場合は `,` 区切りとする想定ですが、現状は 1 つのみの指定しか対応していません。 | (なし) |

- on macOS/Linux
### macOS で環境変数を設定して Android Studio を起動する方法

```shell
# (環境変数を export で設定)
export AWS_ACCESS_KEY_ID=XXXX
# (環境変数の設定の記述を割愛)

# Android Studio を起動
open -a "Android Studio"
```

## Androidアプリケーションのビルドと実行

Androidアプリの開発バージョンをビルドして実行するには、IDEのツールバーにある実行ウィジェットから実行構成を使用するか、ターミナルから直接ビルドしてください:

- macOS/Linuxの場合

```shell
./gradlew :composeApp:assembleDebug
```

- on Windows
- Windowsの場合

```shell
.\gradlew.bat :composeApp:assembleDebug
```

---
[Kotlin Multiplatform](https://www.jetbrains.com/help/kotlin-multiplatform-dev/get-started.html)について詳しく学ぶ…

## 可観測性(Observability)

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

## Observability
### Jaeger の起動方法

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

```shell
# Jaegerを起動
curl -sSL "$download_url" -o jaeger-2.13.0.tar.gz
tar -xzf jaeger-2.13.0.tar.gz
cd jaeger-2.13.0
# Jaeger を起動
curl -sSL "$download_url" -o jaeger.tar.gz
tar -xzf jaeger.tar.gz
cd jaeger
COLLECTOR_OTLP_ENABLED=true ./jaeger \
--set=receivers.otlp.protocols.grpc.endpoint=0.0.0.0:4317 \
--set=receivers.otlp.protocols.http.endpoint=0.0.0.0:4318
```

Access to <http://localhost:16686/search>
<http://localhost:16686/search> にアクセスしてください
81 changes: 81 additions & 0 deletions agents/agent-koog/app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
plugins {
alias(libs.plugins.androidApplication)
alias(libs.plugins.kotlinAndroid)
alias(libs.plugins.composeCompiler)
alias(libs.plugins.composeMultiplatform)

// Add Kotlin serialization plugin for Koog API support
kotlin("plugin.serialization") version "2.3.0"
Comment thread
poad marked this conversation as resolved.
}

android {
namespace = "com.example.koog_example"
compileSdkVersion(libs.versions.android.compileSdk.get().toInt())

defaultConfig {
applicationId = "com.example.koog_example"
minSdk = libs.versions.android.minSdk.get().toInt()
targetSdk = libs.versions.android.targetSdk.get().toInt()
versionCode = 1
versionName = "1.0"
}

buildFeatures {
buildConfig = true
}

packaging {
resources {
excludes += "/META-INF/{AL2.0,LGPL2.1}"
}
dex {
useLegacyPackaging = false
}
}

buildTypes {
getByName("release") {
isMinifyEnabled = true
// 検証コードなのでproguard設定はしない
}
getByName("debug") {
applicationIdSuffix = ".debug"
isDebuggable = true
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21
}

buildFeatures {
buildConfig = true
}
Comment thread
poad marked this conversation as resolved.
}

dependencies {
debugImplementation(compose.uiTooling)
// KMP 共有ライブラリへの依存
implementation(project(":shared"))

implementation(compose.preview)
implementation(libs.androidx.activity.compose)
implementation(compose.runtime)
implementation(compose.foundation)
implementation(compose.material3)
implementation(compose.ui)
implementation(libs.androidx.material.icons.core)
implementation(compose.components.resources)
implementation(compose.components.uiToolingPreview)
implementation(libs.androidx.lifecycle.viewmodelCompose)
implementation(libs.androidx.lifecycle.runtimeCompose)
testImplementation(libs.kotlin.test)
androidTestImplementation(libs.androidx.espresso.core)
}

configurations.all {
// FIXME exclude netty from Koog dependencies?
exclude(group = "io.netty", module = "*")
exclude(group = "org.apache.httpcomponents.httpclient5", module = "*")
exclude(group = "org.apache.httpcomponents.core5", module = "*")
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import androidx.compose.ui.unit.sp
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import androidx.lifecycle.viewmodel.compose.viewModel
import com.example.shared.Agent
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
Expand Down Expand Up @@ -284,5 +285,5 @@ class ChatActivity : ComponentActivity() {
@Preview
@Composable
fun AppAndroidPreview() {
App()
ChatActivity()
}
Comment thread
poad marked this conversation as resolved.
28 changes: 21 additions & 7 deletions agents/agent-koog/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,31 @@ plugins {
// in each subproject's classloader
alias(libs.plugins.androidApplication) apply false
alias(libs.plugins.androidLibrary) apply false
alias(libs.plugins.kotlinAndroid) apply false
alias(libs.plugins.composeMultiplatform) apply false
alias(libs.plugins.composeCompiler) apply false
alias(libs.plugins.kotlinMultiplatform) apply false
alias(libs.plugins.androidKotlinMultiplatformLibrary) apply false
alias(libs.plugins.buildkonfig) apply false
alias(libs.plugins.androidLint) apply false
}

buildscript {
dependencies {
// For KGP
classpath(libs.kotlin.gradle.plugin)

// For KSP
classpath(libs.symbol.processing.gradle.plugin)
}
}

repositories {
google()
// Use Maven Central for resolving dependencies.
mavenCentral()
// Add JetBrains repository for Koog framework
maven {
url = uri("https://packages.jetbrains.team/maven/p/grazi/grazie-platform-public")
}
google()
// Use Maven Central for resolving dependencies.
mavenCentral()
// Add JetBrains repository for Koog framework
maven {
url = uri("https://packages.jetbrains.team/maven/p/grazi/grazie-platform-public")
}
}
106 changes: 0 additions & 106 deletions agents/agent-koog/composeApp/build.gradle.kts

This file was deleted.

Loading