Skip to content

エージェントイベント

エージェントイベントは、エージェントワークフローの一部として発生するアクションまたはインタラクションです。これらには以下が含まれます:

  • エージェントライフサイクルイベント
  • ストラテジーイベント
  • ノード実行イベント
  • LLMコールイベント
  • LLMストリーミングイベント
  • ツール実行イベント

注意:機能イベントは agents-core モジュールで定義されており、ai.koog.agents.core.feature.model.events パッケージの下に配置されています。agents-features-traceagents-features-event-handler などの機能は、これらのイベントを消費して、エージェントの実行中に作成されたメッセージを処理および転送します。

事前定義されたイベントタイプ

Koog は、カスタムメッセージプロセッサで使用できる事前定義されたイベントタイプを提供しています。事前定義されたイベントは、関連するエンティティに応じていくつかのカテゴリに分類できます:

エージェントイベント

AgentStartingEvent

エージェント実行の開始を表します。以下のフィールドが含まれます:

名前データ型必須デフォルト説明
eventIdStringはいイベントまたはイベントグループの一意の識別子。
executionInfoAgentExecutionInfoはいこのイベントに関連付けられた実行に関するコンテキスト情報を提供します。
agentIdStringはいAIエージェントの一意の識別子。
runIdStringはいAIエージェント実行の一意の識別子。

AgentCompletedEvent

エージェント実行の終了を表します。以下のフィールドが含まれます:

名前データ型必須デフォルト説明
eventIdStringはいイベントまたはイベントグループの一意の識別子。
executionInfoAgentExecutionInfoはいこのイベントに関連付けられた実行に関するコンテキスト情報を提供します。
agentIdStringはいAIエージェントの一意の識別子。
runIdStringはいAIエージェント実行の一意の識別子。
resultStringはいエージェント実行の結果。結果がない場合は null になる可能性があります。

AgentExecutionFailedEvent

エージェント実行中にエラーが発生したことを表します。以下のフィールドが含まれます:

名前データ型必須デフォルト説明
eventIdStringはいイベントまたはイベントグループの一意の識別子。
executionInfoAgentExecutionInfoはいこのイベントに関連付けられた実行に関するコンテキスト情報を提供します。
agentIdStringはいAIエージェントの一意の識別子。
runIdStringはいAIエージェント実行の一意の識別子。
errorAIAgentErrorはいエージェント実行中に発生した特定のエラー。詳細については AIAgentError を参照してください。

AgentClosingEvent

エージェントのクローズまたは終了を表します。以下のフィールドが含まれます:

名前データ型必須デフォルト説明
eventIdStringはいイベントまたはイベントグループの一意の識別子。
executionInfoAgentExecutionInfoはいこのイベントに関連付けられた実行に関するコンテキスト情報を提供します。
agentIdStringはいAIエージェントの一意の識別子。

AIAgentError クラスは、エージェント実行中に発生したエラーに関する詳細情報を提供します。以下のフィールドが含まれます:

名前データ型必須デフォルト説明
messageStringはい特定のエラーに関する詳細情報を提供するメッセージ。
stackTraceStringはい最後に実行されたコードまでのスタックレコードのコレクション。
causeStringいいえnull利用可能な場合、エラーの原因。

AgentExecutionInfo クラスは、実行パスに関するコンテキスト情報を提供し、エージェント実行内のネストされた実行コンテキストの追跡を可能にします。以下のフィールドが含まれます:

名前データ型必須デフォルト説明
parentAgentExecutionInfoいいえnull親実行コンテキストへの参照。null の場合、これはルート実行レベルを表します。
partNameStringはい実行の現在のパートまたはセグメントの名前を表す文字列。

ストラテジーイベント

GraphStrategyStartingEvent

グラフベースのストラテジー実行の開始を表します。以下のフィールドが含まれます:

名前データ型必須デフォルト説明
eventIdStringはいイベントまたはイベントグループの一意の識別子。
executionInfoAgentExecutionInfoはいこのイベントに関連付けられた実行に関するコンテキスト情報を提供します。
runIdStringはいストラテジー実行の一意の識別子。
strategyNameStringはいストラテジーの名前。
graphStrategyEventGraphはいストラテジーワークフローを表すグラフ構造。

FunctionalStrategyStartingEvent

関数型ストラテジー実行の開始を表します。以下のフィールドが含まれます:

名前データ型必須デフォルト説明
eventIdStringはいイベントまたはイベントグループの一意の識別子。
executionInfoAgentExecutionInfoはいこのイベントに関連付けられた実行に関するコンテキスト情報を提供します。
runIdStringはいストラテジー実行の一意の識別子。
strategyNameStringはいストラテジーの名前。

StrategyCompletedEvent

ストラテジー実行の終了を表します。以下のフィールドが含まれます:

名前データ型必須デフォルト説明
eventIdStringはいイベントまたはイベントグループの一意の識別子。
executionInfoAgentExecutionInfoはいこのイベントに関連付けられた実行に関するコンテキスト情報を提供します。
runIdStringはいストラテジー実行の一意の識別子。
strategyNameStringはいストラテジーの名前。
resultStringはい実行の結果。結果がない場合は null になる可能性があります。

ノードイベント

NodeExecutionStartingEvent

ノード実行の開始を表します。以下のフィールドが含まれます:

名前データ型必須デフォルト説明
eventIdStringはいイベントまたはイベントグループの一意の識別子。
executionInfoAgentExecutionInfoはいこのイベントに関連付けられた実行に関するコンテキスト情報を提供します。
runIdStringはいストラテジー実行の一意の識別子。
nodeNameStringはい実行が開始されたノードの名前。
inputJsonElementいいえnullノードへの入力値。

NodeExecutionCompletedEvent

ノード実行の終了を表します。以下のフィールドが含まれます:

名前データ型必須デフォルト説明
eventIdStringはいイベントまたはイベントグループの一意の識別子。
executionInfoAgentExecutionInfoはいこのイベントに関連付けられた実行に関するコンテキスト情報を提供します。
runIdStringはいストラテジー実行の一意の識別子。
nodeNameStringはい実行が終了したノードの名前。
inputJsonElementいいえnullノードへの入力値。
outputJsonElementいいえnullノードによって生成された出力値。

NodeExecutionFailedEvent

ノード実行中に発生したエラーを表します。以下のフィールドが含まれます:

名前データ型必須デフォルト説明
eventIdStringはいイベントまたはイベントグループの一意の識別子。
executionInfoAgentExecutionInfoはいこのイベントに関連付けられた実行に関するコンテキスト情報を提供します。
runIdStringはいストラテジー実行の一意の識別子。
nodeNameStringはいエラーが発生したノードの名前。
inputJsonElementいいえnullノードに提供された入力データ。
errorAIAgentErrorはいノード実行中に発生した特定のエラー。詳細については AIAgentError を参照してください。

サブグラフイベント

SubgraphExecutionStartingEvent

サブグラフ実行の開始を表します。以下のフィールドが含まれます:

名前データ型必須デフォルト説明
eventIdStringはいイベントまたはイベントグループの一意の識別子。
executionInfoAgentExecutionInfoはいこのイベントに関連付けられた実行に関するコンテキスト情報を提供します。
runIdStringはいストラテジー実行の一意の識別子。
subgraphNameStringはい実行が開始されたサブグラフの名前。
inputJsonElementいいえnullサブグラフへの入力値。

SubgraphExecutionCompletedEvent

サブグラフ実行の終了を表します。以下のフィールドが含まれます:

名前データ型必須デフォルト説明
eventIdStringはいイベントまたはイベントグループの一意の識別子。
executionInfoAgentExecutionInfoはいこのイベントに関連付けられた実行に関するコンテキスト情報を提供します。
runIdStringはいストラテジー実行の一意の識別子。
subgraphNameStringはい実行が終了したサブグラフの名前。
inputJsonElementいいえnullサブグラフへの入力値。
outputJsonElementいいえnullサブグラフによって生成された出力値。

SubgraphExecutionFailedEvent

サブグラフ実行中に発生したエラーを表します。以下のフィールドが含まれます:

名前データ型必須デフォルト説明
eventIdStringはいイベントまたはイベントグループの一意の識別子。
executionInfoAgentExecutionInfoはいこのイベントに関連付けられた実行に関するコンテキスト情報を提供します。
runIdStringはいストラテジー実行の一意の識別子。
subgraphNameStringはいエラーが発生したサブグラフの名前。
inputJsonElementいいえnullサブグラフに提供された入力データ。
errorAIAgentErrorはいサブグラフ実行中に発生した特定のエラー。詳細については AIAgentError を参照してください。

LLMコールイベント

LLMCallStartingEvent

LLMコールの開始を表します。以下のフィールドが含まれます:

名前データ型必須デフォルト説明
eventIdStringはいイベントまたはイベントグループの一意の識別子。
executionInfoAgentExecutionInfoはいこのイベントに関連付けられた実行に関するコンテキスト情報を提供します。
runIdStringはいLLM実行の一意の識別子。
promptPromptはいモデルに送信されるプロンプト。詳細については Prompt を参照してください。
modelModelInfoはいモデル情報。ModelInfo を参照してください。
toolsList<String>はいモデルが呼び出すことができるツールのリスト。

Prompt クラスは、メッセージのリスト、一意の識別子、および言語モデル設定のオプションパラメータで構成されるプロンプトのデータ構造を表します。以下のフィールドが含まれます:

名前データ型必須デフォルト説明
messagesList<Message>はいプロンプトを構成するメッセージのリスト。
idStringはいプロンプトの一意の識別子。
paramsLLMParamsいいえLLMParams()LLMがコンテンツを生成する方法を制御する設定。

ModelInfo クラスは、プロバイダー、モデル識別子、および特性を含む言語モデルに関する情報を表します。以下のフィールドが含まれます:

名前データ型必須デフォルト説明
providerStringはいプロバイダー識別子(例: "openai", "google", "anthropic")。
modelStringはいモデル識別子(例: "gpt-4", "claude-3")。
displayNameStringいいえnullモデルのオプションの人間が読める表示名。
contextLengthLongいいえnullモデルが処理できるトークンの最大数。
maxOutputTokensLongいいえnullモデルが生成できるトークンの最大数。

LLMCallCompletedEvent

LLMコールの終了を表します。以下のフィールドが含まれます:

名前データ型必須デフォルト説明
eventIdStringはいイベントまたはイベントグループの一意の識別子。
executionInfoAgentExecutionInfoはいこのイベントに関連付けられた実行に関するコンテキスト情報を提供します。
runIdStringはいLLM実行の一意の識別子。
promptPromptはいコールで使用されたプロンプト。
modelModelInfoはいモデル情報。ModelInfo を参照してください。
responsesList<Message.Response>はいモデルによって返された1つ以上のレスポンス。
moderationResponseModerationResultいいえnullモデレーションレスポンス(存在する場合)。

LLMストリーミングイベント

LLMStreamingStartingEvent

LLMストリーミングコールの開始を表します。以下のフィールドが含まれます:

名前データ型必須デフォルト説明
eventIdStringはいイベントまたはイベントグループの一意の識別子。
executionInfoAgentExecutionInfoはいこのイベントに関連付けられた実行に関するコンテキスト情報を提供します。
runIdStringはいLLM実行の一意の識別子。
promptPromptはいモデルに送信されるプロンプト。
modelModelInfoはいモデル情報。ModelInfo を参照してください。
toolsList<String>はいモデルが呼び出すことができるツールのリスト。

LLMStreamingFrameReceivedEvent

LLMから受信したストリーミングフレームを表します。以下のフィールドが含まれます:

名前データ型必須デフォルト説明
eventIdStringはいイベントまたはイベントグループの一意の識別子。
executionInfoAgentExecutionInfoはいこのイベントに関連付けられた実行に関するコンテキスト情報を提供します。
runIdStringはいLLM実行の一意の識別子。
promptPromptはいモデルに送信されるプロンプト。
modelModelInfoはいモデル情報。ModelInfo を参照してください。
frameStreamFrameはいストリームから受信したフレーム。

LLMStreamingFailedEvent

LLMストリーミングコール中にエラーが発生したことを表します。以下のフィールドが含まれます:

名前データ型必須デフォルト説明
eventIdStringはいイベントまたはイベントグループの一意の識別子。
executionInfoAgentExecutionInfoはいこのイベントに関連付けられた実行に関するコンテキスト情報を提供します。
runIdStringはいLLM実行の一意の識別子。
promptPromptはいモデルに送信されるプロンプト。
modelModelInfoはいモデル情報。ModelInfo を参照してください。
errorAIAgentErrorはいストリーミング中に発生した特定のエラー。詳細については AIAgentError を参照してください。

LLMStreamingCompletedEvent

LLMストリーミングコールの終了を表します。以下のフィールドが含まれます:

名前データ型必須デフォルト説明
eventIdStringはいイベントまたはイベントグループの一意の識別子。
executionInfoAgentExecutionInfoはいこのイベントに関連付けられた実行に関するコンテキスト情報を提供します。
runIdStringはいLLM実行の一意の識別子。
promptPromptはいモデルに送信されるプロンプト。
modelModelInfoはいモデル情報。ModelInfo を参照してください。
toolsList<String>はいモデルが呼び出すことができるツールのリスト。

ツール実行イベント

ToolCallStartingEvent

モデルがツールを呼び出すイベントを表します。以下のフィールドが含まれます:

名前データ型必須デフォルト説明
eventIdStringはいイベントまたはイベントグループの一意の識別子。
executionInfoAgentExecutionInfoはいこのイベントに関連付けられた実行に関するコンテキスト情報を提供します。
runIdStringはいストラテジー/エージェント実行の一意の識別子。
toolCallIdStringいいえnull利用可能な場合、ツールコールの識別子。
toolNameStringはいツールの名前。
toolArgsJsonObjectはいツールに提供される引数。

ToolValidationFailedEvent

ツールコール中のバリデーションエラーの発生を表します。以下のフィールドが含まれます:

名前データ型必須デフォルト説明
eventIdStringはいイベントまたはイベントグループの一意の識別子。
executionInfoAgentExecutionInfoはいこのイベントに関連付けられた実行に関するコンテキスト情報を提供します。
runIdStringはいストラテジー/エージェント実行の一意の識別子。
toolCallIdStringいいえnull利用可能な場合、ツールコールの識別子。
toolNameStringはいバリデーションに失敗したツールの名前。
toolArgsJsonObjectはいツールに提供される引数。
toolDescriptionStringいいえnullバリデーションエラーが発生したツールの説明。
messageStringいいえnullバリデーションエラーを説明するメッセージ。
errorAIAgentErrorはい発生した特定のエラー。詳細については AIAgentError を参照してください。

ToolCallFailedEvent

ツールの実行失敗を表します。以下のフィールドが含まれます:

名前データ型必須デフォルト説明
eventIdStringはいイベントまたはイベントグループの一意の識別子。
executionInfoAgentExecutionInfoはいこのイベントに関連付けられた実行に関するコンテキスト情報を提供します。
runIdStringはいストラテジー/エージェント実行の一意の識別子。
toolCallIdStringいいえnull利用可能な場合、ツールコールの識別子。
toolNameStringはいツールの名前。
toolArgsJsonObjectはいツールに提供される引数。
toolDescriptionStringいいえnull失敗したツールの説明。
errorAIAgentErrorはいツールを呼び出そうとしたときに発生した特定のエラー。詳細については AIAgentError を参照してください。

ToolCallCompletedEvent

結果の返却を伴うツールコールの成功を表します。以下のフィールドが含まれます:

名前データ型必須デフォルト説明
eventIdStringはいイベントまたはイベントグループの一意の識別子。
executionInfoAgentExecutionInfoはいこのイベントに関連付けられた実行に関するコンテキスト情報を提供します。
runIdStringはい実行の一意の識別子。
toolCallIdStringいいえnullツールコールの識別子。
toolNameStringはいツールの名前。
toolArgsJsonObjectはいツールに提供された引数。
toolDescriptionStringいいえnull実行されたツールの説明。
resultJsonElementいいえnullツールコールの結果。

FAQとトラブルシューティング

以下のセクションには、トレース機能に関するよくある質問と回答が含まれています。

エージェント実行の特定のパートのみをトレースするにはどうすればよいですか?

messageFilter プロパティを使用してイベントをフィルタリングします。例えば、ノードの実行のみをトレースするには以下のようにします:

=== "Kotlin"

<!--- INCLUDE
import ai.koog.agents.core.agent.AIAgent
import ai.koog.agents.core.feature.model.events.LLMCallCompletedEvent
import ai.koog.agents.core.feature.model.events.LLMCallStartingEvent
import ai.koog.agents.example.exampleTracing01.outputPath
import ai.koog.agents.features.tracing.feature.Tracing
import ai.koog.agents.features.tracing.writer.TraceFeatureMessageFileWriter
import ai.koog.prompt.executor.llms.all.simpleOllamaAIExecutor
import ai.koog.prompt.executor.ollama.client.OllamaModels
import kotlinx.coroutines.runBlocking
const val input = "What's the weather like in New York?"
fun main() {
runBlocking {
// エージェントの作成
val agent = AIAgent(
promptExecutor = simpleOllamaAIExecutor(),
llmModel = OllamaModels.Meta.LLAMA_3_2,
) {
-->
<!--- SUFFIX
        }
    }
}
-->
```kotlin
install(Tracing) {
    val fileWriter = TraceFeatureMessageFileWriter.create(outputPath)
    addMessageProcessor(fileWriter)
    
    // LLMコールのみをトレース
    fileWriter.setMessageFilter { message ->
        message is LLMCallStartingEvent || message is LLMCallCompletedEvent
    }
}
```
<!--- KNIT example-events-01.kt -->

=== "Java"

<!--- INCLUDE
import ai.koog.agents.core.agent.AIAgent;
import ai.koog.agents.core.feature.model.events.LLMCallCompletedEvent;
import ai.koog.agents.core.feature.model.events.LLMCallStartingEvent;
import ai.koog.agents.features.tracing.feature.Tracing;
import ai.koog.agents.features.tracing.writer.TraceFeatureMessageFileWriter;
import ai.koog.prompt.executor.model.PromptExecutor;
import ai.koog.prompt.executor.ollama.client.OllamaModels;
import java.nio.file.Files;
import java.nio.file.Path;
public class exampleEventsJava01 {
    public static void main(String[] args) {
        var outputPath = Path.of("/path/to/trace.log");
        var agent = AIAgent.builder()
            .promptExecutor(PromptExecutor.builder().ollama().build())
            .llmModel(OllamaModels.Meta.LLAMA_3_2)
-->
<!--- SUFFIX
        .build();
    }
}
-->
```java
.install(Tracing.Feature, config -> {
    var fileWriter = TraceFeatureMessageFileWriter.create(outputPath);
    config.addMessageProcessor(fileWriter);

    // LLMコールのみをトレース
    fileWriter.setMessageFilter(message ->
        message instanceof LLMCallStartingEvent || message instanceof LLMCallCompletedEvent
    );
})
```
<!--- KNIT exampleEventsJava01.java -->

複数のメッセージプロセッサを使用できますか?

はい、複数のメッセージプロセッサを追加して、同時に異なる宛先にトレースすることができます:

=== "Kotlin"

<!--- INCLUDE
import ai.koog.agents.core.agent.AIAgent
import ai.koog.agents.core.feature.remote.server.config.DefaultServerConnectionConfig
import ai.koog.agents.example.exampleTracing01.outputPath
import ai.koog.agents.features.tracing.feature.Tracing
import ai.koog.agents.features.tracing.writer.TraceFeatureMessageFileWriter
import ai.koog.agents.features.tracing.writer.TraceFeatureMessageLogWriter
import ai.koog.agents.features.tracing.writer.TraceFeatureMessageRemoteWriter
import ai.koog.prompt.executor.llms.all.simpleOllamaAIExecutor
import ai.koog.prompt.executor.ollama.client.OllamaModels
import io.github.oshai.kotlinlogging.KotlinLogging
import kotlinx.coroutines.runBlocking
import kotlinx.io.buffered
import kotlinx.io.files.Path
import kotlinx.io.files.SystemFileSystem
const val input = "What's the weather like in New York?"
val logger = KotlinLogging.logger {}
val connectionConfig = DefaultServerConnectionConfig(host = ai.koog.agents.example.exampleTracing06.host, port = ai.koog.agents.example.exampleTracing06.port)
fun main() {
runBlocking {
// エージェントの作成
val agent = AIAgent(
promptExecutor = simpleOllamaAIExecutor(),
llmModel = OllamaModels.Meta.LLAMA_3_2,
) {
-->
<!--- SUFFIX
        }
    }
}
-->
```kotlin
install(Tracing) {
    addMessageProcessor(TraceFeatureMessageLogWriter(logger))
    addMessageProcessor(TraceFeatureMessageFileWriter.create(outputPath))
    addMessageProcessor(TraceFeatureMessageRemoteWriter(connectionConfig))
}
```
<!--- KNIT example-events-02.kt -->

=== "Java"

<!--- INCLUDE
import ai.koog.agents.core.agent.AIAgent;
import ai.koog.agents.features.tracing.feature.Tracing;
import ai.koog.agents.features.tracing.writer.TraceFeatureMessageFileWriter;
import ai.koog.agents.features.tracing.writer.TraceFeatureMessageLogWriter;
import ai.koog.agents.features.tracing.writer.TraceFeatureMessageRemoteWriter;
import ai.koog.prompt.executor.model.PromptExecutor;
import ai.koog.prompt.executor.ollama.client.OllamaModels;
import org.slf4j.LoggerFactory;
import java.nio.file.Files;
import java.nio.file.Path;
public class exampleEventsJava02 {
    public static void main(String[] args) {
        var logger = LoggerFactory.getLogger("tracing");
        var outputPath = Path.of("/path/to/trace.log");
        var agent = AIAgent.builder()
            .promptExecutor(PromptExecutor.builder().ollama().build())
            .llmModel(OllamaModels.Meta.LLAMA_3_2)
-->
<!--- SUFFIX
        .build();
    }
}
-->
```java
.install(Tracing.Feature, config -> {
    config.addMessageProcessor(TraceFeatureMessageLogWriter.create(logger));
    config.addMessageProcessor(TraceFeatureMessageFileWriter.create(outputPath));
    config.addMessageProcessor(new TraceFeatureMessageRemoteWriter());
})
```
<!--- KNIT exampleEventsJava02.java -->

カスタムメッセージプロセッサを作成するにはどうすればよいですか?

FeatureMessageProcessor インターフェースを実装します:

=== "Kotlin"

<!--- INCLUDE
import ai.koog.agents.core.agent.AIAgent
import ai.koog.agents.core.feature.model.events.NodeExecutionStartingEvent
import ai.koog.agents.core.feature.model.events.LLMCallCompletedEvent
import ai.koog.agents.core.feature.message.FeatureMessage
import ai.koog.agents.core.feature.message.FeatureMessageProcessor
import ai.koog.agents.features.tracing.feature.Tracing
import ai.koog.prompt.executor.llms.all.simpleOllamaAIExecutor
import ai.koog.prompt.executor.ollama.client.OllamaModels
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.runBlocking
fun main() {
runBlocking {
-->
<!--- SUFFIX
    }
}
-->
```kotlin
class CustomTraceProcessor : FeatureMessageProcessor() {

    override suspend fun processMessage(message: FeatureMessage) {
        // カスタム処理ロジック
        if (message is NodeExecutionStartingEvent) {
            // ノード開始イベントを処理
        } else if (message is LLMCallCompletedEvent) {
            // LLMコール終了イベントを処理
        } else {
            // 他のイベントタイプを処理
        }
    }

    override suspend fun close() {
        // 確立されている場合は接続を閉じる
    }
}

val agent = AIAgent(
    promptExecutor = simpleOllamaAIExecutor(),
    llmModel = OllamaModels.Meta.LLAMA_3_2,
) {
    install(Tracing) {
        // カスタムプロセッサを使用する
        addMessageProcessor(CustomTraceProcessor())
    }
}
```
<!--- KNIT example-events-03.kt -->

=== "Java"

<!--- INCLUDE
import ai.koog.agents.core.agent.AIAgent;
import ai.koog.agents.core.feature.message.FeatureMessage;
import ai.koog.agents.core.feature.message.FeatureMessageProcessor;
import ai.koog.agents.core.feature.model.events.NodeExecutionStartingEvent;
import ai.koog.agents.core.feature.model.events.LLMCallCompletedEvent;
import ai.koog.agents.features.tracing.feature.Tracing;
import ai.koog.prompt.executor.model.PromptExecutor;
import ai.koog.prompt.executor.ollama.client.OllamaModels;
public class exampleEventsJava03 {
    public static void main(String[] args) {
-->
<!--- SUFFIX
    }
}
-->
```java
class CustomTraceProcessor extends FeatureMessageProcessor {

    @Override
    protected void handleMessage(FeatureMessage message) {
        // カスタム処理ロジック
        if (message instanceof NodeExecutionStartingEvent) {
            // ノード開始イベントを処理
        } else if (message instanceof LLMCallCompletedEvent) {
            // LLMコール終了イベントを処理
        } else {
            // 他のイベントタイプを処理
        }
    }

    @Override
    public void handleClose() {
        // 確立されている場合は接続を閉じる
    }
}

var agent = AIAgent.builder()
    .promptExecutor(PromptExecutor.builder().ollama().build())
    .llmModel(OllamaModels.Meta.LLAMA_3_2)

    .install(Tracing.Feature, config -> {
        // カスタムプロセッサを使用する
        config.addMessageProcessor(new CustomTraceProcessor());
    })
    .build();
```
<!--- KNIT exampleEventsJava03.java -->

メッセージプロセッサで処理できる既存のイベントタイプの詳細については、事前定義されたイベントタイプ を参照してください。