This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new acd919bab670 CAMEL-27313: camel-ai-observability - a genai dev console
with the agent runs, model calls and tool calls (#30539)
acd919bab670 is described below
commit acd919bab67033c0a0e5975b6001a0d60edafe01
Author: Claus Ibsen <[email protected]>
AuthorDate: Sat Nov 21 08:50:06 2026 +0100
CAMEL-27313: camel-ai-observability - a genai dev console with the agent
runs, model calls and tool calls (#30539)
* CAMEL-27313: camel-cli-connector - a genai action that answers with the
genai dev console
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Claus Ibsen <[email protected]>
---
.../apache/camel/catalog/dev-consoles-openapi.json | 557 ++++++++++++++++++++
.../apache/camel/catalog/dev-consoles.properties | 1 +
.../apache/camel/catalog/dev-consoles/genai.json | 572 +++++++++++++++++++++
.../camel/catalog/docs/ai-observability.adoc | 71 +++
.../org/apache/camel/dev-console/genai.json | 572 +++++++++++++++++++++
.../services/org/apache/camel/dev-console/genai | 2 +
.../org/apache/camel/dev-consoles.properties | 7 +
.../src/main/docs/ai-observability.adoc | 71 +++
.../ai/observability/GenAiConsoleText.java | 119 +++++
.../ai/observability/GenAiDevConsole.java | 163 ++++++
.../ai/observability/GenAiObservabilityImpl.java | 53 +-
.../component/ai/observability/GenAiRecorder.java | 524 +++++++++++++++++++
.../ai/observability/GenAiDevConsoleTest.java | 244 +++++++++
dsl/camel-cli-connector/pom.xml | 6 +
.../camel/cli/connector/LocalCliConnector.java | 22 +
.../LocalCliConnectorGenAiActionTest.java | 68 +++
16 files changed, 3049 insertions(+), 3 deletions(-)
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/dev-consoles-openapi.json
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/dev-consoles-openapi.json
index 14758bdfcd9a..dfaea0dacbb5 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/dev-consoles-openapi.json
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/dev-consoles-openapi.json
@@ -2378,6 +2378,563 @@
}
}
},
+ "\/q\/dev\/genai": {
+ "get": {
+ "summary": "GenAI",
+ "description": "The model calls, agent runs and
tool calls of the Camel AI components",
+ "operationId": "genai",
+ "parameters": [
+ {
+ "name": "content",
+ "in": "query",
+ "description": "Whether to add
the message content to the listed calls (only recorded at level full)",
+ "required": false,
+ "schema": {
+ "type": "boolean",
+ "default": false
+ }
+ },
+ {
+ "name": "id",
+ "in": "query",
+ "description": "The id of one
call (an agent run, a model call or a tool call) to answer with its content",
+ "required": false,
+ "schema": {
+ "type": "string"
+ }
+ },
+ {
+ "name": "limit",
+ "in": "query",
+ "description": "The number of
the newest top-level calls to list",
+ "required": false,
+ "schema": {
+ "type": "integer",
+ "default": 20
+ }
+ }
+ ],
+ "responses": {
+ "200": {
+ "description": "GenAI output",
+ "content": {
+ "application\/json": {
+ "schema": {
+ "type":
"object",
+
"properties": {
+
"recording": {
+
"type": "boolean",
+
"description": "Whether the calls are recorded: while the dev console
is enabled"
+
},
+
"level": {
+
"type": "string",
+
"description": "The observability level: basic, detailed or full"
+
},
+
"contentMaxLength": {
+
"type": "integer",
+
"description": "The cap on each recorded text"
+
},
+
"modelCalls": {
+
"type": "integer",
+
"description": "The model calls since start"
+
},
+
"agentRuns": {
+
"type": "integer",
+
"description": "The agent runs since start"
+
},
+
"toolCalls": {
+
"type": "integer",
+
"description": "The tool calls since start"
+
},
+
"errors": {
+
"type": "integer",
+
"description": "The calls that failed since start"
+
},
+
"inputTokens": {
+
"type": "integer",
+
"description": "The input tokens of the model calls since start"
+
},
+
"outputTokens": {
+
"type": "integer",
+
"description": "The output tokens of the model calls since start"
+
},
+
"cachedInputTokens": {
+
"type": "integer",
+
"description": "The input tokens read from the cache of the provider
since start"
+
},
+
"models": {
+
"type": "array",
+
"items": {
+
"type": "object",
+
"properties": {
+
"provider": {
+
"type": "string",
+
"description": "The provider, such as openai or
ollama"
+
},
+
"model": {
+
"type": "string",
+
"description": "The model, the response model
when known"
+
},
+
"calls": {
+
"type": "integer",
+
"description": "The model calls"
+
},
+
"errors": {
+
"type": "integer",
+
"description": "The model calls that failed"
+
},
+
"inputTokens": {
+
"type": "integer",
+
"description": "The input tokens"
+
},
+
"outputTokens": {
+
"type": "integer",
+
"description": "The output tokens"
+
},
+
"cachedInputTokens": {
+
"type": "integer",
+
"description": "The input tokens read from the
cache of the provider"
+
},
+
"durationMs": {
+
"type": "integer",
+
"description": "The time of the model calls in
millis"
+
}
+
},
+
"required": [
+
"calls",
+
"errors",
+
"inputTokens",
+
"outputTokens",
+
"cachedInputTokens",
+
"durationMs"
+
]
+
},
+
"description": "The model calls since start per provider and model"
+
},
+
"calls": {
+
"type": "array",
+
"items": {
+
"type": "object",
+
"properties": {
+
"id": {
+
"type": "string",
+
"description": "The id of the call"
+
},
+
"operation": {
+
"type": "string",
+
"description": "The GenAI operation:
invoke_agent, chat, embeddings, ..."
+
},
+
"name": {
+
"type": "string",
+
"description": "The name of the call, such as
chat gpt-4o"
+
},
+
"agentName": {
+
"type": "string",
+
"description": "The agent of an agent run"
+
},
+
"provider": {
+
"type": "string",
+
"description": "The provider"
+
},
+
"model": {
+
"type": "string",
+
"description": "The model"
+
},
+
"component": {
+
"type": "string",
+
"description": "The Camel component"
+
},
+
"conversationId": {
+
"type": "string",
+
"description": "The conversation (chat memory)
id"
+
},
+
"routeId": {
+
"type": "string",
+
"description": "The route of the call"
+
},
+
"exchangeId": {
+
"type": "string",
+
"description": "The exchange of the call"
+
},
+
"timestamp": {
+
"type": "integer",
+
"description": "When the call started, in epoch
millis"
+
},
+
"running": {
+
"type": "boolean",
+
"description": "Whether the call is still
running"
+
},
+
"durationMs": {
+
"type": "integer",
+
"description": "The time of the call in millis,
when it ended"
+
},
+
"inputTokens": {
+
"type": "integer",
+
"description": "The input tokens (of its model
calls, for an agent run)"
+
},
+
"outputTokens": {
+
"type": "integer",
+
"description": "The output tokens (of its model
calls, for an agent run)"
+
},
+
"cachedInputTokens": {
+
"type": "integer",
+
"description": "The input tokens read from the
cache (of its model calls, for an agent run)"
+
},
+
"finishReason": {
+
"type": "string",
+
"description": "The finish reason, such as stop
or tool_calls"
+
},
+
"error": {
+
"type": "string",
+
"description": "The exception type when the
call failed"
+
},
+
"modelCalls": {
+
"type": "integer",
+
"description": "The model calls of an agent run"
+
},
+
"toolCalls": {
+
"type": "integer",
+
"description": "The tool calls of an agent run"
+
},
+
"modelMs": {
+
"type": "integer",
+
"description": "The time of the model calls of
an agent run in millis"
+
},
+
"toolMs": {
+
"type": "integer",
+
"description": "The time of the tool calls of
an agent run in millis"
+
},
+
"steps": {
+
"type": "array",
+
"items": {
+
"type": "object",
+
"properties": {
+
"id": {
+
"type": "string",
+
"description": "The id
of the call"
+
},
+
"parentId": {
+
"type": "string",
+
"description": "The id
of the call it was made in"
+
},
+
"operation": {
+
"type": "string",
+
"description": "The
GenAI operation: chat, execute_tool, ..."
+
},
+
"name": {
+
"type": "string",
+
"description": "The
name of the call"
+
},
+
"toolName": {
+
"type": "string",
+
"description": "The
tool of a tool call"
+
},
+
"toolCallId": {
+
"type": "string",
+
"description": "The id
the model gave to the tool call"
+
},
+
"provider": {
+
"type": "string",
+
"description": "The
provider"
+
},
+
"model": {
+
"type": "string",
+
"description": "The
model of a model call"
+
},
+
"timestamp": {
+
"type": "integer",
+
"description": "When
the call started, in epoch millis"
+
},
+
"running": {
+
"type": "boolean",
+
"description": "Whether
the call is still running"
+
},
+
"durationMs": {
+
"type": "integer",
+
"description": "The
time of the call in millis, when it ended"
+
},
+
"inputTokens": {
+
"type": "integer",
+
"description": "The
input tokens of a model call"
+
},
+
"outputTokens": {
+
"type": "integer",
+
"description": "The
output tokens of a model call"
+
},
+
"cachedInputTokens": {
+
"type": "integer",
+
"description": "The
input tokens read from the cache"
+
},
+
"finishReason": {
+
"type": "string",
+
"description": "The
finish reason, such as stop or tool_calls"
+
},
+
"error": {
+
"type": "string",
+
"description": "The
exception type when the call failed"
+
},
+
"content": {
+
"type": "object",
+
"additionalProperties":
true,
+
"description": "The
content at level full"
+
}
+
},
+
"required": [
+
"timestamp",
+
"running"
+
]
+
},
+
"description": "The calls made inside this one,
in the order they started"
+
},
+
"droppedSteps": {
+
"type": "integer",
+
"description": "The steps not kept, beyond the
cap per call"
+
},
+
"question": {
+
"type": "string",
+
"description": "The first user message, with
content at level full"
+
},
+
"answer": {
+
"type": "string",
+
"description": "The last assistant message,
with content at level full"
+
},
+
"content": {
+
"type": "object",
+
"additionalProperties": true,
+
"description": "The content at level full:
systemInstructions, toolDefinitions, inputMessages, outputMessages,
toolArguments, toolResult"
+
}
+
},
+
"required": [
+
"timestamp",
+
"running"
+
]
+
},
+
"description": "The newest top-level calls (agent runs, and model calls
outside a run), newest first"
+
},
+
"moreCalls": {
+
"type": "integer",
+
"description": "The top-level calls not listed: beyond the limit, or no
longer kept"
+
},
+
"call": {
+
"type": "object",
+
"properties": {
+
"id": {
+
"type": "string",
+
"description": "The id of the call"
+
},
+
"operation": {
+
"type": "string",
+
"description": "The GenAI operation: invoke_agent,
chat, embeddings, ..."
+
},
+
"name": {
+
"type": "string",
+
"description": "The name of the call, such as chat
gpt-4o"
+
},
+
"agentName": {
+
"type": "string",
+
"description": "The agent of an agent run"
+
},
+
"provider": {
+
"type": "string",
+
"description": "The provider"
+
},
+
"model": {
+
"type": "string",
+
"description": "The model"
+
},
+
"component": {
+
"type": "string",
+
"description": "The Camel component"
+
},
+
"conversationId": {
+
"type": "string",
+
"description": "The conversation (chat memory) id"
+
},
+
"routeId": {
+
"type": "string",
+
"description": "The route of the call"
+
},
+
"exchangeId": {
+
"type": "string",
+
"description": "The exchange of the call"
+
},
+
"timestamp": {
+
"type": "integer",
+
"description": "When the call started, in epoch millis"
+
},
+
"running": {
+
"type": "boolean",
+
"description": "Whether the call is still running"
+
},
+
"durationMs": {
+
"type": "integer",
+
"description": "The time of the call in millis, when it
ended"
+
},
+
"inputTokens": {
+
"type": "integer",
+
"description": "The input tokens (of its model calls,
for an agent run)"
+
},
+
"outputTokens": {
+
"type": "integer",
+
"description": "The output tokens (of its model calls,
for an agent run)"
+
},
+
"cachedInputTokens": {
+
"type": "integer",
+
"description": "The input tokens read from the cache
(of its model calls, for an agent run)"
+
},
+
"finishReason": {
+
"type": "string",
+
"description": "The finish reason, such as stop or
tool_calls"
+
},
+
"error": {
+
"type": "string",
+
"description": "The exception type when the call failed"
+
},
+
"modelCalls": {
+
"type": "integer",
+
"description": "The model calls of an agent run"
+
},
+
"toolCalls": {
+
"type": "integer",
+
"description": "The tool calls of an agent run"
+
},
+
"modelMs": {
+
"type": "integer",
+
"description": "The time of the model calls of an agent
run in millis"
+
},
+
"toolMs": {
+
"type": "integer",
+
"description": "The time of the tool calls of an agent
run in millis"
+
},
+
"steps": {
+
"type": "array",
+
"items": {
+
"type": "object",
+
"properties": {
+
"id": {
+
"type": "string",
+
"description": "The id of the
call"
+
},
+
"parentId": {
+
"type": "string",
+
"description": "The id of the
call it was made in"
+
},
+
"operation": {
+
"type": "string",
+
"description": "The GenAI
operation: chat, execute_tool, ..."
+
},
+
"name": {
+
"type": "string",
+
"description": "The name of the
call"
+
},
+
"toolName": {
+
"type": "string",
+
"description": "The tool of a
tool call"
+
},
+
"toolCallId": {
+
"type": "string",
+
"description": "The id the
model gave to the tool call"
+
},
+
"provider": {
+
"type": "string",
+
"description": "The provider"
+
},
+
"model": {
+
"type": "string",
+
"description": "The model of a
model call"
+
},
+
"timestamp": {
+
"type": "integer",
+
"description": "When the call
started, in epoch millis"
+
},
+
"running": {
+
"type": "boolean",
+
"description": "Whether the
call is still running"
+
},
+
"durationMs": {
+
"type": "integer",
+
"description": "The time of the
call in millis, when it ended"
+
},
+
"inputTokens": {
+
"type": "integer",
+
"description": "The input
tokens of a model call"
+
},
+
"outputTokens": {
+
"type": "integer",
+
"description": "The output
tokens of a model call"
+
},
+
"cachedInputTokens": {
+
"type": "integer",
+
"description": "The input
tokens read from the cache"
+
},
+
"finishReason": {
+
"type": "string",
+
"description": "The finish
reason, such as stop or tool_calls"
+
},
+
"error": {
+
"type": "string",
+
"description": "The exception
type when the call failed"
+
},
+
"content": {
+
"type": "object",
+
"additionalProperties": true,
+
"description": "The content at
level full"
+
}
+
},
+
"required": [
+
"timestamp",
+
"running"
+
]
+
},
+
"description": "The calls made inside this one, in the
order they started"
+
},
+
"droppedSteps": {
+
"type": "integer",
+
"description": "The steps not kept, beyond the cap per
call"
+
},
+
"question": {
+
"type": "string",
+
"description": "The first user message, with content at
level full"
+
},
+
"answer": {
+
"type": "string",
+
"description": "The last assistant message, with
content at level full"
+
},
+
"content": {
+
"type": "object",
+
"additionalProperties": true,
+
"description": "The content at level full:
systemInstructions, toolDefinitions, inputMessages, outputMessages,
toolArguments, toolResult"
+
}
+
},
+
"required": [
+
"timestamp",
+
"running"
+
],
+
"description": "The call asked for with the id option"
+
},
+
"error": {
+
"type": "string",
+
"description": "Why the call asked for is not there"
+
}
+ },
+
"required": [
+
"recording",
+
"contentMaxLength",
+
"modelCalls",
+
"agentRuns",
+
"toolCalls",
+
"errors",
+
"inputTokens",
+
"outputTokens",
+
"cachedInputTokens"
+ ]
+ }
+ }
+ }
+ }
+ }
+ }
+ },
"\/q\/dev\/groovy": {
"get": {
"summary": "Groovy",
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/dev-consoles.properties
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/dev-consoles.properties
index 2044b86675e2..35a483c87ebf 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/dev-consoles.properties
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/dev-consoles.properties
@@ -21,6 +21,7 @@ event
fault-tolerance
gc
gcp-secrets
+genai
groovy
hashicorp-secrets
health
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/dev-consoles/genai.json
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/dev-consoles/genai.json
new file mode 100644
index 000000000000..37c6600bad7b
--- /dev/null
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/dev-consoles/genai.json
@@ -0,0 +1,572 @@
+{
+ "console": {
+ "kind": "console",
+ "group": "camel",
+ "name": "genai",
+ "title": "GenAI",
+ "description": "The model calls, agent runs and tool calls of the Camel AI
components",
+ "deprecated": false,
+ "readOnly": true,
+ "javaType": "org.apache.camel.component.ai.observability.GenAiDevConsole",
+ "groupId": "org.apache.camel",
+ "artifactId": "camel-ai-observability",
+ "version": "4.24.0-SNAPSHOT"
+ },
+ "options": {
+ "content": {
+ "index": 0,
+ "kind": "option",
+ "displayName": "Content",
+ "group": "query",
+ "label": "query",
+ "required": false,
+ "type": "boolean",
+ "javaType": "java.lang.Boolean",
+ "deprecated": false,
+ "autowired": false,
+ "secret": false,
+ "defaultValue": false,
+ "description": "Whether to add the message content to the listed calls
(only recorded at level full)"
+ },
+ "id": {
+ "index": 1,
+ "kind": "option",
+ "displayName": "Id",
+ "group": "query",
+ "label": "query",
+ "required": false,
+ "type": "string",
+ "javaType": "java.lang.String",
+ "deprecated": false,
+ "autowired": false,
+ "secret": false,
+ "description": "The id of one call (an agent run, a model call or a tool
call) to answer with its content"
+ },
+ "limit": {
+ "index": 2,
+ "kind": "option",
+ "displayName": "Limit",
+ "group": "query",
+ "label": "query",
+ "required": false,
+ "type": "integer",
+ "javaType": "java.lang.Integer",
+ "deprecated": false,
+ "autowired": false,
+ "secret": false,
+ "defaultValue": 20,
+ "description": "The number of the newest top-level calls to list"
+ }
+ },
+ "response": {
+ "type": "object",
+ "properties": {
+ "recording": {
+ "type": "boolean",
+ "description": "Whether the calls are recorded: while the dev console
is enabled"
+ },
+ "level": {
+ "type": "string",
+ "description": "The observability level: basic, detailed or full"
+ },
+ "contentMaxLength": {
+ "type": "integer",
+ "description": "The cap on each recorded text"
+ },
+ "modelCalls": {
+ "type": "integer",
+ "description": "The model calls since start"
+ },
+ "agentRuns": {
+ "type": "integer",
+ "description": "The agent runs since start"
+ },
+ "toolCalls": {
+ "type": "integer",
+ "description": "The tool calls since start"
+ },
+ "errors": {
+ "type": "integer",
+ "description": "The calls that failed since start"
+ },
+ "inputTokens": {
+ "type": "integer",
+ "description": "The input tokens of the model calls since start"
+ },
+ "outputTokens": {
+ "type": "integer",
+ "description": "The output tokens of the model calls since start"
+ },
+ "cachedInputTokens": {
+ "type": "integer",
+ "description": "The input tokens read from the cache of the provider
since start"
+ },
+ "models": {
+ "type": "array",
+ "items": {
+ "type": "object",
+ "properties": {
+ "provider": {
+ "type": "string",
+ "description": "The provider, such as openai or ollama"
+ },
+ "model": {
+ "type": "string",
+ "description": "The model, the response model when known"
+ },
+ "calls": {
+ "type": "integer",
+ "description": "The model calls"
+ },
+ "errors": {
+ "type": "integer",
+ "description": "The model calls that failed"
+ },
+ "inputTokens": {
+ "type": "integer",
+ "description": "The input tokens"
+ },
+ "outputTokens": {
+ "type": "integer",
+ "description": "The output tokens"
+ },
+ "cachedInputTokens": {
+ "type": "integer",
+ "description": "The input tokens read from the cache of the
provider"
+ },
+ "durationMs": {
+ "type": "integer",
+ "description": "The time of the model calls in millis"
+ }
+ },
+ "required": [
+ "calls",
+ "errors",
+ "inputTokens",
+ "outputTokens",
+ "cachedInputTokens",
+ "durationMs"
+ ]
+ },
+ "description": "The model calls since start per provider and model"
+ },
+ "calls": {
+ "type": "array",
+ "items": {
+ "type": "object",
+ "properties": {
+ "id": {
+ "type": "string",
+ "description": "The id of the call"
+ },
+ "operation": {
+ "type": "string",
+ "description": "The GenAI operation: invoke_agent, chat,
embeddings, ..."
+ },
+ "name": {
+ "type": "string",
+ "description": "The name of the call, such as chat gpt-4o"
+ },
+ "agentName": {
+ "type": "string",
+ "description": "The agent of an agent run"
+ },
+ "provider": {
+ "type": "string",
+ "description": "The provider"
+ },
+ "model": {
+ "type": "string",
+ "description": "The model"
+ },
+ "component": {
+ "type": "string",
+ "description": "The Camel component"
+ },
+ "conversationId": {
+ "type": "string",
+ "description": "The conversation (chat memory) id"
+ },
+ "routeId": {
+ "type": "string",
+ "description": "The route of the call"
+ },
+ "exchangeId": {
+ "type": "string",
+ "description": "The exchange of the call"
+ },
+ "timestamp": {
+ "type": "integer",
+ "description": "When the call started, in epoch millis"
+ },
+ "running": {
+ "type": "boolean",
+ "description": "Whether the call is still running"
+ },
+ "durationMs": {
+ "type": "integer",
+ "description": "The time of the call in millis, when it ended"
+ },
+ "inputTokens": {
+ "type": "integer",
+ "description": "The input tokens (of its model calls, for an
agent run)"
+ },
+ "outputTokens": {
+ "type": "integer",
+ "description": "The output tokens (of its model calls, for an
agent run)"
+ },
+ "cachedInputTokens": {
+ "type": "integer",
+ "description": "The input tokens read from the cache (of its
model calls, for an agent run)"
+ },
+ "finishReason": {
+ "type": "string",
+ "description": "The finish reason, such as stop or tool_calls"
+ },
+ "error": {
+ "type": "string",
+ "description": "The exception type when the call failed"
+ },
+ "modelCalls": {
+ "type": "integer",
+ "description": "The model calls of an agent run"
+ },
+ "toolCalls": {
+ "type": "integer",
+ "description": "The tool calls of an agent run"
+ },
+ "modelMs": {
+ "type": "integer",
+ "description": "The time of the model calls of an agent run in
millis"
+ },
+ "toolMs": {
+ "type": "integer",
+ "description": "The time of the tool calls of an agent run in
millis"
+ },
+ "steps": {
+ "type": "array",
+ "items": {
+ "type": "object",
+ "properties": {
+ "id": {
+ "type": "string",
+ "description": "The id of the call"
+ },
+ "parentId": {
+ "type": "string",
+ "description": "The id of the call it was made in"
+ },
+ "operation": {
+ "type": "string",
+ "description": "The GenAI operation: chat, execute_tool,
..."
+ },
+ "name": {
+ "type": "string",
+ "description": "The name of the call"
+ },
+ "toolName": {
+ "type": "string",
+ "description": "The tool of a tool call"
+ },
+ "toolCallId": {
+ "type": "string",
+ "description": "The id the model gave to the tool call"
+ },
+ "provider": {
+ "type": "string",
+ "description": "The provider"
+ },
+ "model": {
+ "type": "string",
+ "description": "The model of a model call"
+ },
+ "timestamp": {
+ "type": "integer",
+ "description": "When the call started, in epoch millis"
+ },
+ "running": {
+ "type": "boolean",
+ "description": "Whether the call is still running"
+ },
+ "durationMs": {
+ "type": "integer",
+ "description": "The time of the call in millis, when it
ended"
+ },
+ "inputTokens": {
+ "type": "integer",
+ "description": "The input tokens of a model call"
+ },
+ "outputTokens": {
+ "type": "integer",
+ "description": "The output tokens of a model call"
+ },
+ "cachedInputTokens": {
+ "type": "integer",
+ "description": "The input tokens read from the cache"
+ },
+ "finishReason": {
+ "type": "string",
+ "description": "The finish reason, such as stop or
tool_calls"
+ },
+ "error": {
+ "type": "string",
+ "description": "The exception type when the call failed"
+ },
+ "content": {
+ "type": "object",
+ "additionalProperties": true,
+ "description": "The content at level full"
+ }
+ },
+ "required": [
+ "timestamp",
+ "running"
+ ]
+ },
+ "description": "The calls made inside this one, in the order
they started"
+ },
+ "droppedSteps": {
+ "type": "integer",
+ "description": "The steps not kept, beyond the cap per call"
+ },
+ "question": {
+ "type": "string",
+ "description": "The first user message, with content at level
full"
+ },
+ "answer": {
+ "type": "string",
+ "description": "The last assistant message, with content at
level full"
+ },
+ "content": {
+ "type": "object",
+ "additionalProperties": true,
+ "description": "The content at level full: systemInstructions,
toolDefinitions, inputMessages, outputMessages, toolArguments, toolResult"
+ }
+ },
+ "required": [
+ "timestamp",
+ "running"
+ ]
+ },
+ "description": "The newest top-level calls (agent runs, and model
calls outside a run), newest first"
+ },
+ "moreCalls": {
+ "type": "integer",
+ "description": "The top-level calls not listed: beyond the limit, or
no longer kept"
+ },
+ "call": {
+ "type": "object",
+ "properties": {
+ "id": {
+ "type": "string",
+ "description": "The id of the call"
+ },
+ "operation": {
+ "type": "string",
+ "description": "The GenAI operation: invoke_agent, chat,
embeddings, ..."
+ },
+ "name": {
+ "type": "string",
+ "description": "The name of the call, such as chat gpt-4o"
+ },
+ "agentName": {
+ "type": "string",
+ "description": "The agent of an agent run"
+ },
+ "provider": {
+ "type": "string",
+ "description": "The provider"
+ },
+ "model": {
+ "type": "string",
+ "description": "The model"
+ },
+ "component": {
+ "type": "string",
+ "description": "The Camel component"
+ },
+ "conversationId": {
+ "type": "string",
+ "description": "The conversation (chat memory) id"
+ },
+ "routeId": {
+ "type": "string",
+ "description": "The route of the call"
+ },
+ "exchangeId": {
+ "type": "string",
+ "description": "The exchange of the call"
+ },
+ "timestamp": {
+ "type": "integer",
+ "description": "When the call started, in epoch millis"
+ },
+ "running": {
+ "type": "boolean",
+ "description": "Whether the call is still running"
+ },
+ "durationMs": {
+ "type": "integer",
+ "description": "The time of the call in millis, when it ended"
+ },
+ "inputTokens": {
+ "type": "integer",
+ "description": "The input tokens (of its model calls, for an agent
run)"
+ },
+ "outputTokens": {
+ "type": "integer",
+ "description": "The output tokens (of its model calls, for an
agent run)"
+ },
+ "cachedInputTokens": {
+ "type": "integer",
+ "description": "The input tokens read from the cache (of its model
calls, for an agent run)"
+ },
+ "finishReason": {
+ "type": "string",
+ "description": "The finish reason, such as stop or tool_calls"
+ },
+ "error": {
+ "type": "string",
+ "description": "The exception type when the call failed"
+ },
+ "modelCalls": {
+ "type": "integer",
+ "description": "The model calls of an agent run"
+ },
+ "toolCalls": {
+ "type": "integer",
+ "description": "The tool calls of an agent run"
+ },
+ "modelMs": {
+ "type": "integer",
+ "description": "The time of the model calls of an agent run in
millis"
+ },
+ "toolMs": {
+ "type": "integer",
+ "description": "The time of the tool calls of an agent run in
millis"
+ },
+ "steps": {
+ "type": "array",
+ "items": {
+ "type": "object",
+ "properties": {
+ "id": {
+ "type": "string",
+ "description": "The id of the call"
+ },
+ "parentId": {
+ "type": "string",
+ "description": "The id of the call it was made in"
+ },
+ "operation": {
+ "type": "string",
+ "description": "The GenAI operation: chat, execute_tool, ..."
+ },
+ "name": {
+ "type": "string",
+ "description": "The name of the call"
+ },
+ "toolName": {
+ "type": "string",
+ "description": "The tool of a tool call"
+ },
+ "toolCallId": {
+ "type": "string",
+ "description": "The id the model gave to the tool call"
+ },
+ "provider": {
+ "type": "string",
+ "description": "The provider"
+ },
+ "model": {
+ "type": "string",
+ "description": "The model of a model call"
+ },
+ "timestamp": {
+ "type": "integer",
+ "description": "When the call started, in epoch millis"
+ },
+ "running": {
+ "type": "boolean",
+ "description": "Whether the call is still running"
+ },
+ "durationMs": {
+ "type": "integer",
+ "description": "The time of the call in millis, when it
ended"
+ },
+ "inputTokens": {
+ "type": "integer",
+ "description": "The input tokens of a model call"
+ },
+ "outputTokens": {
+ "type": "integer",
+ "description": "The output tokens of a model call"
+ },
+ "cachedInputTokens": {
+ "type": "integer",
+ "description": "The input tokens read from the cache"
+ },
+ "finishReason": {
+ "type": "string",
+ "description": "The finish reason, such as stop or
tool_calls"
+ },
+ "error": {
+ "type": "string",
+ "description": "The exception type when the call failed"
+ },
+ "content": {
+ "type": "object",
+ "additionalProperties": true,
+ "description": "The content at level full"
+ }
+ },
+ "required": [
+ "timestamp",
+ "running"
+ ]
+ },
+ "description": "The calls made inside this one, in the order they
started"
+ },
+ "droppedSteps": {
+ "type": "integer",
+ "description": "The steps not kept, beyond the cap per call"
+ },
+ "question": {
+ "type": "string",
+ "description": "The first user message, with content at level full"
+ },
+ "answer": {
+ "type": "string",
+ "description": "The last assistant message, with content at level
full"
+ },
+ "content": {
+ "type": "object",
+ "additionalProperties": true,
+ "description": "The content at level full: systemInstructions,
toolDefinitions, inputMessages, outputMessages, toolArguments, toolResult"
+ }
+ },
+ "required": [
+ "timestamp",
+ "running"
+ ],
+ "description": "The call asked for with the id option"
+ },
+ "error": {
+ "type": "string",
+ "description": "Why the call asked for is not there"
+ }
+ },
+ "required": [
+ "recording",
+ "contentMaxLength",
+ "modelCalls",
+ "agentRuns",
+ "toolCalls",
+ "errors",
+ "inputTokens",
+ "outputTokens",
+ "cachedInputTokens"
+ ]
+ }
+}
+
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/ai-observability.adoc
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/ai-observability.adoc
index 1d926f5b1718..75f4ba24f555 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/ai-observability.adoc
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/ai-observability.adoc
@@ -197,6 +197,77 @@ messages.
* Session and user ids set as OpenTelemetry baggage (for example through
`CamelBaggage_` exchange properties) are sent
to every downstream service that propagates baggage, including the LLM
provider when its HTTP client is instrumented.
+== GenAI dev console
+
+The `genai` dev console shows the GenAI calls of the running application,
without a tracer or a metrics backend:
+
+* the totals since start: the model calls per provider and model (calls,
failed calls, input, output and cached input
+tokens, time), the agent runs and the tool calls
+* the newest top-level calls (agent runs, and model calls outside a run),
newest first, each agent run with its model
+calls and tool calls in the order they started
+* the observability level in use
+
+The calls are recorded while the dev console is enabled
(`camel.main.devConsoleEnabled=true`), which the dev profile
+does (for example with `camel run`). Without it nothing is recorded, as in
production by default. The console keeps the
+newest 50 top-level calls, and 200 steps per call. Agent runs and tool calls
are only there from level `detailed`, as
+the producers observe them from that level.
+
+[width="100%",cols="15%,15%,70%",options="header"]
+|===
+| Option | Default | Description
+| `limit` | 20 | The number of the newest top-level calls to list.
+| `content` | `false` | Whether to add the message content to the listed
calls, with the first user message
+(`question`) and the last assistant message (`answer`) of each run.
+| `id` | | The id of one call (an agent run, a model call or a tool call) to
answer with, with its content.
+|===
+
+The content (`systemInstructions`, `toolDefinitions`, `inputMessages`,
`outputMessages`, `toolArguments` and
+`toolResult`) is only recorded at level `full`, capped at
`camel.aiObservability.contentMaxLength` as on the spans, and
+only in the answer when asked with `content` or `id`. The messages are in the
GenAI messages format of the spans.
+
+Over HTTP the console is on the management server (`camel run --console`), as
text or as JSON:
+
+[source,bash]
+----
+curl http://localhost:8080/q/dev/genai
+curl -H 'Accept: application/json' 'http://localhost:8080/q/dev/genai?id=7'
+----
+
+An agent run in the JSON answer, shortened:
+
+[source,json]
+----
+{
+ "id": "7",
+ "operation": "invoke_agent",
+ "name": "invoke_agent support",
+ "agentName": "support",
+ "provider": "ollama",
+ "model": "granite4:3b",
+ "routeId": "support",
+ "running": false,
+ "durationMs": 2310,
+ "modelCalls": 2,
+ "toolCalls": 1,
+ "inputTokens": 700,
+ "outputTokens": 60,
+ "cachedInputTokens": 270,
+ "modelMs": 2240,
+ "toolMs": 5,
+ "steps": [
+ { "id": "8", "parentId": "7", "operation": "chat", "name": "chat
granite4:3b", "durationMs": 1180,
+ "inputTokens": 300, "outputTokens": 40, "cachedInputTokens": 270,
"finishReason": "tool_calls" },
+ { "id": "9", "parentId": "7", "operation": "execute_tool", "name":
"execute_tool lookupStock", "toolName": "lookupStock",
+ "durationMs": 5 },
+ { "id": "10", "parentId": "7", "operation": "chat", "name": "chat
granite4:3b", "durationMs": 1060,
+ "inputTokens": 400, "outputTokens": 20, "finishReason": "stop" }
+ ]
+}
+----
+
+The steps are a flat list: `parentId` is the call a step was made in, such as
the tool call for a model call made by
+the route of a tool.
+
== Camel TUI integration
When monitoring a running integration with `camel tui` and observability
enabled, the AI panel usage view
diff --git
a/components/camel-ai/camel-ai-observability/src/generated/resources/META-INF/org/apache/camel/dev-console/genai.json
b/components/camel-ai/camel-ai-observability/src/generated/resources/META-INF/org/apache/camel/dev-console/genai.json
new file mode 100644
index 000000000000..37c6600bad7b
--- /dev/null
+++
b/components/camel-ai/camel-ai-observability/src/generated/resources/META-INF/org/apache/camel/dev-console/genai.json
@@ -0,0 +1,572 @@
+{
+ "console": {
+ "kind": "console",
+ "group": "camel",
+ "name": "genai",
+ "title": "GenAI",
+ "description": "The model calls, agent runs and tool calls of the Camel AI
components",
+ "deprecated": false,
+ "readOnly": true,
+ "javaType": "org.apache.camel.component.ai.observability.GenAiDevConsole",
+ "groupId": "org.apache.camel",
+ "artifactId": "camel-ai-observability",
+ "version": "4.24.0-SNAPSHOT"
+ },
+ "options": {
+ "content": {
+ "index": 0,
+ "kind": "option",
+ "displayName": "Content",
+ "group": "query",
+ "label": "query",
+ "required": false,
+ "type": "boolean",
+ "javaType": "java.lang.Boolean",
+ "deprecated": false,
+ "autowired": false,
+ "secret": false,
+ "defaultValue": false,
+ "description": "Whether to add the message content to the listed calls
(only recorded at level full)"
+ },
+ "id": {
+ "index": 1,
+ "kind": "option",
+ "displayName": "Id",
+ "group": "query",
+ "label": "query",
+ "required": false,
+ "type": "string",
+ "javaType": "java.lang.String",
+ "deprecated": false,
+ "autowired": false,
+ "secret": false,
+ "description": "The id of one call (an agent run, a model call or a tool
call) to answer with its content"
+ },
+ "limit": {
+ "index": 2,
+ "kind": "option",
+ "displayName": "Limit",
+ "group": "query",
+ "label": "query",
+ "required": false,
+ "type": "integer",
+ "javaType": "java.lang.Integer",
+ "deprecated": false,
+ "autowired": false,
+ "secret": false,
+ "defaultValue": 20,
+ "description": "The number of the newest top-level calls to list"
+ }
+ },
+ "response": {
+ "type": "object",
+ "properties": {
+ "recording": {
+ "type": "boolean",
+ "description": "Whether the calls are recorded: while the dev console
is enabled"
+ },
+ "level": {
+ "type": "string",
+ "description": "The observability level: basic, detailed or full"
+ },
+ "contentMaxLength": {
+ "type": "integer",
+ "description": "The cap on each recorded text"
+ },
+ "modelCalls": {
+ "type": "integer",
+ "description": "The model calls since start"
+ },
+ "agentRuns": {
+ "type": "integer",
+ "description": "The agent runs since start"
+ },
+ "toolCalls": {
+ "type": "integer",
+ "description": "The tool calls since start"
+ },
+ "errors": {
+ "type": "integer",
+ "description": "The calls that failed since start"
+ },
+ "inputTokens": {
+ "type": "integer",
+ "description": "The input tokens of the model calls since start"
+ },
+ "outputTokens": {
+ "type": "integer",
+ "description": "The output tokens of the model calls since start"
+ },
+ "cachedInputTokens": {
+ "type": "integer",
+ "description": "The input tokens read from the cache of the provider
since start"
+ },
+ "models": {
+ "type": "array",
+ "items": {
+ "type": "object",
+ "properties": {
+ "provider": {
+ "type": "string",
+ "description": "The provider, such as openai or ollama"
+ },
+ "model": {
+ "type": "string",
+ "description": "The model, the response model when known"
+ },
+ "calls": {
+ "type": "integer",
+ "description": "The model calls"
+ },
+ "errors": {
+ "type": "integer",
+ "description": "The model calls that failed"
+ },
+ "inputTokens": {
+ "type": "integer",
+ "description": "The input tokens"
+ },
+ "outputTokens": {
+ "type": "integer",
+ "description": "The output tokens"
+ },
+ "cachedInputTokens": {
+ "type": "integer",
+ "description": "The input tokens read from the cache of the
provider"
+ },
+ "durationMs": {
+ "type": "integer",
+ "description": "The time of the model calls in millis"
+ }
+ },
+ "required": [
+ "calls",
+ "errors",
+ "inputTokens",
+ "outputTokens",
+ "cachedInputTokens",
+ "durationMs"
+ ]
+ },
+ "description": "The model calls since start per provider and model"
+ },
+ "calls": {
+ "type": "array",
+ "items": {
+ "type": "object",
+ "properties": {
+ "id": {
+ "type": "string",
+ "description": "The id of the call"
+ },
+ "operation": {
+ "type": "string",
+ "description": "The GenAI operation: invoke_agent, chat,
embeddings, ..."
+ },
+ "name": {
+ "type": "string",
+ "description": "The name of the call, such as chat gpt-4o"
+ },
+ "agentName": {
+ "type": "string",
+ "description": "The agent of an agent run"
+ },
+ "provider": {
+ "type": "string",
+ "description": "The provider"
+ },
+ "model": {
+ "type": "string",
+ "description": "The model"
+ },
+ "component": {
+ "type": "string",
+ "description": "The Camel component"
+ },
+ "conversationId": {
+ "type": "string",
+ "description": "The conversation (chat memory) id"
+ },
+ "routeId": {
+ "type": "string",
+ "description": "The route of the call"
+ },
+ "exchangeId": {
+ "type": "string",
+ "description": "The exchange of the call"
+ },
+ "timestamp": {
+ "type": "integer",
+ "description": "When the call started, in epoch millis"
+ },
+ "running": {
+ "type": "boolean",
+ "description": "Whether the call is still running"
+ },
+ "durationMs": {
+ "type": "integer",
+ "description": "The time of the call in millis, when it ended"
+ },
+ "inputTokens": {
+ "type": "integer",
+ "description": "The input tokens (of its model calls, for an
agent run)"
+ },
+ "outputTokens": {
+ "type": "integer",
+ "description": "The output tokens (of its model calls, for an
agent run)"
+ },
+ "cachedInputTokens": {
+ "type": "integer",
+ "description": "The input tokens read from the cache (of its
model calls, for an agent run)"
+ },
+ "finishReason": {
+ "type": "string",
+ "description": "The finish reason, such as stop or tool_calls"
+ },
+ "error": {
+ "type": "string",
+ "description": "The exception type when the call failed"
+ },
+ "modelCalls": {
+ "type": "integer",
+ "description": "The model calls of an agent run"
+ },
+ "toolCalls": {
+ "type": "integer",
+ "description": "The tool calls of an agent run"
+ },
+ "modelMs": {
+ "type": "integer",
+ "description": "The time of the model calls of an agent run in
millis"
+ },
+ "toolMs": {
+ "type": "integer",
+ "description": "The time of the tool calls of an agent run in
millis"
+ },
+ "steps": {
+ "type": "array",
+ "items": {
+ "type": "object",
+ "properties": {
+ "id": {
+ "type": "string",
+ "description": "The id of the call"
+ },
+ "parentId": {
+ "type": "string",
+ "description": "The id of the call it was made in"
+ },
+ "operation": {
+ "type": "string",
+ "description": "The GenAI operation: chat, execute_tool,
..."
+ },
+ "name": {
+ "type": "string",
+ "description": "The name of the call"
+ },
+ "toolName": {
+ "type": "string",
+ "description": "The tool of a tool call"
+ },
+ "toolCallId": {
+ "type": "string",
+ "description": "The id the model gave to the tool call"
+ },
+ "provider": {
+ "type": "string",
+ "description": "The provider"
+ },
+ "model": {
+ "type": "string",
+ "description": "The model of a model call"
+ },
+ "timestamp": {
+ "type": "integer",
+ "description": "When the call started, in epoch millis"
+ },
+ "running": {
+ "type": "boolean",
+ "description": "Whether the call is still running"
+ },
+ "durationMs": {
+ "type": "integer",
+ "description": "The time of the call in millis, when it
ended"
+ },
+ "inputTokens": {
+ "type": "integer",
+ "description": "The input tokens of a model call"
+ },
+ "outputTokens": {
+ "type": "integer",
+ "description": "The output tokens of a model call"
+ },
+ "cachedInputTokens": {
+ "type": "integer",
+ "description": "The input tokens read from the cache"
+ },
+ "finishReason": {
+ "type": "string",
+ "description": "The finish reason, such as stop or
tool_calls"
+ },
+ "error": {
+ "type": "string",
+ "description": "The exception type when the call failed"
+ },
+ "content": {
+ "type": "object",
+ "additionalProperties": true,
+ "description": "The content at level full"
+ }
+ },
+ "required": [
+ "timestamp",
+ "running"
+ ]
+ },
+ "description": "The calls made inside this one, in the order
they started"
+ },
+ "droppedSteps": {
+ "type": "integer",
+ "description": "The steps not kept, beyond the cap per call"
+ },
+ "question": {
+ "type": "string",
+ "description": "The first user message, with content at level
full"
+ },
+ "answer": {
+ "type": "string",
+ "description": "The last assistant message, with content at
level full"
+ },
+ "content": {
+ "type": "object",
+ "additionalProperties": true,
+ "description": "The content at level full: systemInstructions,
toolDefinitions, inputMessages, outputMessages, toolArguments, toolResult"
+ }
+ },
+ "required": [
+ "timestamp",
+ "running"
+ ]
+ },
+ "description": "The newest top-level calls (agent runs, and model
calls outside a run), newest first"
+ },
+ "moreCalls": {
+ "type": "integer",
+ "description": "The top-level calls not listed: beyond the limit, or
no longer kept"
+ },
+ "call": {
+ "type": "object",
+ "properties": {
+ "id": {
+ "type": "string",
+ "description": "The id of the call"
+ },
+ "operation": {
+ "type": "string",
+ "description": "The GenAI operation: invoke_agent, chat,
embeddings, ..."
+ },
+ "name": {
+ "type": "string",
+ "description": "The name of the call, such as chat gpt-4o"
+ },
+ "agentName": {
+ "type": "string",
+ "description": "The agent of an agent run"
+ },
+ "provider": {
+ "type": "string",
+ "description": "The provider"
+ },
+ "model": {
+ "type": "string",
+ "description": "The model"
+ },
+ "component": {
+ "type": "string",
+ "description": "The Camel component"
+ },
+ "conversationId": {
+ "type": "string",
+ "description": "The conversation (chat memory) id"
+ },
+ "routeId": {
+ "type": "string",
+ "description": "The route of the call"
+ },
+ "exchangeId": {
+ "type": "string",
+ "description": "The exchange of the call"
+ },
+ "timestamp": {
+ "type": "integer",
+ "description": "When the call started, in epoch millis"
+ },
+ "running": {
+ "type": "boolean",
+ "description": "Whether the call is still running"
+ },
+ "durationMs": {
+ "type": "integer",
+ "description": "The time of the call in millis, when it ended"
+ },
+ "inputTokens": {
+ "type": "integer",
+ "description": "The input tokens (of its model calls, for an agent
run)"
+ },
+ "outputTokens": {
+ "type": "integer",
+ "description": "The output tokens (of its model calls, for an
agent run)"
+ },
+ "cachedInputTokens": {
+ "type": "integer",
+ "description": "The input tokens read from the cache (of its model
calls, for an agent run)"
+ },
+ "finishReason": {
+ "type": "string",
+ "description": "The finish reason, such as stop or tool_calls"
+ },
+ "error": {
+ "type": "string",
+ "description": "The exception type when the call failed"
+ },
+ "modelCalls": {
+ "type": "integer",
+ "description": "The model calls of an agent run"
+ },
+ "toolCalls": {
+ "type": "integer",
+ "description": "The tool calls of an agent run"
+ },
+ "modelMs": {
+ "type": "integer",
+ "description": "The time of the model calls of an agent run in
millis"
+ },
+ "toolMs": {
+ "type": "integer",
+ "description": "The time of the tool calls of an agent run in
millis"
+ },
+ "steps": {
+ "type": "array",
+ "items": {
+ "type": "object",
+ "properties": {
+ "id": {
+ "type": "string",
+ "description": "The id of the call"
+ },
+ "parentId": {
+ "type": "string",
+ "description": "The id of the call it was made in"
+ },
+ "operation": {
+ "type": "string",
+ "description": "The GenAI operation: chat, execute_tool, ..."
+ },
+ "name": {
+ "type": "string",
+ "description": "The name of the call"
+ },
+ "toolName": {
+ "type": "string",
+ "description": "The tool of a tool call"
+ },
+ "toolCallId": {
+ "type": "string",
+ "description": "The id the model gave to the tool call"
+ },
+ "provider": {
+ "type": "string",
+ "description": "The provider"
+ },
+ "model": {
+ "type": "string",
+ "description": "The model of a model call"
+ },
+ "timestamp": {
+ "type": "integer",
+ "description": "When the call started, in epoch millis"
+ },
+ "running": {
+ "type": "boolean",
+ "description": "Whether the call is still running"
+ },
+ "durationMs": {
+ "type": "integer",
+ "description": "The time of the call in millis, when it
ended"
+ },
+ "inputTokens": {
+ "type": "integer",
+ "description": "The input tokens of a model call"
+ },
+ "outputTokens": {
+ "type": "integer",
+ "description": "The output tokens of a model call"
+ },
+ "cachedInputTokens": {
+ "type": "integer",
+ "description": "The input tokens read from the cache"
+ },
+ "finishReason": {
+ "type": "string",
+ "description": "The finish reason, such as stop or
tool_calls"
+ },
+ "error": {
+ "type": "string",
+ "description": "The exception type when the call failed"
+ },
+ "content": {
+ "type": "object",
+ "additionalProperties": true,
+ "description": "The content at level full"
+ }
+ },
+ "required": [
+ "timestamp",
+ "running"
+ ]
+ },
+ "description": "The calls made inside this one, in the order they
started"
+ },
+ "droppedSteps": {
+ "type": "integer",
+ "description": "The steps not kept, beyond the cap per call"
+ },
+ "question": {
+ "type": "string",
+ "description": "The first user message, with content at level full"
+ },
+ "answer": {
+ "type": "string",
+ "description": "The last assistant message, with content at level
full"
+ },
+ "content": {
+ "type": "object",
+ "additionalProperties": true,
+ "description": "The content at level full: systemInstructions,
toolDefinitions, inputMessages, outputMessages, toolArguments, toolResult"
+ }
+ },
+ "required": [
+ "timestamp",
+ "running"
+ ],
+ "description": "The call asked for with the id option"
+ },
+ "error": {
+ "type": "string",
+ "description": "Why the call asked for is not there"
+ }
+ },
+ "required": [
+ "recording",
+ "contentMaxLength",
+ "modelCalls",
+ "agentRuns",
+ "toolCalls",
+ "errors",
+ "inputTokens",
+ "outputTokens",
+ "cachedInputTokens"
+ ]
+ }
+}
+
diff --git
a/components/camel-ai/camel-ai-observability/src/generated/resources/META-INF/services/org/apache/camel/dev-console/genai
b/components/camel-ai/camel-ai-observability/src/generated/resources/META-INF/services/org/apache/camel/dev-console/genai
new file mode 100644
index 000000000000..9bc68906c512
--- /dev/null
+++
b/components/camel-ai/camel-ai-observability/src/generated/resources/META-INF/services/org/apache/camel/dev-console/genai
@@ -0,0 +1,2 @@
+# Generated by camel build tools - do NOT edit this file!
+class=org.apache.camel.component.ai.observability.GenAiDevConsole
diff --git
a/components/camel-ai/camel-ai-observability/src/generated/resources/META-INF/services/org/apache/camel/dev-consoles.properties
b/components/camel-ai/camel-ai-observability/src/generated/resources/META-INF/services/org/apache/camel/dev-consoles.properties
new file mode 100644
index 000000000000..42866a6d68d1
--- /dev/null
+++
b/components/camel-ai/camel-ai-observability/src/generated/resources/META-INF/services/org/apache/camel/dev-consoles.properties
@@ -0,0 +1,7 @@
+# Generated by camel build tools - do NOT edit this file!
+dev-consoles=genai
+groupId=org.apache.camel
+artifactId=camel-ai-observability
+version=4.24.0-SNAPSHOT
+projectName=Camel :: AI :: Observability
+projectDescription=GenAI observability support for Camel AI components
(OpenTelemetry and Micrometer)
diff --git
a/components/camel-ai/camel-ai-observability/src/main/docs/ai-observability.adoc
b/components/camel-ai/camel-ai-observability/src/main/docs/ai-observability.adoc
index 1d926f5b1718..75f4ba24f555 100644
---
a/components/camel-ai/camel-ai-observability/src/main/docs/ai-observability.adoc
+++
b/components/camel-ai/camel-ai-observability/src/main/docs/ai-observability.adoc
@@ -197,6 +197,77 @@ messages.
* Session and user ids set as OpenTelemetry baggage (for example through
`CamelBaggage_` exchange properties) are sent
to every downstream service that propagates baggage, including the LLM
provider when its HTTP client is instrumented.
+== GenAI dev console
+
+The `genai` dev console shows the GenAI calls of the running application,
without a tracer or a metrics backend:
+
+* the totals since start: the model calls per provider and model (calls,
failed calls, input, output and cached input
+tokens, time), the agent runs and the tool calls
+* the newest top-level calls (agent runs, and model calls outside a run),
newest first, each agent run with its model
+calls and tool calls in the order they started
+* the observability level in use
+
+The calls are recorded while the dev console is enabled
(`camel.main.devConsoleEnabled=true`), which the dev profile
+does (for example with `camel run`). Without it nothing is recorded, as in
production by default. The console keeps the
+newest 50 top-level calls, and 200 steps per call. Agent runs and tool calls
are only there from level `detailed`, as
+the producers observe them from that level.
+
+[width="100%",cols="15%,15%,70%",options="header"]
+|===
+| Option | Default | Description
+| `limit` | 20 | The number of the newest top-level calls to list.
+| `content` | `false` | Whether to add the message content to the listed
calls, with the first user message
+(`question`) and the last assistant message (`answer`) of each run.
+| `id` | | The id of one call (an agent run, a model call or a tool call) to
answer with, with its content.
+|===
+
+The content (`systemInstructions`, `toolDefinitions`, `inputMessages`,
`outputMessages`, `toolArguments` and
+`toolResult`) is only recorded at level `full`, capped at
`camel.aiObservability.contentMaxLength` as on the spans, and
+only in the answer when asked with `content` or `id`. The messages are in the
GenAI messages format of the spans.
+
+Over HTTP the console is on the management server (`camel run --console`), as
text or as JSON:
+
+[source,bash]
+----
+curl http://localhost:8080/q/dev/genai
+curl -H 'Accept: application/json' 'http://localhost:8080/q/dev/genai?id=7'
+----
+
+An agent run in the JSON answer, shortened:
+
+[source,json]
+----
+{
+ "id": "7",
+ "operation": "invoke_agent",
+ "name": "invoke_agent support",
+ "agentName": "support",
+ "provider": "ollama",
+ "model": "granite4:3b",
+ "routeId": "support",
+ "running": false,
+ "durationMs": 2310,
+ "modelCalls": 2,
+ "toolCalls": 1,
+ "inputTokens": 700,
+ "outputTokens": 60,
+ "cachedInputTokens": 270,
+ "modelMs": 2240,
+ "toolMs": 5,
+ "steps": [
+ { "id": "8", "parentId": "7", "operation": "chat", "name": "chat
granite4:3b", "durationMs": 1180,
+ "inputTokens": 300, "outputTokens": 40, "cachedInputTokens": 270,
"finishReason": "tool_calls" },
+ { "id": "9", "parentId": "7", "operation": "execute_tool", "name":
"execute_tool lookupStock", "toolName": "lookupStock",
+ "durationMs": 5 },
+ { "id": "10", "parentId": "7", "operation": "chat", "name": "chat
granite4:3b", "durationMs": 1060,
+ "inputTokens": 400, "outputTokens": 20, "finishReason": "stop" }
+ ]
+}
+----
+
+The steps are a flat list: `parentId` is the call a step was made in, such as
the tool call for a model call made by
+the route of a tool.
+
== Camel TUI integration
When monitoring a running integration with `camel tui` and observability
enabled, the AI panel usage view
diff --git
a/components/camel-ai/camel-ai-observability/src/main/java/org/apache/camel/component/ai/observability/GenAiConsoleText.java
b/components/camel-ai/camel-ai-observability/src/main/java/org/apache/camel/component/ai/observability/GenAiConsoleText.java
new file mode 100644
index 000000000000..1c747be296b1
--- /dev/null
+++
b/components/camel-ai/camel-ai-observability/src/main/java/org/apache/camel/component/ai/observability/GenAiConsoleText.java
@@ -0,0 +1,119 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.ai.observability;
+
+import java.util.List;
+import java.util.Map;
+
+import org.apache.camel.util.json.JsonObject;
+
+/**
+ * The text answer of the {@code genai} dev console, made from its JSON answer.
+ */
+final class GenAiConsoleText {
+
+ private GenAiConsoleText() {
+ }
+
+ static String format(Map<String, Object> json) {
+ JsonObject root = new JsonObject(json);
+ StringBuilder sb = new StringBuilder();
+ sb.append(String.format("GenAI (level: %s%s)%n",
root.getString("level"),
+ Boolean.TRUE.equals(root.getBoolean("recording")) ? "" : ",
not recording: the dev console is off"));
+ sb.append(String.format(" Model calls: %d, agent runs: %d, tool
calls: %d, errors: %d%n",
+ number(root, "modelCalls"), number(root, "agentRuns"),
number(root, "toolCalls"),
+ number(root, "errors")));
+ sb.append(String.format(" Tokens: in %d (cached %d), out %d%n",
number(root, "inputTokens"),
+ number(root, "cachedInputTokens"), number(root,
"outputTokens")));
+ List<JsonObject> models = root.getCollection("models");
+ if (models != null && !models.isEmpty()) {
+ sb.append(String.format("%nModels:%n"));
+ for (JsonObject model : models) {
+ sb.append(String.format(" %s/%s: %d calls (%d failed), in
%d (cached %d), out %d, %d ms%n",
+ orDash(model.getString("provider")),
orDash(model.getString("model")),
+ number(model, "calls"), number(model, "errors"),
number(model, "inputTokens"),
+ number(model, "cachedInputTokens"), number(model,
"outputTokens"), number(model, "durationMs")));
+ }
+ }
+ JsonObject one = root.getMap("call");
+ if (one != null) {
+ sb.append(String.format("%n"));
+ call(sb, one);
+ }
+ List<JsonObject> calls = root.getCollection("calls");
+ if (calls != null && !calls.isEmpty()) {
+ sb.append(String.format("%nCalls (newest first):%n"));
+ for (JsonObject call : calls) {
+ call(sb, call);
+ }
+ }
+ if (number(root, "moreCalls") > 0) {
+ sb.append(String.format(" ... %d more%n", number(root,
"moreCalls")));
+ }
+ if (root.getString("error") != null) {
+ sb.append(String.format("%n%s%n", root.getString("error")));
+ }
+ return sb.toString();
+ }
+
+ private static void call(StringBuilder sb, JsonObject call) {
+ sb.append(String.format(" #%s %s%s%s%n", call.getString("id"),
call.getString("name"), duration(call),
+ usage(call)));
+ if (call.getString("question") != null) {
+ sb.append(String.format(" question: %s%n",
call.getString("question")));
+ }
+ List<JsonObject> steps = call.getCollection("steps");
+ if (steps != null) {
+ for (JsonObject step : steps) {
+ sb.append(String.format(" #%s %s%s%s%n",
step.getString("id"), step.getString("name"),
+ duration(step), usage(step)));
+ }
+ }
+ if (call.getString("answer") != null) {
+ sb.append(String.format(" answer: %s%n",
call.getString("answer")));
+ }
+ }
+
+ private static String duration(JsonObject call) {
+ if (Boolean.TRUE.equals(call.getBoolean("running"))) {
+ return " (running)";
+ }
+ return " " + number(call, "durationMs") + " ms";
+ }
+
+ private static String usage(JsonObject call) {
+ StringBuilder sb = new StringBuilder();
+ if (call.get("inputTokens") != null || call.get("outputTokens") !=
null) {
+ sb.append(String.format(", in %d out %d", number(call,
"inputTokens"), number(call, "outputTokens")));
+ }
+ if (call.getString("finishReason") != null) {
+ sb.append(", ").append(call.getString("finishReason"));
+ }
+ if (call.getString("error") != null) {
+ sb.append(", failed: ").append(call.getString("error"));
+ }
+ return sb.toString();
+ }
+
+ private static long number(JsonObject json, String key) {
+ return json.get(key) instanceof Number n ? n.longValue() : 0;
+ }
+
+ private static String orDash(String value) {
+ return value != null ? value : "-";
+ }
+}
diff --git
a/components/camel-ai/camel-ai-observability/src/main/java/org/apache/camel/component/ai/observability/GenAiDevConsole.java
b/components/camel-ai/camel-ai-observability/src/main/java/org/apache/camel/component/ai/observability/GenAiDevConsole.java
new file mode 100644
index 000000000000..b1ac0ef91ac0
--- /dev/null
+++
b/components/camel-ai/camel-ai-observability/src/main/java/org/apache/camel/component/ai/observability/GenAiDevConsole.java
@@ -0,0 +1,163 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.ai.observability;
+
+import java.util.List;
+import java.util.Map;
+
+import org.apache.camel.spi.Metadata;
+import org.apache.camel.spi.annotations.DevConsole;
+import org.apache.camel.support.console.AbstractDevConsole;
+import org.apache.camel.util.json.JsonObject;
+
+/**
+ * The GenAI calls of the Camel AI components: the model calls per model, and
the newest agent runs with their model
+ * calls and tool calls in order. Recorded without a tracer while the dev
console is enabled.
+ */
+@DevConsole(name = "genai", displayName = "GenAI",
+ description = "The model calls, agent runs and tool calls of the
Camel AI components")
+public class GenAiDevConsole extends AbstractDevConsole {
+
+ @Metadata(label = "query", description = "The number of the newest
top-level calls to list", defaultValue = "20",
+ javaType = "java.lang.Integer")
+ public static final String LIMIT = "limit";
+
+ @Metadata(label = "query",
+ description = "The id of one call (an agent run, a model call or
a tool call) to answer with its content",
+ javaType = "java.lang.String")
+ public static final String ID = "id";
+
+ @Metadata(label = "query",
+ description = "Whether to add the message content to the listed
calls (only recorded at level full)",
+ defaultValue = "false", javaType = "java.lang.Boolean")
+ public static final String CONTENT = "content";
+
+ static final int DEFAULT_LIMIT = 20;
+
+ /** The answer: the totals and the newest top-level calls, or with {@code
id} only that call. */
+ public record Response(
+ @Metadata(description = "Whether the calls are recorded: while the
dev console is enabled") boolean recording,
+ @Metadata(description = "The observability level: basic, detailed
or full") String level,
+ @Metadata(description = "The cap on each recorded text") int
contentMaxLength,
+ @Metadata(description = "The model calls since start") long
modelCalls,
+ @Metadata(description = "The agent runs since start") long
agentRuns,
+ @Metadata(description = "The tool calls since start") long
toolCalls,
+ @Metadata(description = "The calls that failed since start") long
errors,
+ @Metadata(description = "The input tokens of the model calls since
start") long inputTokens,
+ @Metadata(description = "The output tokens of the model calls
since start") long outputTokens,
+ @Metadata(description = "The input tokens read from the cache of
the provider since start") long cachedInputTokens,
+ @Metadata(description = "The model calls since start per provider
and model") List<Model> models,
+ @Metadata(description = "The newest top-level calls (agent runs,
and model calls outside a run), newest first") List<Call> calls,
+ @Metadata(description = "The top-level calls not listed: beyond
the limit, or no longer kept") Long moreCalls,
+ @Metadata(description = "The call asked for with the id option")
Call call,
+ @Metadata(description = "Why the call asked for is not there")
String error) {
+ }
+
+ /** The model calls of one provider and model. */
+ public record Model(
+ @Metadata(description = "The provider, such as openai or ollama")
String provider,
+ @Metadata(description = "The model, the response model when
known") String model,
+ @Metadata(description = "The model calls") long calls,
+ @Metadata(description = "The model calls that failed") long errors,
+ @Metadata(description = "The input tokens") long inputTokens,
+ @Metadata(description = "The output tokens") long outputTokens,
+ @Metadata(description = "The input tokens read from the cache of
the provider") long cachedInputTokens,
+ @Metadata(description = "The time of the model calls in millis")
long durationMs) {
+ }
+
+ /** A top-level call with its steps. */
+ public record Call(
+ @Metadata(description = "The id of the call") String id,
+ @Metadata(description = "The GenAI operation: invoke_agent, chat,
embeddings, ...") String operation,
+ @Metadata(description = "The name of the call, such as chat
gpt-4o") String name,
+ @Metadata(description = "The agent of an agent run") String
agentName,
+ @Metadata(description = "The provider") String provider,
+ @Metadata(description = "The model") String model,
+ @Metadata(description = "The Camel component") String component,
+ @Metadata(description = "The conversation (chat memory) id")
String conversationId,
+ @Metadata(description = "The route of the call") String routeId,
+ @Metadata(description = "The exchange of the call") String
exchangeId,
+ @Metadata(description = "When the call started, in epoch millis")
long timestamp,
+ @Metadata(description = "Whether the call is still running")
boolean running,
+ @Metadata(description = "The time of the call in millis, when it
ended") Long durationMs,
+ @Metadata(description = "The input tokens (of its model calls, for
an agent run)") Long inputTokens,
+ @Metadata(description = "The output tokens (of its model calls,
for an agent run)") Long outputTokens,
+ @Metadata(description = "The input tokens read from the cache (of
its model calls, for an agent run)") Long cachedInputTokens,
+ @Metadata(description = "The finish reason, such as stop or
tool_calls") String finishReason,
+ @Metadata(description = "The exception type when the call failed")
String error,
+ @Metadata(description = "The model calls of an agent run") Integer
modelCalls,
+ @Metadata(description = "The tool calls of an agent run") Integer
toolCalls,
+ @Metadata(description = "The time of the model calls of an agent
run in millis") Long modelMs,
+ @Metadata(description = "The time of the tool calls of an agent
run in millis") Long toolMs,
+ @Metadata(description = "The calls made inside this one, in the
order they started") List<Step> steps,
+ @Metadata(description = "The steps not kept, beyond the cap per
call") Integer droppedSteps,
+ @Metadata(description = "The first user message, with content at
level full") String question,
+ @Metadata(description = "The last assistant message, with content
at level full") String answer,
+ @Metadata(description = "The content at level full:
systemInstructions, toolDefinitions, inputMessages, outputMessages,
toolArguments, toolResult") Map<String, Object> content) {
+ }
+
+ /** A model call or tool call made inside a top-level call. */
+ public record Step(
+ @Metadata(description = "The id of the call") String id,
+ @Metadata(description = "The id of the call it was made in")
String parentId,
+ @Metadata(description = "The GenAI operation: chat, execute_tool,
...") String operation,
+ @Metadata(description = "The name of the call") String name,
+ @Metadata(description = "The tool of a tool call") String toolName,
+ @Metadata(description = "The id the model gave to the tool call")
String toolCallId,
+ @Metadata(description = "The provider") String provider,
+ @Metadata(description = "The model of a model call") String model,
+ @Metadata(description = "When the call started, in epoch millis")
long timestamp,
+ @Metadata(description = "Whether the call is still running")
boolean running,
+ @Metadata(description = "The time of the call in millis, when it
ended") Long durationMs,
+ @Metadata(description = "The input tokens of a model call") Long
inputTokens,
+ @Metadata(description = "The output tokens of a model call") Long
outputTokens,
+ @Metadata(description = "The input tokens read from the cache")
Long cachedInputTokens,
+ @Metadata(description = "The finish reason, such as stop or
tool_calls") String finishReason,
+ @Metadata(description = "The exception type when the call failed")
String error,
+ @Metadata(description = "The content at level full") Map<String,
Object> content) {
+ }
+
+ public GenAiDevConsole() {
+ super("camel", "genai", "GenAI", "The model calls, agent runs and tool
calls of the Camel AI components");
+ }
+
+ @Override
+ protected Map<String, Object> doCallJson(Map<String, Object> options) {
+ GenAiRecorder recorder = GenAiRecorder.get(getCamelContext());
+ String id = optionString(options, ID);
+ if (id != null) {
+ JsonObject root = recorder.toJson(0, false);
+ root.remove("calls");
+ root.remove("moreCalls");
+ JsonObject call = recorder.toJson(id);
+ if (call != null) {
+ root.put("call", call);
+ } else {
+ root.put("error", "No GenAI call with id " + id + ": it may no
longer be kept (the newest "
+ + GenAiRecorder.MAX_CALLS + " top-level
calls are)");
+ }
+ return root;
+ }
+ int limit = Math.max(0, optionInt(options, LIMIT, DEFAULT_LIMIT));
+ return recorder.toJson(limit, optionBoolean(options, CONTENT, false));
+ }
+
+ @Override
+ protected String doCallText(Map<String, Object> options) {
+ return GenAiConsoleText.format(doCallJson(options));
+ }
+}
diff --git
a/components/camel-ai/camel-ai-observability/src/main/java/org/apache/camel/component/ai/observability/GenAiObservabilityImpl.java
b/components/camel-ai/camel-ai-observability/src/main/java/org/apache/camel/component/ai/observability/GenAiObservabilityImpl.java
index 54a6a7b0602d..c788be3231ab 100644
---
a/components/camel-ai/camel-ai-observability/src/main/java/org/apache/camel/component/ai/observability/GenAiObservabilityImpl.java
+++
b/components/camel-ai/camel-ai-observability/src/main/java/org/apache/camel/component/ai/observability/GenAiObservabilityImpl.java
@@ -16,6 +16,7 @@
*/
package org.apache.camel.component.ai.observability;
+import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
@@ -61,10 +62,12 @@ public final class GenAiObservabilityImpl implements
GenAiObservationFactory {
GenAiMicrometerObservationBackend observationBackend =
resolved.observation();
Tracer tracer = camelContext.hasService(Tracer.class);
GenAiMetricsBackend metricsBackend = resolved.metrics();
- if (!observationBackend.isAvailable() && tracer == null &&
!metricsBackend.isAvailable()) {
+ // the genai dev console records the calls without a tracer
+ GenAiRecorder recorder = GenAiRecorder.isRecording(camelContext) ?
GenAiRecorder.get(camelContext) : null;
+ if (!observationBackend.isAvailable() && tracer == null &&
!metricsBackend.isAvailable() && recorder == null) {
return NOOP;
}
- return new DefaultGenAiObservation(exchange, context, tracer,
metricsBackend, observationBackend);
+ return new DefaultGenAiObservation(exchange, context, tracer,
metricsBackend, observationBackend, recorder);
}
/**
@@ -138,6 +141,8 @@ public final class GenAiObservabilityImpl implements
GenAiObservationFactory {
private static final Set<String> LOW_CARDINALITY_KEYS = Set.of(
GenAiAttributes.OPERATION_NAME, GenAiAttributes.SYSTEM,
GenAiAttributes.REQUEST_MODEL,
GenAiAttributes.CAMEL_COMPONENT);
+ // the content attributes (recorded at level full) and their names in
the genai dev console
+ private static final Map<String, String> CONTENT_KEYS = contentKeys();
private final Exchange exchange;
private final Tracer tracer;
@@ -149,18 +154,22 @@ public final class GenAiObservabilityImpl implements
GenAiObservationFactory {
// attributes decided while the call runs, applied when it ends
private final Map<String, Object> endAttributes = new
LinkedHashMap<>();
private final GenAiObservationContext context;
+ private final GenAiRecorder recorder;
+ private final GenAiRecorder.Call call;
private Span span;
private boolean pushed;
private GenAiUsage usage;
private Throwable error;
+ private Long cachedInputTokens;
private boolean closed;
private DefaultGenAiObservation(
Exchange exchange,
GenAiObservationContext context, Tracer tracer,
GenAiMetricsBackend metricsBackend,
- GenAiMicrometerObservationBackend
observationBackend) {
+ GenAiMicrometerObservationBackend
observationBackend, GenAiRecorder recorder) {
this.exchange = exchange;
this.context = context;
+ this.recorder = recorder;
this.tracer = tracer;
this.metricsBackend = metricsBackend;
this.level = GenAiObservability.level(exchange.getContext());
@@ -178,6 +187,28 @@ public final class GenAiObservabilityImpl implements
GenAiObservationFactory {
if (this.micrometerObservation == null) {
startSpan(parentObservation);
}
+ this.call = recorder != null ? startCall(parentObservation) : null;
+ }
+
+ private GenAiRecorder.Call startCall(DefaultGenAiObservation
parentObservation) {
+ GenAiRecorder.Call parentCall = parentObservation != null &&
parentObservation.call != null
+ ? parentObservation.call : GenAiRecorder.active(exchange);
+ GenAiRecorder.Call started = recorder.start(context, exchange,
parentCall);
+ if (isAgentOrTool()) {
+ GenAiRecorder.push(exchange, started);
+ }
+ return started;
+ }
+
+ private static Map<String, String> contentKeys() {
+ Map<String, String> keys = new LinkedHashMap<>();
+ keys.put(GenAiAttributes.SYSTEM_INSTRUCTIONS,
"systemInstructions");
+ keys.put(GenAiAttributes.TOOL_DEFINITIONS, "toolDefinitions");
+ keys.put(GenAiAttributes.INPUT_MESSAGES, "inputMessages");
+ keys.put(GenAiAttributes.OUTPUT_MESSAGES, "outputMessages");
+ keys.put(GenAiAttributes.TOOL_CALL_ARGUMENTS, "toolArguments");
+ keys.put(GenAiAttributes.TOOL_CALL_RESULT, "toolResult");
+ return Collections.unmodifiableMap(keys);
}
private boolean isAgentOrTool() {
@@ -240,6 +271,7 @@ public final class GenAiObservabilityImpl implements
GenAiObservationFactory {
@Override
public void recordCachedInputTokens(Long cachedInputTokens) {
+ this.cachedInputTokens = cachedInputTokens;
if (cachedInputTokens != null &&
level.includes(GenAiObservabilityLevel.DETAILED)) {
endAttributes.put(GenAiAttributes.CACHE_READ_INPUT_TOKENS,
cachedInputTokens);
}
@@ -321,6 +353,21 @@ public final class GenAiObservabilityImpl implements
GenAiObservationFactory {
closeSpan(endAttributes());
}
recordMetrics();
+ endCall();
+ }
+
+ private void endCall() {
+ if (call == null) {
+ return;
+ }
+ GenAiRecorder.pop(exchange, call);
+ Map<String, String> content = new LinkedHashMap<>();
+ CONTENT_KEYS.forEach((attribute, key) -> {
+ if (endAttributes.get(attribute) instanceof String value) {
+ content.put(key, value);
+ }
+ });
+ recorder.end(call, usage, cachedInputTokens, error, content,
(System.nanoTime() - startNanos) / 1_000_000);
}
private Map<String, Object> endAttributes() {
diff --git
a/components/camel-ai/camel-ai-observability/src/main/java/org/apache/camel/component/ai/observability/GenAiRecorder.java
b/components/camel-ai/camel-ai-observability/src/main/java/org/apache/camel/component/ai/observability/GenAiRecorder.java
new file mode 100644
index 000000000000..54ca161435b4
--- /dev/null
+++
b/components/camel-ai/camel-ai-observability/src/main/java/org/apache/camel/component/ai/observability/GenAiRecorder.java
@@ -0,0 +1,524 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.ai.observability;
+
+import java.util.ArrayDeque;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Deque;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Exchange;
+import org.apache.camel.ExtendedCamelContext;
+import org.apache.camel.support.ExchangeHelper;
+import org.apache.camel.util.ObjectHelper;
+import org.apache.camel.util.json.JsonArray;
+import org.apache.camel.util.json.JsonObject;
+import org.apache.camel.util.json.Jsoner;
+
+/**
+ * Keeps the GenAI calls of a CamelContext in memory for the {@code genai} dev
console: the totals since start (per
+ * model, and the agent runs and tool calls), and the newest top-level calls
(agent runs, and model calls outside a run)
+ * with their steps in the order they started.
+ * <p>
+ * It records only when the dev console is enabled ({@code
camel.main.devConsoleEnabled}, on in the dev profile), so it
+ * needs no tracer. Message content is only there at level {@link
GenAiObservabilityLevel#FULL}, capped as on the spans.
+ */
+final class GenAiRecorder {
+
+ /** The newest top-level calls kept. */
+ static final int MAX_CALLS = 50;
+ /** The steps kept per top-level call; the steps after are only counted. */
+ static final int MAX_STEPS = 200;
+ /** The length of the question and the answer of a run in the list of
calls. */
+ static final int MAX_PREVIEW = 200;
+
+ // the call open on the exchange (an agent run or a tool call), as the
span stack of camel-telemetry: the copies of
+ // the exchange made for tool calls carry it, so the calls started on them
nest under the run
+ private static final String ACTIVE_CALL = "genai.activeCall";
+ private static final Object LOCK = new Object();
+
+ private final CamelContext camelContext;
+ // all guarded by this
+ private final Deque<Call> calls = new ArrayDeque<>();
+ private final Map<String, ModelTotals> models = new LinkedHashMap<>();
+ private long ids;
+ private long agentRuns;
+ private long toolCalls;
+ private long modelCalls;
+ private long errors;
+ private long droppedCalls;
+
+ private GenAiRecorder(CamelContext camelContext) {
+ this.camelContext = camelContext;
+ }
+
+ /** Whether the calls are recorded: when the dev console is enabled. */
+ static boolean isRecording(CamelContext camelContext) {
+ return Boolean.TRUE.equals(camelContext.isDevConsole());
+ }
+
+ /** The recorder of the context, kept as a context plugin so it goes away
with the context. */
+ static GenAiRecorder get(CamelContext camelContext) {
+ ExtendedCamelContext extension =
camelContext.getCamelContextExtension();
+ GenAiRecorder recorder =
extension.getContextPlugin(GenAiRecorder.class);
+ if (recorder == null) {
+ synchronized (LOCK) {
+ recorder = extension.getContextPlugin(GenAiRecorder.class);
+ if (recorder == null) {
+ recorder = new GenAiRecorder(camelContext);
+ extension.addContextPlugin(GenAiRecorder.class, recorder);
+ }
+ }
+ }
+ return recorder;
+ }
+
+ /** The agent run or tool call open on the exchange, or {@code null}. */
+ static Call active(Exchange exchange) {
+ Frame frame = exchange.getProperty(ACTIVE_CALL, Frame.class);
+ return frame != null ? frame.call : null;
+ }
+
+ /** Makes an agent run or tool call the one open on the exchange, until
{@link #pop(Exchange, Call)}. */
+ static void push(Exchange exchange, Call call) {
+ exchange.setProperty(ACTIVE_CALL, new Frame(call,
exchange.getProperty(ACTIVE_CALL, Frame.class)));
+ }
+
+ /** Ends the call open on the exchange, when it is the given one. */
+ static void pop(Exchange exchange, Call call) {
+ Frame frame = exchange.getProperty(ACTIVE_CALL, Frame.class);
+ if (frame != null && frame.call == call) {
+ if (frame.parent != null) {
+ exchange.setProperty(ACTIVE_CALL, frame.parent);
+ } else {
+ exchange.removeProperty(ACTIVE_CALL);
+ }
+ }
+ }
+
+ /** Records the start of a call, as a step of the parent when there is
one, else as a new top-level call. */
+ synchronized Call start(GenAiObservationContext context, Exchange
exchange, Call parent) {
+ Call call = new Call(String.valueOf(++ids), context, exchange, parent);
+ if (parent != null) {
+ Call root = parent.root();
+ if (root.stepCount < MAX_STEPS) {
+ root.steps.add(call);
+ root.stepCount++;
+ } else {
+ root.droppedSteps++;
+ }
+ } else {
+ calls.addFirst(call);
+ if (calls.size() > MAX_CALLS) {
+ calls.removeLast();
+ droppedCalls++;
+ }
+ }
+ return call;
+ }
+
+ /** Records the end of a call, and counts it in the totals. */
+ synchronized void end(
+ Call call, GenAiUsage usage, Long cachedInputTokens, Throwable
error, Map<String, String> content,
+ long durationMs) {
+ call.durationMs = durationMs;
+ if (usage != null) {
+ call.inputTokens = usage.inputTokens();
+ call.outputTokens = usage.outputTokens();
+ call.finishReason = usage.finishReason();
+ if (error == null &&
ObjectHelper.isNotEmpty(usage.responseModel())) {
+ call.responseModel = usage.responseModel();
+ }
+ }
+ call.cachedInputTokens = cachedInputTokens;
+ call.errorType = error != null ? error.getClass().getSimpleName() :
null;
+ call.content.putAll(content);
+ if (error != null) {
+ errors++;
+ }
+ switch (call.kind()) {
+ case AGENT_RUN -> agentRuns++;
+ case TOOL_CALL -> toolCalls++;
+ default -> {
+ modelCalls++;
+ models.computeIfAbsent(call.provider() + "/" + call.model(), k
-> new ModelTotals(call)).add(call);
+ }
+ }
+ }
+
+ /**
+ * The totals and the newest top-level calls, newest first.
+ *
+ * @param limit the top-level calls to list
+ * @param content whether to add the message content (only recorded at
level full)
+ */
+ synchronized JsonObject toJson(int limit, boolean content) {
+ JsonObject root = summary();
+ JsonArray list = new JsonArray();
+ for (Call call : calls) {
+ if (list.size() >= limit) {
+ break;
+ }
+ list.add(call.toJson(content));
+ }
+ root.put("calls", list);
+ root.put("moreCalls", calls.size() - list.size() + droppedCalls);
+ return root;
+ }
+
+ /** One call (a top-level call, or a step of one) with its content, or
{@code null} when it is no longer kept. */
+ synchronized JsonObject toJson(String id) {
+ for (Call call : calls) {
+ if (call.id.equals(id)) {
+ return call.toJson(true);
+ }
+ for (Call step : call.steps) {
+ if (step.id.equals(id)) {
+ return step.toJson(true);
+ }
+ }
+ }
+ return null;
+ }
+
+ private JsonObject summary() {
+ JsonObject root = new JsonObject();
+ root.put("recording", isRecording(camelContext));
+ root.put("level",
GenAiObservability.level(camelContext).name().toLowerCase(Locale.ROOT));
+ root.put("contentMaxLength",
GenAiObservability.contentMaxLength(camelContext));
+ root.put("modelCalls", modelCalls);
+ root.put("agentRuns", agentRuns);
+ root.put("toolCalls", toolCalls);
+ root.put("errors", errors);
+ long in = 0;
+ long out = 0;
+ long cached = 0;
+ JsonArray list = new JsonArray();
+ for (ModelTotals totals : models.values()) {
+ in += totals.inputTokens;
+ out += totals.outputTokens;
+ cached += totals.cachedInputTokens;
+ list.add(totals.toJson());
+ }
+ root.put("inputTokens", in);
+ root.put("outputTokens", out);
+ root.put("cachedInputTokens", cached);
+ root.put("models", list);
+ return root;
+ }
+
+ enum Kind {
+ AGENT_RUN,
+ TOOL_CALL,
+ MODEL_CALL
+ }
+
+ private record Frame(Call call, Frame parent) {
+ }
+
+ /** One GenAI call; changed only under the lock of its recorder. */
+ static final class Call {
+
+ private final String id;
+ private final Call parent;
+ private final GenAiOperationName operation;
+ private final String name;
+ private final String agentName;
+ private final String toolName;
+ private final String toolCallId;
+ private final String conversationId;
+ private final String system;
+ private final String requestModel;
+ private final String component;
+ private final String routeId;
+ private final String exchangeId;
+ private final long timestamp = System.currentTimeMillis();
+ // the steps of a top-level call, in the order they started (all the
levels below it)
+ private final List<Call> steps = new ArrayList<>();
+ private final Map<String, String> content = new LinkedHashMap<>();
+ private int stepCount;
+ private int droppedSteps;
+ private Long durationMs;
+ private String responseModel;
+ private Long inputTokens;
+ private Long outputTokens;
+ private Long cachedInputTokens;
+ private String finishReason;
+ private String errorType;
+
+ private Call(String id, GenAiObservationContext context, Exchange
exchange, Call parent) {
+ this.id = id;
+ this.parent = parent;
+ this.operation = context.operationName();
+ this.name = context.spanName();
+ this.agentName = context.agentName();
+ this.toolName = context.toolName();
+ this.toolCallId = context.toolCallId();
+ this.conversationId = context.conversationId();
+ this.system = context.system();
+ this.requestModel = context.requestModel();
+ this.component = context.componentScheme();
+ this.routeId = ExchangeHelper.getAtRouteId(exchange);
+ this.exchangeId = exchange.getExchangeId();
+ }
+
+ Kind kind() {
+ if (operation == GenAiOperationName.INVOKE_AGENT) {
+ return Kind.AGENT_RUN;
+ }
+ return operation == GenAiOperationName.EXECUTE_TOOL ?
Kind.TOOL_CALL : Kind.MODEL_CALL;
+ }
+
+ private Call root() {
+ Call call = this;
+ while (call.parent != null) {
+ call = call.parent;
+ }
+ return call;
+ }
+
+ private String provider() {
+ return ObjectHelper.isEmpty(system) || "unknown".equals(system) ?
null : system;
+ }
+
+ private String model() {
+ String model = responseModel != null ? responseModel :
requestModel;
+ return ObjectHelper.isEmpty(model) || "unknown".equals(model) ?
null : model;
+ }
+
+ private JsonObject toJson(boolean withContent) {
+ JsonObject json = fields();
+ if (parent == null) {
+ JsonArray list = new JsonArray();
+ long in = 0;
+ long out = 0;
+ long cached = 0;
+ long modelMs = 0;
+ long toolMs = 0;
+ int models = 0;
+ int tools = 0;
+ for (Call step : steps) {
+ JsonObject stepJson = step.fields();
+ if (withContent) {
+ putContent(stepJson, step.content);
+ }
+ list.add(stepJson);
+ if (step.kind() == Kind.MODEL_CALL) {
+ models++;
+ in += zero(step.inputTokens);
+ out += zero(step.outputTokens);
+ cached += zero(step.cachedInputTokens);
+ modelMs += zero(step.durationMs);
+ } else if (step.kind() == Kind.TOOL_CALL) {
+ tools++;
+ toolMs += zero(step.durationMs);
+ }
+ }
+ if (kind() == Kind.AGENT_RUN) {
+ // the model calls carry the token usage of the run
+ json.put("modelCalls", models);
+ json.put("toolCalls", tools);
+ json.put("inputTokens", in);
+ json.put("outputTokens", out);
+ json.put("cachedInputTokens", cached);
+ json.put("modelMs", modelMs);
+ json.put("toolMs", toolMs);
+ }
+ if (!list.isEmpty() || kind() != Kind.MODEL_CALL) {
+ json.put("steps", list);
+ }
+ if (droppedSteps > 0) {
+ json.put("droppedSteps", droppedSteps);
+ }
+ if (withContent) {
+ putContent(json, content);
+ putIfNotNull(json, "question",
preview(firstText(GenAiMessages.USER, true)));
+ putIfNotNull(json, "answer",
preview(firstText(GenAiMessages.ASSISTANT, false)));
+ }
+ } else if (withContent) {
+ putContent(json, content);
+ }
+ return json;
+ }
+
+ private JsonObject fields() {
+ JsonObject json = new JsonObject();
+ json.put("id", id);
+ putIfNotNull(json, "parentId", parent != null ? parent.id : null);
+ json.put("operation", operation.value());
+ json.put("name", name);
+ putIfNotNull(json, "agentName", agentName);
+ putIfNotNull(json, "toolName", toolName);
+ putIfNotNull(json, "toolCallId", toolCallId);
+ putIfNotNull(json, "provider", provider());
+ if (kind() != Kind.TOOL_CALL) {
+ putIfNotNull(json, "model", model());
+ }
+ putIfNotNull(json, "component", component);
+ putIfNotNull(json, "conversationId", conversationId);
+ putIfNotNull(json, "routeId", routeId);
+ putIfNotNull(json, "exchangeId", exchangeId);
+ json.put("timestamp", timestamp);
+ json.put("running", durationMs == null);
+ putIfNotNull(json, "durationMs", durationMs);
+ if (kind() == Kind.MODEL_CALL) {
+ putIfNotNull(json, "inputTokens", inputTokens);
+ putIfNotNull(json, "outputTokens", outputTokens);
+ putIfNotNull(json, "cachedInputTokens", cachedInputTokens);
+ }
+ putIfNotNull(json, "finishReason", finishReason);
+ putIfNotNull(json, "error", errorType);
+ return json;
+ }
+
+ /**
+ * The first text of a role in the messages of the run, else of its
model calls: the question is the first user
+ * message (searched from the start), the answer the last assistant
message (searched from the end).
+ */
+ private String firstText(String role, boolean fromStart) {
+ List<String> sources = new ArrayList<>();
+ String own = content.get(fromStart ? "inputMessages" :
"outputMessages");
+ if (own != null) {
+ sources.add(own);
+ }
+ for (Call step : steps) {
+ if (step.kind() == Kind.MODEL_CALL) {
+ String messages = step.content.get(fromStart ?
"inputMessages" : "outputMessages");
+ if (messages != null) {
+ sources.add(messages);
+ }
+ }
+ }
+ if (!fromStart) {
+ Collections.reverse(sources);
+ }
+ for (String messages : sources) {
+ String text = text(messages, role, fromStart);
+ if (text != null) {
+ return text;
+ }
+ }
+ return null;
+ }
+ }
+
+ private static final class ModelTotals {
+ private final String provider;
+ private final String model;
+ private long calls;
+ private long errors;
+ private long inputTokens;
+ private long outputTokens;
+ private long cachedInputTokens;
+ private long durationMs;
+
+ private ModelTotals(Call call) {
+ this.provider = call.provider();
+ this.model = call.model();
+ }
+
+ private void add(Call call) {
+ calls++;
+ if (call.errorType != null) {
+ errors++;
+ }
+ inputTokens += zero(call.inputTokens);
+ outputTokens += zero(call.outputTokens);
+ cachedInputTokens += zero(call.cachedInputTokens);
+ durationMs += zero(call.durationMs);
+ }
+
+ private JsonObject toJson() {
+ JsonObject json = new JsonObject();
+ putIfNotNull(json, "provider", provider);
+ putIfNotNull(json, "model", model);
+ json.put("calls", calls);
+ json.put("errors", errors);
+ json.put("inputTokens", inputTokens);
+ json.put("outputTokens", outputTokens);
+ json.put("cachedInputTokens", cachedInputTokens);
+ json.put("durationMs", durationMs);
+ return json;
+ }
+ }
+
+ /** The content of a call, the messages as JSON (they are recorded in the
GenAI messages format). */
+ private static void putContent(JsonObject json, Map<String, String>
content) {
+ if (content.isEmpty()) {
+ return;
+ }
+ JsonObject map = new JsonObject();
+ content.forEach((key, value) -> map.put(key, key.endsWith("Messages")
|| "toolDefinitions".equals(key)
+ ? parse(value) : value));
+ json.put("content", map);
+ }
+
+ private static Object parse(String value) {
+ try {
+ return Jsoner.deserialize(value);
+ } catch (Exception e) {
+ // cut by the length cap: given as the text it is
+ return value;
+ }
+ }
+
+ /** The first (or last) text part of a role in GenAI messages JSON, or
{@code null}. */
+ static String text(String messages, String role, boolean fromStart) {
+ if (!(parse(messages) instanceof JsonArray array)) {
+ return null;
+ }
+ String found = null;
+ for (Object item : array) {
+ if (item instanceof JsonObject message &&
role.equals(message.getString("role"))
+ && message.get("parts") instanceof JsonArray parts) {
+ for (Object part : parts) {
+ if (part instanceof JsonObject p &&
"text".equals(p.getString("type"))
+ &&
ObjectHelper.isNotEmpty(p.getString("content"))) {
+ if (fromStart) {
+ return p.getString("content");
+ }
+ found = p.getString("content");
+ }
+ }
+ }
+ }
+ return found;
+ }
+
+ private static String preview(String text) {
+ if (text == null) {
+ return null;
+ }
+ String line = text.strip().replaceAll("\\s+", " ");
+ return line.length() > MAX_PREVIEW ? line.substring(0, MAX_PREVIEW) +
"..." : line;
+ }
+
+ private static long zero(Long value) {
+ return value != null ? value : 0;
+ }
+
+ private static void putIfNotNull(JsonObject json, String key, Object
value) {
+ if (value != null) {
+ json.put(key, value);
+ }
+ }
+}
diff --git
a/components/camel-ai/camel-ai-observability/src/test/java/org/apache/camel/component/ai/observability/GenAiDevConsoleTest.java
b/components/camel-ai/camel-ai-observability/src/test/java/org/apache/camel/component/ai/observability/GenAiDevConsoleTest.java
new file mode 100644
index 000000000000..4c9be6880765
--- /dev/null
+++
b/components/camel-ai/camel-ai-observability/src/test/java/org/apache/camel/component/ai/observability/GenAiDevConsoleTest.java
@@ -0,0 +1,244 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.ai.observability;
+
+import java.util.List;
+import java.util.Map;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Exchange;
+import org.apache.camel.console.DevConsole;
+import org.apache.camel.support.DefaultExchange;
+import org.apache.camel.support.PluginHelper;
+import org.apache.camel.test.junit6.ExchangeTestSupport;
+import org.apache.camel.util.json.JsonObject;
+import org.junit.jupiter.api.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+class GenAiDevConsoleTest extends ExchangeTestSupport {
+
+ @Override
+ protected CamelContext createCamelContext() throws Exception {
+ CamelContext context = super.createCamelContext();
+ context.setDevConsole(true);
+ return context;
+ }
+
+ private void level(String level) {
+
context.getPropertiesComponent().addOverrideProperty(GenAiObservabilityProperties.LEVEL,
level);
+ }
+
+ @Test
+ void theConsoleIsFoundByName() throws Exception {
+ DevConsole console =
PluginHelper.getDevConsoleResolver(context).resolveDevConsole("genai");
+
+ assertThat(console).isInstanceOf(GenAiDevConsole.class);
+ assertThat(console.isReadOnly()).isTrue();
+ }
+
+ @Test
+ void aModelCallIsRecordedWithoutATracer() {
+ chat(new DefaultExchange(context), null, 120, 30, 100L, "stop");
+
+ JsonObject json = call(Map.of());
+
+ assertThat(json).containsEntry("recording",
true).containsEntry("level", "basic")
+ .containsEntry("modelCalls", 1L).containsEntry("agentRuns", 0L)
+ .containsEntry("inputTokens",
120L).containsEntry("cachedInputTokens", 100L);
+ List<JsonObject> models = json.getCollection("models");
+ assertThat(models).singleElement().satisfies(model -> assertThat(model)
+ .containsEntry("provider", "ollama").containsEntry("model",
"granite4:3b").containsEntry("calls", 1L));
+ List<JsonObject> calls = json.getCollection("calls");
+ assertThat(calls).singleElement().satisfies(call -> assertThat(call)
+ .containsEntry("operation", "chat").containsEntry("running",
false)
+ .containsEntry("finishReason",
"stop").doesNotContainKey("content"));
+ }
+
+ @Test
+ void anAgentRunHasItsModelCallsAndToolCallsInOrder() {
+ level("detailed");
+ Exchange exchange = new DefaultExchange(context);
+ GenAiObservation run = agentRun(exchange);
+ chat(exchange, run, 300, 40, 270L, "tool_calls");
+ tool(exchange.copy(), run);
+ chat(exchange, run, 400, 20, null, "stop");
+ run.close();
+
+ JsonObject json = call(Map.of());
+
+ assertThat(json).containsEntry("level",
"detailed").containsEntry("modelCalls", 2L)
+ .containsEntry("agentRuns", 1L).containsEntry("toolCalls", 1L);
+ JsonObject agent = list(json, "calls").get(0);
+ assertThat(agent).containsEntry("operation",
"invoke_agent").containsEntry("agentName", "support")
+ .containsEntry("modelCalls", 2).containsEntry("toolCalls", 1)
+ .containsEntry("inputTokens",
700L).containsEntry("cachedInputTokens", 270L);
+ List<JsonObject> steps = agent.getCollection("steps");
+ assertThat(steps).extracting(step -> step.getString("name"))
+ .containsExactly("chat granite4:3b", "execute_tool
lookupStock", "chat granite4:3b");
+ assertThat(steps).allSatisfy(step ->
assertThat(step).containsEntry("parentId", agent.getString("id")));
+ }
+
+ @Test
+ void callsStartedOnTheExchangeOfARunNestUnderIt() {
+ level("detailed");
+ // as camel-openai: the model calls of the run are started without a
parent
+ Exchange exchange = new DefaultExchange(context);
+ GenAiObservation run = agentRun(exchange);
+ chat(exchange, null, 10, 5, null, "tool_calls");
+ Exchange copy = exchange.copy();
+ GenAiObservation tool = tool(copy, null);
+ chat(copy, null, 7, 3, null, "stop");
+ tool.close();
+ run.close();
+ chat(exchange, null, 1, 1, null, "stop");
+
+ List<JsonObject> calls = call(Map.of()).getCollection("calls");
+
+ assertThat(calls).hasSize(2);
+ assertThat(calls.get(0)).containsEntry("operation",
"chat").doesNotContainKey("steps");
+ List<JsonObject> steps = calls.get(1).getCollection("steps");
+ assertThat(steps).extracting(step -> step.getString("operation"))
+ .containsExactly("chat", "execute_tool", "chat");
+ assertThat(steps.get(2)).containsEntry("parentId",
steps.get(1).getString("id"));
+ }
+
+ @Test
+ void theContentIsOnlyThereAtLevelFullAndWhenAsked() {
+ level("detailed");
+ conversation();
+ assertThat(list(call(Map.of("content", "true")), "calls").get(0))
+ .doesNotContainKeys("content", "question");
+
+ level("full");
+ conversation();
+ JsonObject listed = list(call(Map.of()), "calls").get(0);
+ assertThat(listed).doesNotContainKeys("content", "question");
+
+ JsonObject withContent = list(call(Map.of("content", "true")),
"calls").get(0);
+ assertThat(withContent).containsEntry("question", "Is order ORD-1001
paid?")
+ .containsEntry("answer", "Yes, it is paid.");
+ JsonObject tool = list(withContent, "steps").get(1);
+ Map<String, Object> content = tool.getMap("content");
+ assertThat(content).containsEntry("toolArguments",
"{\"order\":\"ORD-1001\"}")
+ .containsEntry("toolResult", "paid");
+
+ Map<String, Object> one = call(Map.of("id",
listed.getString("id"))).getMap("call");
+ assertThat(one).containsEntry("question", "Is order ORD-1001 paid?");
+ assertThat(call(Map.of("id",
"999"))).doesNotContainKey("call").containsKey("error");
+ }
+
+ @Test
+ void onlyTheNewestCallsAreKeptButTheTotalsCountAll() {
+ for (int i = 0; i < GenAiRecorder.MAX_CALLS + 10; i++) {
+ chat(new DefaultExchange(context), null, 1, 1, null, "stop");
+ }
+
+ JsonObject json = call(Map.of("limit", "5"));
+
+ assertThat(json).containsEntry("modelCalls", (long)
GenAiRecorder.MAX_CALLS + 10)
+ .containsEntry("moreCalls", (long) GenAiRecorder.MAX_CALLS +
5);
+ assertThat(list(json, "calls")).hasSize(5);
+ }
+
+ @Test
+ void nothingIsRecordedWhenTheDevConsoleIsOff() {
+ context.setDevConsole(false);
+ chat(new DefaultExchange(context), null, 1, 1, null, "stop");
+
+ JsonObject json = call(Map.of());
+
+ assertThat(json).containsEntry("recording",
false).containsEntry("modelCalls", 0L);
+ }
+
+ @Test
+ void theTextAnswerSummarizesTheCalls() {
+ level("full");
+ conversation();
+
+ String text = (String) console().call(DevConsole.MediaType.TEXT,
Map.of("content", "true"));
+
+ assertThat(text).contains("GenAI (level: full)", "Model calls: 2,
agent runs: 1, tool calls: 1",
+ "ollama/granite4:3b: 2 calls", "invoke_agent support",
"question: Is order ORD-1001 paid?",
+ "execute_tool lookupOrder");
+ }
+
+ private void conversation() {
+ Exchange exchange = new DefaultExchange(context);
+ GenAiObservation run = agentRun(exchange);
+ GenAiObservation first = start(exchange, chatContext(run));
+ first.recordInputMessages(() -> new
GenAiMessages().text(GenAiMessages.SYSTEM, "You answer the customers.")
+ .text(GenAiMessages.USER, "Is order ORD-1001 paid?"));
+ first.recordSuccess(GenAiUsage.of(50L, 10L, "tool_calls", null));
+ first.close();
+ GenAiObservation tool = start(exchange,
GenAiObservationContext.builder()
+
.operationName(GenAiOperationName.EXECUTE_TOOL).toolName("lookupOrder").parent(run).build());
+ tool.recordToolArguments(() -> "{\"order\":\"ORD-1001\"}");
+ tool.recordToolResult(() -> "paid");
+ tool.close();
+ GenAiObservation second = start(exchange, chatContext(run));
+ second.recordOutputMessages(() -> new
GenAiMessages().text(GenAiMessages.ASSISTANT, "Yes, it is paid."));
+ second.recordSuccess(GenAiUsage.of(60L, 8L, "stop", null));
+ second.close();
+ run.close();
+ }
+
+ private GenAiObservation agentRun(Exchange exchange) {
+ return start(exchange, GenAiObservationContext.builder()
+
.operationName(GenAiOperationName.INVOKE_AGENT).agentName("support").system("ollama")
+ .requestModel("granite4:3b").build());
+ }
+
+ private void chat(Exchange exchange, GenAiObservation parent, long in,
long out, Long cached, String finish) {
+ GenAiObservation chat = start(exchange, chatContext(parent));
+ chat.recordCachedInputTokens(cached);
+ chat.recordSuccess(GenAiUsage.of(in, out, finish, null));
+ chat.close();
+ }
+
+ private GenAiObservation tool(Exchange exchange, GenAiObservation parent) {
+ GenAiObservation tool = start(exchange,
GenAiObservationContext.builder()
+
.operationName(GenAiOperationName.EXECUTE_TOOL).toolName("lookupStock").parent(parent).build());
+ if (parent != null) {
+ tool.close();
+ }
+ return tool;
+ }
+
+ private static GenAiObservationContext chatContext(GenAiObservation
parent) {
+ return
GenAiObservationContext.builder().operationName(GenAiOperationName.CHAT).system("ollama")
+
.requestModel("granite4:3b").componentScheme("openai").parent(parent).build();
+ }
+
+ private static GenAiObservation start(Exchange exchange,
GenAiObservationContext context) {
+ return GenAiObservability.start(exchange, context);
+ }
+
+ private GenAiDevConsole console() {
+ GenAiDevConsole console = new GenAiDevConsole();
+ console.setCamelContext(context);
+ return console;
+ }
+
+ private static List<JsonObject> list(JsonObject json, String key) {
+ return json.getCollection(key);
+ }
+
+ private JsonObject call(Map<String, Object> options) {
+ return (JsonObject) console().call(DevConsole.MediaType.JSON, options);
+ }
+}
diff --git a/dsl/camel-cli-connector/pom.xml b/dsl/camel-cli-connector/pom.xml
index 1411e9ded79d..9c9000045cf8 100644
--- a/dsl/camel-cli-connector/pom.xml
+++ b/dsl/camel-cli-connector/pom.xml
@@ -77,6 +77,12 @@
<artifactId>camel-sanitizer</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <!-- the genai action and the genai dev console, tested end to end
-->
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-ai-observability</artifactId>
+ <scope>test</scope>
+ </dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-test-junit6</artifactId>
diff --git
a/dsl/camel-cli-connector/src/main/java/org/apache/camel/cli/connector/LocalCliConnector.java
b/dsl/camel-cli-connector/src/main/java/org/apache/camel/cli/connector/LocalCliConnector.java
index 312e850f5ae6..5fe70fc3a617 100644
---
a/dsl/camel-cli-connector/src/main/java/org/apache/camel/cli/connector/LocalCliConnector.java
+++
b/dsl/camel-cli-connector/src/main/java/org/apache/camel/cli/connector/LocalCliConnector.java
@@ -458,6 +458,8 @@ public class LocalCliConnector extends ServiceSupport
doActionBrowseTask(root);
} else if ("span".equals(action)) {
doActionSpanTask(root);
+ } else if ("genai".equals(action)) {
+ doActionGenAiTask(root);
} else if ("receive".equals(action)) {
doActionReceiveTask(root);
} else if ("readme".equals(action)) {
@@ -1254,6 +1256,26 @@ public class LocalCliConnector extends ServiceSupport
}
}
+ private void doActionGenAiTask(JsonObject root) throws IOException {
+ // the genai console of camel-ai-observability: the GenAI calls,
recorded without a tracer
+ DevConsole dc =
camelContext.getCamelContextExtension().getContextPlugin(DevConsoleRegistry.class)
+ .resolveById("genai");
+ if (dc != null) {
+ Map<String, Object> params = new HashMap<>();
+ for (String key : new String[] { "limit", "id", "content" }) {
+ String value = root.getString(key);
+ if (value != null) {
+ params.put(key, value);
+ }
+ }
+ writeOutput((JsonObject) dc.call(DevConsole.MediaType.JSON,
params));
+ } else {
+ JsonObject json = new JsonObject();
+ json.put("enabled", false);
+ writeOutput(json);
+ }
+ }
+
private void doActionReceiveTask(JsonObject root) throws Exception {
DevConsole dc =
camelContext.getCamelContextExtension().getContextPlugin(DevConsoleRegistry.class)
.resolveById("receive");
diff --git
a/dsl/camel-cli-connector/src/test/java/org/apache/camel/cli/connector/LocalCliConnectorGenAiActionTest.java
b/dsl/camel-cli-connector/src/test/java/org/apache/camel/cli/connector/LocalCliConnectorGenAiActionTest.java
new file mode 100644
index 000000000000..295ac8a4009c
--- /dev/null
+++
b/dsl/camel-cli-connector/src/test/java/org/apache/camel/cli/connector/LocalCliConnectorGenAiActionTest.java
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.cli.connector;
+
+import java.util.List;
+import java.util.concurrent.atomic.AtomicReference;
+
+import org.apache.camel.component.ai.observability.GenAiObservability;
+import org.apache.camel.component.ai.observability.GenAiObservation;
+import org.apache.camel.component.ai.observability.GenAiObservationContext;
+import org.apache.camel.component.ai.observability.GenAiUsage;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.spi.CliConnectorFactory;
+import org.apache.camel.support.DefaultExchange;
+import org.apache.camel.util.json.JsonObject;
+import org.junit.jupiter.api.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * CAMEL-27313: the genai action answers with the genai console of
camel-ai-observability, which the Camel CLI reads for
+ * the GenAI calls of an integration.
+ */
+class LocalCliConnectorGenAiActionTest {
+
+ @Test
+ void theGenAiActionAnswersWithTheCallsOfTheConsole() throws Exception {
+ try (var context = new DefaultCamelContext()) {
+ context.setDevConsole(true);
+ // the action is dispatched here: a connector of the context would
poll the {pid} files of other tests
+ var disabled = new DefaultCliConnectorFactory();
+ disabled.setEnabled(false);
+
context.getCamelContextExtension().addContextPlugin(CliConnectorFactory.class,
disabled);
+ context.start();
+ GenAiObservation chat = GenAiObservability.start(new
DefaultExchange(context),
+
GenAiObservationContext.builder().system("ollama").requestModel("granite4:3b").build());
+ chat.recordSuccess(GenAiUsage.of(12L, 3L, "stop", null));
+ chat.close();
+ var connector = new LocalCliConnector(new
DefaultCliConnectorFactory());
+ connector.setCamelContext(context);
+ JsonObject request = new JsonObject();
+ request.put("action", "genai");
+ request.put("limit", "5");
+
+ var answer = new AtomicReference<JsonObject>();
+ assertThat(connector.dispatch(request, answer::set)).isTrue();
+
+ assertThat(answer.get()).containsEntry("recording",
true).containsEntry("modelCalls", 1L)
+ .containsEntry("inputTokens", 12L);
+ List<JsonObject> calls = answer.get().getCollection("calls");
+ assertThat(calls).singleElement().satisfies(call ->
assertThat(call).containsEntry("name", "chat granite4:3b"));
+ }
+ }
+}