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 bd3532de5ea9 CAMEL-27312: camel-jbang - the MCP server shows the agent 
runs, model calls and tool calls of the GenAI spans (#30525)
bd3532de5ea9 is described below

commit bd3532de5ea941120f226e7556eab4e281aa3bd3
Author: Claus Ibsen <[email protected]>
AuthorDate: Sat Nov 21 08:03:15 2026 +0100

    CAMEL-27312: camel-jbang - the MCP server shows the agent runs, model calls 
and tool calls of the GenAI spans (#30525)
    
    camel_runtime_ai_trace read no spans, so an AI coding agent saw no agent 
runs,
    no tool calls and no per-call tokens; camel_runtime_spans gives the raw 
dump.
    
    - the span model of the Camel TUI moves to camel-jbang-core
      (org.apache.camel.dsl.jbang.core.common.genai): SpanEntry, GenAiSpans 
(model
      call, agent run, tool call, provider, model, level), GenAiAgentRuns (runs
      with their steps, exchange id, question) and GenAiTranscript, so the TUI 
and
      the MCP server read the spans the same way; camel-jbang-core gets
      camel-ai-observability-api for the attribute names
    - camel_runtime_ai_trace starts with the GenAI spans: a summary line that 
fits
      in what a chat history keeps (level, agent runs, model calls, tool calls,
      what to do next), the model calls per model, and the newest five agent 
runs
      with their steps; at level full also the question and the tool arguments 
and
      results, cut at 200 characters. Without spans it says how to turn them on
    - camel_runtime_ai_conversation: the messages of one run by its runId, cut 
at
      1,000 characters a text and 6,000 in all, saying what was cut
    - the spans are read without McpToolNames, so recorded messages stay as they
      were; a dump that cannot be read is no spans (logged at debug), not an 
error
    
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
    Signed-off-by: Claus Ibsen <[email protected]>
---
 .../modules/ROOT/pages/camel-jbang-mcp.adoc        |  23 +-
 dsl/camel-jbang/camel-jbang-core/pom.xml           |   5 +
 .../jbang/core/common/genai/GenAiAgentRuns.java    | 161 +++++++++++
 .../dsl/jbang/core/common/genai/GenAiSpans.java}   | 204 ++++++--------
 .../jbang/core/common/genai}/GenAiTranscript.java  |  38 ++-
 .../dsl/jbang/core/common/genai}/SpanEntry.java    |  19 +-
 .../core/common/genai/GenAiAgentRunsTest.java      | 130 +++++++++
 .../core/common/genai}/GenAiTranscriptTest.java    |  12 +-
 .../dsl/jbang/core/commands/mcp/AiTraceTools.java  |  68 ++++-
 .../jbang/core/commands/mcp/GenAiTraceReport.java  | 298 +++++++++++++++++++++
 .../core/commands/mcp/GenAiTraceReportTest.java    | 255 ++++++++++++++++++
 .../core/commands/mcp/RuntimeToolsWiringTest.java  |   8 +
 .../camel/dsl/jbang/core/commands/tui/AiPanel.java |   1 +
 .../dsl/jbang/core/commands/tui/AiUsageStats.java  |   6 +-
 .../core/commands/tui/DataRefreshService.java      |   1 +
 .../core/commands/tui/GenAiSpanUsageExtractor.java | 224 ++--------------
 .../dsl/jbang/core/commands/tui/GenAiSpanView.java | 157 ++---------
 .../dsl/jbang/core/commands/tui/OllamaMonitor.java |   6 +-
 .../dsl/jbang/core/commands/tui/SpansTab.java      |  18 +-
 .../jbang/core/commands/tui/TranscriptOverlay.java |   1 +
 .../core/commands/tui/AiPanelGenAiUsageTest.java   |   1 +
 .../commands/tui/GenAiSpanUsageExtractorTest.java  |  34 +--
 .../jbang/core/commands/tui/GenAiSpanViewTest.java |  14 +-
 .../jbang/core/commands/tui/OllamaMonitorTest.java |   1 +
 .../core/commands/tui/OllamaTabRenderTest.java     |   1 +
 .../jbang/core/commands/tui/SourceSizeTest.java    |   2 +-
 .../core/commands/tui/SpansTabRenderTest.java      |   1 +
 27 files changed, 1147 insertions(+), 542 deletions(-)

diff --git a/docs/user-manual/modules/ROOT/pages/camel-jbang-mcp.adoc 
b/docs/user-manual/modules/ROOT/pages/camel-jbang-mcp.adoc
index 2dc4656f2571..d90dbfa00ceb 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-jbang-mcp.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-jbang-mcp.adoc
@@ -1188,11 +1188,24 @@ 
xref:camel-jbang-tui-local-models.adoc#_tool_groups_from_the_selected_integratio
   at the `read-only` access level can read the traces.
 
 | `camel_runtime_ai_trace`
-| Trace the AI-specific exchange flow of a running application: token usage, 
model ids, guardrail outcomes,
-  completion reasons, streaming chunk counts and per-component latency for the 
AI components (Bedrock,
-  LangChain4j, Docling, Textract, OpenAI, KServe, DJL, TensorFlow Serving, 
HuggingFace). It combines the message
-  history with the processor statistics, filtered to the AI steps. A process 
that does not answer is reported as
-  an error.
+a| Trace how a running application used AI. The answer starts with the GenAI 
spans that `camel run --observe` records
+  (camel-ai-observability), in the same words as the Camel TUI:
+  * a summary line with the GenAI observability level and the number of agent 
runs, model calls and tool calls
+  * the model calls per model, with their tokens (input, output, cached), 
average time and finish reasons
+  * the newest five agent runs (and how many more there are), each with its 
model calls and tool calls in order,
+    their time and tokens, the route and exchange id, and at level `full` the 
question and the tool arguments and
+    results (cut at 200 characters)
+
+  Without GenAI spans, the summary says how to turn them on. Then come the 
token usage, model ids, guardrail
+  outcomes, completion reasons, streaming chunk counts and per-component 
latency of the AI components (Bedrock,
+  LangChain4j, Docling, Textract, OpenAI, KServe, DJL, TensorFlow Serving, 
HuggingFace), from the message history
+  and the processor statistics. A process that does not answer is reported as 
an error.
+
+| `camel_runtime_ai_conversation`
+| The conversation of one agent run, by the `runId` that 
`camel_runtime_ai_trace` lists: the system instructions,
+  the user and assistant messages, and each tool call with its arguments and 
result, in order. The messages are
+  recorded at `camel.aiObservability.level=full` only, and may hold customers' 
data. Each text is cut at 1,000
+  characters and the answer at 6,000, and it says what was cut.
 
 | `camel_runtime_browse`
 | Browse messages in a Camel endpoint (e.g., messages queued in a SEDA 
endpoint).
diff --git a/dsl/camel-jbang/camel-jbang-core/pom.xml 
b/dsl/camel-jbang/camel-jbang-core/pom.xml
index dc029a2d8767..a2d03ace4813 100644
--- a/dsl/camel-jbang/camel-jbang-core/pom.xml
+++ b/dsl/camel-jbang/camel-jbang-core/pom.xml
@@ -57,6 +57,11 @@
             <groupId>org.apache.camel</groupId>
             <artifactId>camel-jbang-run</artifactId>
         </dependency>
+        <!-- the GenAI span attributes, read by the TUI and the MCP server 
(CAMEL-27312) -->
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-ai-observability-api</artifactId>
+        </dependency>
         <dependency>
             <groupId>org.apache.camel</groupId>
             <artifactId>camel-dataweave</artifactId>
diff --git 
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/common/genai/GenAiAgentRuns.java
 
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/common/genai/GenAiAgentRuns.java
new file mode 100644
index 000000000000..daea24a3dc46
--- /dev/null
+++ 
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/common/genai/GenAiAgentRuns.java
@@ -0,0 +1,161 @@
+/*
+ * 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.dsl.jbang.core.common.genai;
+
+import java.util.Comparator;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.camel.component.ai.observability.GenAiAttributes;
+import org.apache.camel.component.ai.observability.GenAiMessages;
+
+/**
+ * The agent runs among the GenAI spans: an {@code invoke_agent} span with the 
model calls and tool calls whose nearest
+ * agent run it is (observability level detailed and above).
+ */
+public final class GenAiAgentRuns {
+
+    /**
+     * A model call or a tool call of an agent run.
+     *
+     * @param arguments the tool arguments, recorded at level full only
+     * @param result    the tool result, recorded at level full only
+     */
+    public record Step(SpanEntry span, boolean tool, String name, long 
durationMs, long inputTokens, long outputTokens,
+            long cachedTokens, String finishReason, String arguments, String 
result) {
+    }
+
+    /** An agent run with its steps in the order they started. */
+    public record AgentRun(SpanEntry span, String agentName, String model, 
String provider, String conversationId,
+            long durationMs, List<Step> steps) {
+
+        public long modelCalls() {
+            return steps.stream().filter(s -> !s.tool()).count();
+        }
+
+        public long toolCalls() {
+            return steps.stream().filter(Step::tool).count();
+        }
+
+        public long inputTokens() {
+            return steps.stream().mapToLong(Step::inputTokens).sum();
+        }
+
+        public long outputTokens() {
+            return steps.stream().mapToLong(Step::outputTokens).sum();
+        }
+
+        public long cachedTokens() {
+            return steps.stream().mapToLong(Step::cachedTokens).sum();
+        }
+
+        public long modelMs() {
+            return steps.stream().filter(s -> 
!s.tool()).mapToLong(Step::durationMs).sum();
+        }
+
+        public long toolMs() {
+            return 
steps.stream().filter(Step::tool).mapToLong(Step::durationMs).sum();
+        }
+
+        /** The time of the run outside its model and tool calls. */
+        public long otherMs() {
+            return Math.max(0, durationMs - modelMs() - toolMs());
+        }
+    }
+
+    private GenAiAgentRuns() {
+    }
+
+    /** The agent runs among the spans, the newest first. */
+    public static List<AgentRun> agentRuns(List<SpanEntry> spans) {
+        if (spans == null) {
+            return List.of();
+        }
+        return spans.stream()
+                .filter(GenAiSpans::isAgentRun)
+                
.sorted(Comparator.comparingLong(SpanEntry::startEpochNanos).reversed())
+                .map(agent -> agentRun(agent, spans))
+                .toList();
+    }
+
+    /** The agent run with its model and tool calls: the GenAI spans whose 
nearest agent run is this one. */
+    public static AgentRun agentRun(SpanEntry agent, List<SpanEntry> spans) {
+        Map<String, SpanEntry> byId = GenAiSpans.byId(spans);
+        List<Step> steps = spans.stream()
+                .filter(s -> s != agent && GenAiSpans.isGenAiSpan(s) && 
!GenAiSpans.isAgentRun(s))
+                .filter(s -> {
+                    SpanEntry run = GenAiSpans.nearestAgentRun(s, byId);
+                    return run != null && agent.spanId() != null && 
agent.spanId().equals(run.spanId());
+                })
+                .sorted(Comparator.comparingLong(SpanEntry::startEpochNanos))
+                .map(GenAiAgentRuns::step)
+                .toList();
+        Map<String, Object> attrs = agent.attributes();
+        String agentName = GenAiSpans.text(attrs, GenAiAttributes.AGENT_NAME);
+        String provider = GenAiSpans.text(attrs, 
GenAiAttributes.PROVIDER_NAME);
+        return new AgentRun(
+                agent, agentName != null ? agentName : agent.routeId(), 
GenAiSpans.model(attrs),
+                provider != null ? provider : GenAiSpans.text(attrs, 
GenAiAttributes.SYSTEM),
+                GenAiSpans.text(attrs, GenAiAttributes.CONVERSATION_ID), 
agent.durationMs(), steps);
+    }
+
+    private static Step step(SpanEntry span) {
+        Map<String, Object> attrs = span.attributes();
+        if (GenAiSpans.isToolCall(span)) {
+            String name = GenAiSpans.text(attrs, GenAiAttributes.TOOL_NAME);
+            return new Step(
+                    span, true, name != null ? name : span.name(), 
span.durationMs(), 0, 0, 0, null,
+                    GenAiSpans.text(attrs, 
GenAiAttributes.TOOL_CALL_ARGUMENTS),
+                    GenAiSpans.text(attrs, GenAiAttributes.TOOL_CALL_RESULT));
+        }
+        String model = GenAiSpans.model(attrs);
+        return new Step(
+                span, false, GenAiSpans.operation(span) + (model != null ? " " 
+ model : ""),
+                span.durationMs(), GenAiSpans.number(attrs, 
GenAiAttributes.INPUT_TOKENS),
+                GenAiSpans.number(attrs, GenAiAttributes.OUTPUT_TOKENS),
+                GenAiSpans.number(attrs, 
GenAiAttributes.CACHE_READ_INPUT_TOKENS),
+                GenAiSpans.text(attrs, GenAiAttributes.FINISH_REASONS), null, 
null);
+    }
+
+    /** The exchange id of the Camel span nearest above the span, or {@code 
null}. */
+    public static String exchangeId(SpanEntry span, List<SpanEntry> spans) {
+        Map<String, SpanEntry> byId = GenAiSpans.byId(spans);
+        SpanEntry current = span;
+        for (int hops = 0; hops < GenAiSpans.MAX_PARENT_HOPS && current != 
null; hops++) {
+            String exchangeId = GenAiSpans.text(current.attributes(), 
"exchangeId");
+            if (exchangeId != null) {
+                return exchangeId;
+            }
+            current = current.isRoot() ? null : 
byId.get(current.parentSpanId());
+        }
+        return null;
+    }
+
+    /** The first user message of the run (recorded at level full), or {@code 
null}. */
+    public static String firstUserMessage(AgentRun run, List<SpanEntry> spans) 
{
+        for (GenAiTranscript.Turn turn : GenAiTranscript.of(run.span(), 
spans).turns()) {
+            if (GenAiMessages.USER.equals(turn.role())) {
+                for (GenAiTranscript.Part part : turn.parts()) {
+                    if (part.kind() == GenAiTranscript.Kind.TEXT && 
part.text() != null) {
+                        return part.text();
+                    }
+                }
+            }
+        }
+        return null;
+    }
+}
diff --git 
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/GenAiSpanUsageExtractor.java
 
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/common/genai/GenAiSpans.java
similarity index 56%
copy from 
dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/GenAiSpanUsageExtractor.java
copy to 
dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/common/genai/GenAiSpans.java
index dcfd1f8c2a22..2d17b86a296d 100644
--- 
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/GenAiSpanUsageExtractor.java
+++ 
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/common/genai/GenAiSpans.java
@@ -14,10 +14,9 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.camel.dsl.jbang.core.commands.tui;
+package org.apache.camel.dsl.jbang.core.common.genai;
 
 import java.time.Instant;
-import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -28,9 +27,11 @@ import 
org.apache.camel.component.ai.observability.GenAiObservabilityLevel;
 import org.apache.camel.component.ai.observability.GenAiOperationName;
 
 /**
- * Converts OTel spans exported from monitored Camel integrations into AI 
usage entries for the TUI stats view.
+ * Reads the GenAI spans the Camel AI producers record 
(camel-ai-observability): which span is a model call, an agent
+ * run or a tool call, and at which observability level they were recorded. 
The Camel TUI and the MCP server read the
+ * spans the same way.
  */
-final class GenAiSpanUsageExtractor {
+public final class GenAiSpans {
 
     /**
      * The GenAI operations that are not a model call: an agent run and a tool 
call (observability level detailed and
@@ -49,7 +50,7 @@ final class GenAiSpanUsageExtractor {
             GenAiAttributes.INPUT_MESSAGES, GenAiAttributes.OUTPUT_MESSAGES, 
GenAiAttributes.SYSTEM_INSTRUCTIONS,
             GenAiAttributes.TOOL_CALL_ARGUMENTS, 
GenAiAttributes.TOOL_CALL_RESULT);
 
-    private static final int MAX_PARENT_HOPS = 50;
+    static final int MAX_PARENT_HOPS = 50;
 
     /**
      * The agent runs and tool calls among the GenAI spans, and the 
observability level they were recorded at.
@@ -59,97 +60,85 @@ final class GenAiSpanUsageExtractor {
      * @param toolCalls       the {@code execute_tool} spans
      * @param level           the level the Camel GenAI spans show, or {@code 
null} when there are none
      */
-    record GenAiActivity(int agentRuns, int agentModelCalls, int toolCalls, 
GenAiObservabilityLevel level) {
+    public record GenAiActivity(int agentRuns, int agentModelCalls, int 
toolCalls, GenAiObservabilityLevel level) {
 
-        static final GenAiActivity NONE = new GenAiActivity(0, 0, 0, null);
+        public static final GenAiActivity NONE = new GenAiActivity(0, 0, 0, 
null);
     }
 
-    private GenAiSpanUsageExtractor() {
+    private GenAiSpans() {
     }
 
     /** Any GenAI span: a model call, an agent run or a tool call. */
-    static boolean isGenAiSpan(SpanEntry span) {
-        if (span == null || span.attributes() == null) {
-            return false;
-        }
-        return span.attributes().containsKey(GenAiAttributes.OPERATION_NAME);
+    public static boolean isGenAiSpan(SpanEntry span) {
+        return span != null && span.attributes() != null
+                && 
span.attributes().containsKey(GenAiAttributes.OPERATION_NAME);
     }
 
     /**
      * A GenAI span of one model call (chat, embeddings, generate_content, 
...), not an agent run or a tool call. An
      * operation the Camel observability does not know, such as one recorded 
by an AI framework, counts as a model call.
      */
-    static boolean isModelCall(SpanEntry span) {
+    public static boolean isModelCall(SpanEntry span) {
         return isGenAiSpan(span) && 
!NON_MODEL_OPERATIONS.contains(operation(span));
     }
 
+    /** An agent run ({@code invoke_agent}). */
+    public static boolean isAgentRun(SpanEntry span) {
+        return GenAiOperationName.INVOKE_AGENT.value().equals(operation(span));
+    }
+
+    /** A tool call ({@code execute_tool}). */
+    public static boolean isToolCall(SpanEntry span) {
+        return GenAiOperationName.EXECUTE_TOOL.value().equals(operation(span));
+    }
+
+    /** The GenAI operation of a span ({@code gen_ai.operation.name}), or 
{@code null}. */
+    public static String operation(SpanEntry span) {
+        return span != null ? text(span.attributes(), 
GenAiAttributes.OPERATION_NAME) : null;
+    }
+
     /** The provider of a GenAI span: {@code gen_ai.system}, else the newer 
{@code gen_ai.provider.name}. */
-    static String provider(Map<String, Object> attrs) {
-        String provider = stringAttr(attrs, GenAiAttributes.SYSTEM);
-        if (isBlank(provider) || "unknown".equalsIgnoreCase(provider)) {
-            String name = stringAttr(attrs, GenAiAttributes.PROVIDER_NAME);
-            if (!isBlank(name)) {
+    public static String provider(Map<String, Object> attrs) {
+        String provider = text(attrs, GenAiAttributes.SYSTEM);
+        if (provider == null || "unknown".equalsIgnoreCase(provider)) {
+            String name = text(attrs, GenAiAttributes.PROVIDER_NAME);
+            if (name != null) {
                 return name;
             }
         }
         return provider;
     }
 
-    static List<AiUsageEntry> extract(List<SpanEntry> spans) {
-        if (spans == null || spans.isEmpty()) {
-            return List.of();
+    /** The model of a GenAI span: the response model, else the request model; 
{@code null} when not known. */
+    public static String model(Map<String, Object> attrs) {
+        String model = text(attrs, GenAiAttributes.RESPONSE_MODEL);
+        if (model == null) {
+            model = text(attrs, GenAiAttributes.REQUEST_MODEL);
         }
-        List<AiUsageEntry> entries = new ArrayList<>();
-        for (SpanEntry span : spans) {
-            if (!isModelCall(span)) {
-                continue;
-            }
-            AiUsageEntry entry = toUsageEntry(span);
-            if (entry != null) {
-                entries.add(entry);
-            }
-        }
-        return List.copyOf(entries);
+        return "unknown".equalsIgnoreCase(model) ? null : model;
     }
 
-    private static AiUsageEntry toUsageEntry(SpanEntry span) {
-        Map<String, Object> attrs = span.attributes();
-        String requestModel = stringAttr(attrs, GenAiAttributes.REQUEST_MODEL);
-        String responseModel = stringAttr(attrs, 
GenAiAttributes.RESPONSE_MODEL);
-        String model = !isBlank(responseModel) ? responseModel : requestModel;
-        if (isBlank(model) || "unknown".equalsIgnoreCase(model)) {
-            model = span.name() != null ? span.name() : "unknown";
+    /** A text attribute, or {@code null} when absent or blank. */
+    public static String text(Map<String, Object> attrs, String key) {
+        Object value = attrs != null ? attrs.get(key) : null;
+        if (value == null) {
+            return null;
         }
+        String text = value.toString();
+        return text.isBlank() ? null : text;
+    }
 
-        String provider = provider(attrs);
-        if (isBlank(provider)) {
-            provider = "unknown";
+    /** A number attribute (a number or a numeric text), or 0. */
+    public static long number(Map<String, Object> attrs, String key) {
+        Object value = attrs != null ? attrs.get(key) : null;
+        if (value instanceof Number n) {
+            return n.longValue();
+        }
+        try {
+            return value != null ? Long.parseLong(value.toString().trim()) : 0;
+        } catch (NumberFormatException e) {
+            return 0;
         }
-
-        int inputTokens = intAttr(attrs, GenAiAttributes.INPUT_TOKENS);
-        int outputTokens = intAttr(attrs, GenAiAttributes.OUTPUT_TOKENS);
-        int totalTokens = inputTokens + outputTokens;
-        int cachedInputTokens = intAttr(attrs, 
GenAiAttributes.CACHE_READ_INPUT_TOKENS);
-
-        long latencyMs = span.durationMs() > 0 ? span.durationMs() : 0;
-        String stopReason = stringAttr(attrs, GenAiAttributes.FINISH_REASONS);
-        Instant timestamp = span.startEpochNanos() > 0
-                ? Instant.ofEpochSecond(0, span.startEpochNanos())
-                : Instant.EPOCH;
-
-        return new AiUsageEntry(
-                model,
-                provider,
-                inputTokens,
-                outputTokens,
-                totalTokens,
-                latencyMs,
-                stopReason,
-                timestamp,
-                AiUsageSource.ROUTE,
-                span.routeId(),
-                0,
-                cachedInputTokens);
     }
 
     /**
@@ -157,18 +146,13 @@ final class GenAiSpanUsageExtractor {
      * and tells the observability level from the attributes of the Camel 
GenAI spans: the level is not exported with
      * the spans, but each level records attributes the level below does not.
      */
-    static GenAiActivity activity(List<SpanEntry> spans, Instant since) {
+    public static GenAiActivity activity(List<SpanEntry> spans, Instant since) 
{
         if (spans == null || spans.isEmpty()) {
             return GenAiActivity.NONE;
         }
         long sinceNanos = since != null && since.isAfter(Instant.EPOCH)
                 ? since.getEpochSecond() * 1_000_000_000L + since.getNano() : 
0;
-        Map<String, SpanEntry> byId = new HashMap<>();
-        for (SpanEntry span : spans) {
-            if (span != null && span.spanId() != null) {
-                byId.put(span.spanId(), span);
-            }
-        }
+        Map<String, SpanEntry> byId = byId(spans);
         int agentRuns = 0;
         int agentModelCalls = 0;
         int toolCalls = 0;
@@ -177,16 +161,15 @@ final class GenAiSpanUsageExtractor {
             if (!isGenAiSpan(span) || span.startEpochNanos() < sinceNanos) {
                 continue;
             }
-            String operation = operation(span);
-            if (GenAiOperationName.INVOKE_AGENT.value().equals(operation)) {
+            if (isAgentRun(span)) {
                 agentRuns++;
-            } else if 
(GenAiOperationName.EXECUTE_TOOL.value().equals(operation)) {
+            } else if (isToolCall(span)) {
                 toolCalls++;
-            } else if (isModelCall(span) && insideAgentRun(span, byId)) {
+            } else if (isModelCall(span) && nearestAgentRun(span, byId) != 
null) {
                 agentModelCalls++;
             }
             if (span.isCamelSpan()) {
-                GenAiObservabilityLevel spanLevel = levelOf(span, operation);
+                GenAiObservabilityLevel spanLevel = levelOf(span);
                 if (level == null || spanLevel.includes(level)) {
                     level = spanLevel;
                 }
@@ -195,14 +178,19 @@ final class GenAiSpanUsageExtractor {
         return new GenAiActivity(agentRuns, agentModelCalls, toolCalls, level);
     }
 
-    private static GenAiObservabilityLevel levelOf(SpanEntry span, String 
operation) {
+    /** The level the Camel GenAI spans show, or {@code null} when there are 
none. */
+    public static GenAiObservabilityLevel level(List<SpanEntry> spans) {
+        return activity(spans, null).level();
+    }
+
+    private static GenAiObservabilityLevel levelOf(SpanEntry span) {
         Map<String, Object> attrs = span.attributes();
         for (String key : FULL_ATTRIBUTES) {
             if (attrs.containsKey(key)) {
                 return GenAiObservabilityLevel.FULL;
             }
         }
-        if (NON_MODEL_OPERATIONS.contains(operation)) {
+        if (NON_MODEL_OPERATIONS.contains(operation(span))) {
             return GenAiObservabilityLevel.DETAILED;
         }
         for (String key : DETAILED_ATTRIBUTES) {
@@ -213,46 +201,26 @@ final class GenAiSpanUsageExtractor {
         return GenAiObservabilityLevel.BASIC;
     }
 
-    private static boolean insideAgentRun(SpanEntry span, Map<String, 
SpanEntry> byId) {
-        SpanEntry current = span;
-        for (int hops = 0; hops < MAX_PARENT_HOPS && current != null && 
!current.isRoot(); hops++) {
-            current = byId.get(current.parentSpanId());
-            if (current != null && 
GenAiOperationName.INVOKE_AGENT.value().equals(operation(current))) {
-                return true;
+    /** The spans by span id. */
+    static Map<String, SpanEntry> byId(List<SpanEntry> spans) {
+        Map<String, SpanEntry> byId = new HashMap<>();
+        for (SpanEntry span : spans) {
+            if (span != null && span.spanId() != null) {
+                byId.put(span.spanId(), span);
             }
         }
-        return false;
-    }
-
-    private static String operation(SpanEntry span) {
-        return span.attributes() != null ? stringAttr(span.attributes(), 
GenAiAttributes.OPERATION_NAME) : null;
+        return byId;
     }
 
-    private static String stringAttr(Map<String, Object> attrs, String key) {
-        Object value = attrs.get(key);
-        if (value == null) {
-            return null;
-        }
-        String text = value.toString();
-        return text.isBlank() ? null : text;
-    }
-
-    private static int intAttr(Map<String, Object> attrs, String key) {
-        Object value = attrs.get(key);
-        if (value == null) {
-            return 0;
-        }
-        if (value instanceof Number number) {
-            return number.intValue();
-        }
-        try {
-            return Integer.parseInt(value.toString());
-        } catch (NumberFormatException e) {
-            return 0;
+    /** The nearest agent run above a span, or {@code null}. */
+    static SpanEntry nearestAgentRun(SpanEntry span, Map<String, SpanEntry> 
byId) {
+        SpanEntry current = span;
+        for (int hops = 0; hops < MAX_PARENT_HOPS && current != null && 
!current.isRoot(); hops++) {
+            current = byId.get(current.parentSpanId());
+            if (current != null && isAgentRun(current)) {
+                return current;
+            }
         }
-    }
-
-    private static boolean isBlank(String value) {
-        return value == null || value.isBlank();
+        return null;
     }
 }
diff --git 
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/GenAiTranscript.java
 
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/common/genai/GenAiTranscript.java
similarity index 93%
rename from 
dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/GenAiTranscript.java
rename to 
dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/common/genai/GenAiTranscript.java
index 83782d2e1f85..b87b161b9cf9 100644
--- 
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/GenAiTranscript.java
+++ 
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/common/genai/GenAiTranscript.java
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.camel.dsl.jbang.core.commands.tui;
+package org.apache.camel.dsl.jbang.core.common.genai;
 
 import java.util.ArrayList;
 import java.util.Collection;
@@ -39,9 +39,9 @@ import org.apache.camel.util.json.Jsoner;
  * An agent run ({@code invoke_agent}) shows the input and output of its last 
model call: that input already holds the
  * whole conversation of the run, with every tool call and result.
  */
-final class GenAiTranscript {
+public final class GenAiTranscript {
 
-    enum Kind {
+    public enum Kind {
         TEXT,
         REASONING,
         TOOL_CALL,
@@ -52,19 +52,19 @@ final class GenAiTranscript {
      * A part of a message: a text, a tool call with its arguments, or a tool 
result. {@code id} pairs a tool call with
      * its result.
      */
-    record Part(Kind kind, String text, String toolName, String id) {
+    public record Part(Kind kind, String text, String toolName, String id) {
 
-        Part(Kind kind, String text) {
+        public Part(Kind kind, String text) {
             this(kind, text, null, null);
         }
     }
 
     /** A message: its role (system, user, assistant, tool), its parts, and 
the finish reason of an output message. */
-    record Turn(String role, List<Part> parts, String finishReason) {
+    public record Turn(String role, List<Part> parts, String finishReason) {
     }
 
     /** The mark {@code GenAiMessages} puts at the end of a text cut at {@code 
contentMaxLength}. */
-    static final String TRUNCATED = "...[truncated]";
+    public static final String TRUNCATED = "...[truncated]";
 
     private static final List<String> CONTENT_ATTRIBUTES = List.of(
             GenAiAttributes.INPUT_MESSAGES, GenAiAttributes.OUTPUT_MESSAGES, 
GenAiAttributes.SYSTEM_INSTRUCTIONS,
@@ -77,11 +77,11 @@ final class GenAiTranscript {
         this.turns = List.copyOf(turns);
     }
 
-    List<Turn> turns() {
+    public List<Turn> turns() {
         return turns;
     }
 
-    boolean isEmpty() {
+    public boolean isEmpty() {
         return turns.isEmpty();
     }
 
@@ -89,7 +89,7 @@ final class GenAiTranscript {
      * The conversation as Markdown: a heading per message, the texts as they 
are (a model answers in Markdown), and the
      * tool arguments and results as code blocks.
      */
-    String toMarkdown() {
+    public String toMarkdown() {
         StringBuilder sb = new StringBuilder();
         for (Turn turn : turns) {
             sb.append("### ").append(heading(turn)).append("\n\n");
@@ -164,15 +164,9 @@ final class GenAiTranscript {
         }
     }
 
-    /** Whether the span is a GenAI span: a model call, an agent run or a tool 
call. */
-    static boolean isGenAiSpan(SpanEntry span) {
-        return span != null && span.attributes() != null
-                && 
span.attributes().containsKey(GenAiAttributes.OPERATION_NAME);
-    }
-
     /** Whether the span carries message content, recorded at observability 
level {@code full}. */
-    static boolean hasContent(SpanEntry span) {
-        if (!isGenAiSpan(span)) {
+    public static boolean hasContent(SpanEntry span) {
+        if (!GenAiSpans.isGenAiSpan(span)) {
             return false;
         }
         for (String key : CONTENT_ATTRIBUTES) {
@@ -187,8 +181,8 @@ final class GenAiTranscript {
      * The conversation of a GenAI span. {@code traceSpans} are the spans of 
its trace, where the model calls of an
      * agent run are found.
      */
-    static GenAiTranscript of(SpanEntry span, List<SpanEntry> traceSpans) {
-        if (!isGenAiSpan(span)) {
+    public static GenAiTranscript of(SpanEntry span, List<SpanEntry> 
traceSpans) {
+        if (!GenAiSpans.isGenAiSpan(span)) {
             return new GenAiTranscript(List.of());
         }
         String operation = 
String.valueOf(span.attributes().get(GenAiAttributes.OPERATION_NAME));
@@ -248,7 +242,7 @@ final class GenAiTranscript {
         }
         SpanEntry last = null;
         for (SpanEntry s : traceSpans) {
-            if (s != agent && isGenAiSpan(s) && 
s.attributes().containsKey(GenAiAttributes.INPUT_MESSAGES)
+            if (s != agent && GenAiSpans.isGenAiSpan(s) && 
s.attributes().containsKey(GenAiAttributes.INPUT_MESSAGES)
                     && !isAgentOrTool(s) && isInside(s, agent.spanId(), byId)
                     && (last == null || s.startEpochNanos() >= 
last.startEpochNanos())) {
                 last = s;
@@ -301,7 +295,7 @@ final class GenAiTranscript {
      * Parses a {@code gen_ai.*.messages} or {@code 
gen_ai.system_instructions} attribute. A value that is not a JSON
      * array of messages is shown as one text.
      */
-    static List<Turn> parseMessages(String json) {
+    public static List<Turn> parseMessages(String json) {
         if (json == null || json.isBlank()) {
             return List.of();
         }
diff --git 
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/SpanEntry.java
 
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/common/genai/SpanEntry.java
similarity index 80%
rename from 
dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/SpanEntry.java
rename to 
dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/common/genai/SpanEntry.java
index b877a2a6ef80..f841e64eebfc 100644
--- 
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/SpanEntry.java
+++ 
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/common/genai/SpanEntry.java
@@ -14,13 +14,19 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.camel.dsl.jbang.core.commands.tui;
+package org.apache.camel.dsl.jbang.core.common.genai;
 
 import java.util.Map;
 
 import org.apache.camel.util.json.JsonObject;
 
-record SpanEntry(
+/**
+ * A span of the span dump of a running integration (the OpenTelemetry dev 
console, {@code camel cmd span} and the
+ * {@code get_spans} tool), as the Camel TUI and the MCP server read it.
+ *
+ * @param attributes the span attributes, {@code null} when there are none
+ */
+public record SpanEntry(
         String traceId,
         String spanId,
         String parentSpanId,
@@ -35,8 +41,9 @@ record SpanEntry(
         String scopeName,
         Map<String, Object> attributes) {
 
+    /** A span of the dump. */
     @SuppressWarnings("unchecked")
-    static SpanEntry fromJson(JsonObject jo) {
+    public static SpanEntry fromJson(JsonObject jo) {
         Map<String, Object> attrs = null;
         JsonObject attrsObj = jo.getMap("attributes");
         if (attrsObj != null && !attrsObj.isEmpty()) {
@@ -58,15 +65,15 @@ record SpanEntry(
                 attrs);
     }
 
-    boolean isRoot() {
+    public boolean isRoot() {
         return parentSpanId == null || parentSpanId.isEmpty();
     }
 
-    boolean isError() {
+    public boolean isError() {
         return "ERROR".equals(status);
     }
 
-    boolean isCamelSpan() {
+    public boolean isCamelSpan() {
         return scopeName == null || "camel".equals(scopeName);
     }
 }
diff --git 
a/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/common/genai/GenAiAgentRunsTest.java
 
b/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/common/genai/GenAiAgentRunsTest.java
new file mode 100644
index 000000000000..1585fc0a7fdf
--- /dev/null
+++ 
b/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/common/genai/GenAiAgentRunsTest.java
@@ -0,0 +1,130 @@
+/*
+ * 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.dsl.jbang.core.common.genai;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.camel.component.ai.observability.GenAiAttributes;
+import org.apache.camel.component.ai.observability.GenAiMessages;
+import org.apache.camel.component.ai.observability.GenAiObservabilityLevel;
+import org.apache.camel.dsl.jbang.core.common.genai.GenAiAgentRuns.AgentRun;
+import org.apache.camel.dsl.jbang.core.common.genai.GenAiAgentRuns.Step;
+import org.junit.jupiter.api.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+class GenAiAgentRunsTest {
+
+    @Test
+    void agentRunsAreTheNewestFirstWithTheirStepsInOrder() {
+        List<SpanEntry> spans = List.of(
+                route("route-old", 0), agent("old", "route-old", 10, 100),
+                route("route-new", 1000), agent("new", "route-new", 1010, 300),
+                chat("new-chat1", "new", 1020, 120, 300, 40, 270, 
"tool_calls"),
+                tool("new-tool", "new", 1150, 5, "{\"sku\":\"CAMEL-CAP\"}", "0 
CAMEL-CAP in stock"),
+                chat("new-chat2", "new", 1160, 140, 400, 20, 0, "stop"));
+
+        List<AgentRun> runs = GenAiAgentRuns.agentRuns(spans);
+
+        assertThat(runs).extracting(run -> 
run.span().spanId()).containsExactly("new", "old");
+        AgentRun run = runs.get(0);
+        assertThat(run.agentName()).isEqualTo("support");
+        assertThat(run.model()).isEqualTo("granite4:3b");
+        assertThat(run.steps()).extracting(Step::name)
+                .containsExactly("chat granite4:3b", "lookupStock", "chat 
granite4:3b");
+        
assertThat(run.steps().get(1).arguments()).isEqualTo("{\"sku\":\"CAMEL-CAP\"}");
+        assertThat(run.steps().get(1).result()).isEqualTo("0 CAMEL-CAP in 
stock");
+        assertThat(run.modelCalls()).isEqualTo(2);
+        assertThat(run.toolCalls()).isEqualTo(1);
+        assertThat(run.inputTokens()).isEqualTo(700);
+        assertThat(run.cachedTokens()).isEqualTo(270);
+        assertThat(run.modelMs()).isEqualTo(260);
+        assertThat(run.toolMs()).isEqualTo(5);
+        assertThat(run.otherMs()).isEqualTo(35);
+        assertThat(runs.get(1).steps()).isEmpty();
+        
assertThat(GenAiSpans.level(spans)).isEqualTo(GenAiObservabilityLevel.FULL);
+    }
+
+    @Test
+    void exchangeIdComesFromTheCamelSpanAboveTheRun() {
+        List<SpanEntry> spans = List.of(route("route1", 0), agent("run1", 
"route1", 10, 100));
+
+        assertThat(GenAiAgentRuns.exchangeId(spans.get(1), 
spans)).isEqualTo("EX-route1");
+        assertThat(GenAiAgentRuns.exchangeId(agent("lonely", null, 0, 10), 
List.of())).isNull();
+    }
+
+    @Test
+    void firstUserMessageIsTheQuestionOfTheRun() {
+        Map<String, Object> attrs = attrs("chat", 
GenAiAttributes.REQUEST_MODEL, "granite4:3b");
+        attrs.put(GenAiAttributes.INPUT_MESSAGES, new GenAiMessages()
+                .text(GenAiMessages.SYSTEM, "You answer the customers.")
+                .text(GenAiMessages.USER, "Is order ORD-1001 paid?")
+                .toJson(8192));
+        List<SpanEntry> spans = List.of(agent("run1", null, 0, 100), 
span("chat", "run1", 10, 50, attrs));
+
+        AgentRun run = GenAiAgentRuns.agentRun(spans.get(0), spans);
+
+        assertThat(GenAiAgentRuns.firstUserMessage(run, spans)).isEqualTo("Is 
order ORD-1001 paid?");
+        
assertThat(GenAiAgentRuns.firstUserMessage(GenAiAgentRuns.agentRun(spans.get(0),
 List.of(spans.get(0))),
+                List.of(spans.get(0)))).isNull();
+    }
+
+    private static SpanEntry route(String id, long startMs) {
+        return new SpanEntry(
+                "t", id, null, "file://questions", "INTERNAL", "OK", startMs * 
1_000_000L,
+                (startMs + 500) * 1_000_000L, 500, "support", null, "camel", 
Map.of("exchangeId", "EX-" + id));
+    }
+
+    private static SpanEntry agent(String id, String parent, long startMs, 
long ms) {
+        return span(id, parent, startMs, ms, attrs("invoke_agent", 
GenAiAttributes.AGENT_NAME, "support",
+                GenAiAttributes.REQUEST_MODEL, "granite4:3b"));
+    }
+
+    private static SpanEntry chat(
+            String id, String parent, long startMs, long ms, long in, long 
out, long cached, String finish) {
+        Map<String, Object> attrs = attrs("chat", 
GenAiAttributes.REQUEST_MODEL, "granite4:3b",
+                GenAiAttributes.FINISH_REASONS, finish);
+        attrs.put(GenAiAttributes.INPUT_TOKENS, in);
+        attrs.put(GenAiAttributes.OUTPUT_TOKENS, out);
+        if (cached > 0) {
+            attrs.put(GenAiAttributes.CACHE_READ_INPUT_TOKENS, cached);
+        }
+        return span(id, parent, startMs, ms, attrs);
+    }
+
+    private static SpanEntry tool(String id, String parent, long startMs, long 
ms, String args, String result) {
+        return span(id, parent, startMs, ms, attrs("execute_tool", 
GenAiAttributes.TOOL_NAME, "lookupStock",
+                GenAiAttributes.TOOL_CALL_ARGUMENTS, args, 
GenAiAttributes.TOOL_CALL_RESULT, result));
+    }
+
+    private static Map<String, Object> attrs(String operation, String... 
keyValues) {
+        Map<String, Object> attrs = new HashMap<>();
+        attrs.put(GenAiAttributes.OPERATION_NAME, operation);
+        for (int i = 0; i < keyValues.length; i += 2) {
+            attrs.put(keyValues[i], keyValues[i + 1]);
+        }
+        return attrs;
+    }
+
+    private static SpanEntry span(String id, String parent, long startMs, long 
ms, Map<String, Object> attributes) {
+        return new SpanEntry(
+                "t", id, parent, id, "INTERNAL", "OK", startMs * 1_000_000L, 
(startMs + ms) * 1_000_000L,
+                ms, "support", null, "camel", attributes);
+    }
+}
diff --git 
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/GenAiTranscriptTest.java
 
b/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/common/genai/GenAiTranscriptTest.java
similarity index 96%
rename from 
dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/GenAiTranscriptTest.java
rename to 
dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/common/genai/GenAiTranscriptTest.java
index 15366e120ae5..8cd0e3c68118 100644
--- 
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/GenAiTranscriptTest.java
+++ 
b/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/common/genai/GenAiTranscriptTest.java
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.camel.dsl.jbang.core.commands.tui;
+package org.apache.camel.dsl.jbang.core.common.genai;
 
 import java.util.HashMap;
 import java.util.List;
@@ -22,9 +22,9 @@ import java.util.Map;
 
 import org.apache.camel.component.ai.observability.GenAiAttributes;
 import org.apache.camel.component.ai.observability.GenAiMessages;
-import org.apache.camel.dsl.jbang.core.commands.tui.GenAiTranscript.Kind;
-import org.apache.camel.dsl.jbang.core.commands.tui.GenAiTranscript.Part;
-import org.apache.camel.dsl.jbang.core.commands.tui.GenAiTranscript.Turn;
+import org.apache.camel.dsl.jbang.core.common.genai.GenAiTranscript.Kind;
+import org.apache.camel.dsl.jbang.core.common.genai.GenAiTranscript.Part;
+import org.apache.camel.dsl.jbang.core.common.genai.GenAiTranscript.Turn;
 import org.junit.jupiter.api.Test;
 
 import static org.assertj.core.api.Assertions.assertThat;
@@ -129,10 +129,10 @@ class GenAiTranscriptTest {
         SpanEntry basic = span("chat", "", attrs("chat", 
GenAiAttributes.REQUEST_MODEL, "llama3.2"));
         SpanEntry route = span("route", "", Map.of("camel.uri", "timer:ask"));
 
-        assertThat(GenAiTranscript.isGenAiSpan(basic)).isTrue();
+        assertThat(GenAiSpans.isGenAiSpan(basic)).isTrue();
         assertThat(GenAiTranscript.hasContent(basic)).isFalse();
         assertThat(GenAiTranscript.of(basic, 
List.of(basic)).isEmpty()).isTrue();
-        assertThat(GenAiTranscript.isGenAiSpan(route)).isFalse();
+        assertThat(GenAiSpans.isGenAiSpan(route)).isFalse();
         assertThat(GenAiTranscript.of(route, 
List.of(route)).isEmpty()).isTrue();
     }
 
diff --git 
a/dsl/camel-jbang/camel-jbang-mcp/src/main/java/org/apache/camel/dsl/jbang/core/commands/mcp/AiTraceTools.java
 
b/dsl/camel-jbang/camel-jbang-mcp/src/main/java/org/apache/camel/dsl/jbang/core/commands/mcp/AiTraceTools.java
index 3cf96f77a0ce..3d3fe04d2a82 100644
--- 
a/dsl/camel-jbang/camel-jbang-mcp/src/main/java/org/apache/camel/dsl/jbang/core/commands/mcp/AiTraceTools.java
+++ 
b/dsl/camel-jbang/camel-jbang-mcp/src/main/java/org/apache/camel/dsl/jbang/core/commands/mcp/AiTraceTools.java
@@ -31,8 +31,10 @@ import io.quarkiverse.mcp.server.ToolGuardrails;
 import org.apache.camel.dsl.jbang.core.commands.ai.ToolContext;
 import org.apache.camel.dsl.jbang.core.commands.ai.ToolExecutionException;
 import org.apache.camel.dsl.jbang.core.commands.ai.ToolRegistry;
+import org.apache.camel.dsl.jbang.core.common.genai.SpanEntry;
 import org.apache.camel.util.json.JsonArray;
 import org.apache.camel.util.json.JsonObject;
+import org.jboss.logging.Logger;
 
 /**
  * MCP Tool for tracing AI-specific exchange flow in running Camel 
applications.
@@ -45,6 +47,11 @@ import org.apache.camel.util.json.JsonObject;
 @ApplicationScoped
 public class AiTraceTools {
 
+    private static final Logger LOG = Logger.getLogger(AiTraceTools.class);
+
+    /** The spans read for the GenAI part: an agent run with its route steps 
takes some 20 spans. */
+    private static final int SPAN_LIMIT = 1000;
+
     private static final String NAME_OR_PID_DESC
             = "Name or PID of the Camel process. Leave empty to auto-detect 
(works when exactly one Camel process is running)";
 
@@ -67,12 +74,14 @@ public class AiTraceTools {
 
     @ToolGuardrails(input = McpArgumentGuardrail.class, output = 
McpArgumentGuardrail.class)
     @Tool(annotations = @Tool.Annotations(readOnlyHint = true, destructiveHint 
= false, openWorldHint = false),
-          description = "Trace AI-specific exchange flow in a running Camel 
application. "
-                        + "Shows token usage, model IDs, guardrail outcomes, 
completion reasons, "
-                        + "streaming chunk counts, and per-component latency 
for AI components "
-                        + "(Bedrock, LangChain4j, Docling, Textract, OpenAI, 
KServe, DJL, "
-                        + "TensorFlow Serving, HuggingFace). "
-                        + "Combines message history with processor statistics 
filtered to AI steps.")
+          description = "Trace how a running Camel application used AI. Starts 
with the GenAI spans "
+                        + "(camel run --observe): a summary line, the model 
calls per model with their tokens, "
+                        + "and the newest agent runs with each model call and 
tool call (name, time, tokens, and "
+                        + "at camel.aiObservability.level=full the question, 
tool arguments and results). "
+                        + "Then token usage, model IDs, guardrail outcomes, 
completion reasons and per-component "
+                        + "latency of the AI components (Bedrock, LangChain4j, 
Docling, Textract, OpenAI, KServe, "
+                        + "DJL, TensorFlow Serving, HuggingFace) from the 
message history and processor "
+                        + "statistics. " + GenAiTraceReport.CONVERSATION_TOOL 
+ " shows the messages of one run.")
     public AiTraceResult camel_runtime_ai_trace(
             @ToolArg(description = NAME_OR_PID_DESC, required = false) String 
nameOrPid,
             @ToolArg(description = "Route ID filter (exact match or * for all, 
default: *)",
@@ -94,8 +103,10 @@ public class AiTraceTools {
             List<AiHeaderInfo> aiHeaders = extractAiHeaders(history);
             List<AiProcessorStat> aiProcessorStats = 
extractAiProcessorStats(topProcessors);
             AiTraceSummary summary = buildSummary(aiComponents, aiHeaders, 
aiProcessorStats);
+            List<SpanEntry> spans = loadSpans(ctx);
 
             return new AiTraceResult(
+                    GenAiTraceReport.summary(spans, filter), 
GenAiTraceReport.genAi(spans, filter),
                     p.name(), p.pid(),
                     aiComponents.isEmpty() ? null : aiComponents,
                     aiHeaders.isEmpty() ? null : aiHeaders,
@@ -109,6 +120,49 @@ public class AiTraceTools {
         }
     }
 
+    @ToolGuardrails(input = McpArgumentGuardrail.class, output = 
McpArgumentGuardrail.class)
+    @Tool(annotations = @Tool.Annotations(readOnlyHint = true, destructiveHint 
= false, openWorldHint = false),
+          description = "The conversation of one GenAI agent run of a running 
Camel application: the system "
+                        + "instructions, the user and assistant messages, and 
each tool call with its arguments and "
+                        + "result, in order. Take the runId from 
camel_runtime_ai_trace. The messages are recorded "
+                        + "at camel.aiObservability.level=full only and may 
hold customers' data; long texts are "
+                        + "cut, and the answer says what was cut.")
+    public GenAiTraceReport.Conversation camel_runtime_ai_conversation(
+            @ToolArg(description = NAME_OR_PID_DESC, required = false) String 
nameOrPid,
+            @ToolArg(description = "The runId of an agent run, as 
camel_runtime_ai_trace lists it") String runId) {
+
+        RuntimeService.ProcessInfo p = 
runtimeService.findSingleProcess(nameOrPid);
+        ToolContext ctx = new ToolContext();
+        ctx.selectProcess(p.pid());
+        List<SpanEntry> spans = loadSpans(ctx);
+        if (spans.isEmpty()) {
+            throw new ToolCallException(GenAiTraceReport.NO_SPANS, null);
+        }
+        GenAiTraceReport.Conversation conversation = 
GenAiTraceReport.conversation(spans, runId);
+        if (conversation == null) {
+            throw new ToolCallException(
+                    "No GenAI span with runId " + runId + ": 
camel_runtime_ai_trace lists the runIds of the newest "
+                                        + "agent runs, and older spans may 
have left the span dump.",
+                    null);
+        }
+        return conversation;
+    }
+
+    /**
+     * The spans of the span dump, or none when tracing is off or the dump 
cannot be read: the GenAI part of the trace
+     * then says how to turn it on. Not passed through {@link McpToolNames}, 
as the spans carry the messages of the
+     * models as they were.
+     */
+    List<SpanEntry> loadSpans(ToolContext ctx) {
+        try {
+            Object result = ToolRegistry.execute("get_spans", ctx, 
Map.of("limit", String.valueOf(SPAN_LIMIT)));
+            return GenAiTraceReport.spans(RuntimeTools.toJsonObject(result));
+        } catch (Exception e) {
+            LOG.debugf("The span dump cannot be read (%s): the trace shows no 
GenAI spans", e.getMessage());
+            return List.of();
+        }
+    }
+
     /**
      * Runs one registry query. A failure (the process is gone, or did not 
answer in time) is an error of the whole
      * call: answering with what the other queries returned would read as "no 
AI components".
@@ -289,6 +343,8 @@ public class AiTraceTools {
     // ---- Result records ----
 
     record AiTraceResult(
+            String genAiSummary,
+            GenAiTraceReport.GenAi genAi,
             String processName,
             long pid,
             List<AiComponentInfo> aiComponents,
diff --git 
a/dsl/camel-jbang/camel-jbang-mcp/src/main/java/org/apache/camel/dsl/jbang/core/commands/mcp/GenAiTraceReport.java
 
b/dsl/camel-jbang/camel-jbang-mcp/src/main/java/org/apache/camel/dsl/jbang/core/commands/mcp/GenAiTraceReport.java
new file mode 100644
index 000000000000..ab1edfb48e33
--- /dev/null
+++ 
b/dsl/camel-jbang/camel-jbang-mcp/src/main/java/org/apache/camel/dsl/jbang/core/commands/mcp/GenAiTraceReport.java
@@ -0,0 +1,298 @@
+/*
+ * 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.dsl.jbang.core.commands.mcp;
+
+import java.time.Instant;
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.camel.component.ai.observability.GenAiAttributes;
+import org.apache.camel.component.ai.observability.GenAiObservabilityLevel;
+import org.apache.camel.dsl.jbang.core.common.genai.GenAiAgentRuns;
+import org.apache.camel.dsl.jbang.core.common.genai.GenAiAgentRuns.AgentRun;
+import org.apache.camel.dsl.jbang.core.common.genai.GenAiAgentRuns.Step;
+import org.apache.camel.dsl.jbang.core.common.genai.GenAiSpans;
+import org.apache.camel.dsl.jbang.core.common.genai.GenAiTranscript;
+import org.apache.camel.dsl.jbang.core.common.genai.SpanEntry;
+import org.apache.camel.util.json.JsonArray;
+import org.apache.camel.util.json.JsonObject;
+
+/**
+ * The GenAI part of the AI trace and the conversation of a run, from the 
GenAI spans of the span dump (CAMEL-27312).
+ * Written for a model that reads the answer: the summary comes first and fits 
in the few hundred characters a chat
+ * history keeps of a tool result, the runs are the newest first and shallow, 
and the long texts are cut with a note.
+ * The words are those of the Camel TUI: agent run, model call, tool call.
+ */
+final class GenAiTraceReport {
+
+    static final String CONVERSATION_TOOL = "camel_runtime_ai_conversation";
+    static final int MAX_RUNS = 5;
+    static final int MAX_STEP_TEXT = 200;
+    static final int MAX_QUESTION = 200;
+    static final int MAX_MESSAGE = 1000;
+    static final int MAX_CONVERSATION = 6000;
+    private static final int MAX_MODELS_IN_SUMMARY = 3;
+
+    static final String NO_SPANS = "No GenAI spans. Run the integration with 
camel run --observe (it adds "
+                                   + "camel-ai-observability when a GenAI 
component is used) and set "
+                                   + "camel.aiObservability.level=detailed to 
see the agent runs and tool calls.";
+
+    /** The model calls of one model. */
+    record ModelCalls(String model, String provider, int calls, long 
inputTokens, long outputTokens, Long cachedTokens,
+            long avgMs, String finishReasons) {
+    }
+
+    /** A model call or tool call of a run; the arguments and result are 
recorded at level full only. */
+    record RunStep(String step, String name, long durationMs, Long 
inputTokens, Long outputTokens, Long cachedTokens,
+            String finishReason, String arguments, String result) {
+    }
+
+    /** An agent run; the question is its first user message, recorded at 
level full only. */
+    record Run(String runId, String question, String agent, String model, 
String routeId, String exchangeId,
+            String start, long durationMs, long modelCalls, long toolCalls, 
long inputTokens, long outputTokens,
+            Long cachedTokens, List<RunStep> steps) {
+    }
+
+    /** The GenAI part of the AI trace. */
+    record GenAi(String level, List<ModelCalls> modelCalls, List<Run> 
agentRuns, String moreRuns) {
+    }
+
+    /** A part of a message of a conversation. */
+    record Message(String role, String type, String tool, String text, String 
finishReason) {
+    }
+
+    /** The conversation of a run. */
+    record Conversation(String summary, String level, String runId, String 
agent, String model, List<Message> messages,
+            String cut) {
+    }
+
+    private GenAiTraceReport() {
+    }
+
+    /** The spans of a {@code get_spans} answer, or an empty list when tracing 
is off. */
+    static List<SpanEntry> spans(JsonObject dump) {
+        if (dump == null || Boolean.FALSE.equals(dump.getBoolean("enabled"))) {
+            return List.of();
+        }
+        JsonArray array = dump.getCollection("spans");
+        if (array == null) {
+            return List.of();
+        }
+        List<SpanEntry> spans = new ArrayList<>(array.size());
+        for (Object o : array) {
+            if (o instanceof JsonObject jo) {
+                spans.add(SpanEntry.fromJson(jo));
+            }
+        }
+        return spans;
+    }
+
+    /** The one-line summary: the level, the counts and what to do next. */
+    static String summary(List<SpanEntry> spans, String routeFilter) {
+        List<SpanEntry> modelCalls = modelCallSpans(spans, routeFilter);
+        GenAiObservabilityLevel level = GenAiSpans.level(spans);
+        if (level == null && modelCalls.isEmpty()) {
+            return NO_SPANS;
+        }
+        String models = String.join(", ", models(modelCalls));
+        String calls = modelCalls.size() + " model call" + (modelCalls.size() 
== 1 ? "" : "s")
+                       + (models.isEmpty() ? "" : " (" + models + ")");
+        if (level == null || level == GenAiObservabilityLevel.BASIC) {
+            return "GenAI level=basic: " + calls + ". Agent runs and tool 
calls are not traced: set "
+                   + "camel.aiObservability.level=detailed.";
+        }
+        List<AgentRun> runs = runs(spans, routeFilter);
+        long toolCalls = runs.stream().mapToLong(AgentRun::toolCalls).sum();
+        StringBuilder sb = new StringBuilder("GenAI 
level=").append(level(level)).append(": ")
+                .append(runs.size()).append(" agent run").append(runs.size() 
== 1 ? "" : "s").append(", ")
+                .append(calls).append(", ").append(toolCalls).append(" tool 
call").append(toolCalls == 1 ? "" : "s");
+        if (!runs.isEmpty()) {
+            sb.append("; runs newest first. ");
+            sb.append(level == GenAiObservabilityLevel.FULL
+                    ? CONVERSATION_TOOL + " with a runId shows the messages of 
a run."
+                    : "The messages need camel.aiObservability.level=full.");
+        }
+        return sb.toString();
+    }
+
+    /** The model calls per model, the newest five agent runs and the level; 
{@code null} without GenAI spans. */
+    static GenAi genAi(List<SpanEntry> spans, String routeFilter) {
+        List<SpanEntry> modelCalls = modelCallSpans(spans, routeFilter);
+        GenAiObservabilityLevel level = GenAiSpans.level(spans);
+        if (level == null && modelCalls.isEmpty()) {
+            return null;
+        }
+        List<AgentRun> runs = runs(spans, routeFilter);
+        List<Run> shown = runs.stream().limit(MAX_RUNS).map(run -> run(run, 
spans)).toList();
+        return new GenAi(
+                level(level), modelCalls(modelCalls), shown.isEmpty() ? null : 
shown,
+                runs.size() > MAX_RUNS ? "+" + (runs.size() - MAX_RUNS) + " 
more runs" : null);
+    }
+
+    /**
+     * The messages of a run (or of a model call or tool call) by its span id, 
cut at {@value #MAX_MESSAGE} characters a
+     * message and {@value #MAX_CONVERSATION} in all; {@code null} when there 
is no GenAI span with that id.
+     */
+    static Conversation conversation(List<SpanEntry> spans, String runId) {
+        SpanEntry span = spans.stream()
+                .filter(s -> runId != null && runId.equals(s.spanId()) && 
GenAiSpans.isGenAiSpan(s))
+                .findFirst().orElse(null);
+        if (span == null) {
+            return null;
+        }
+        String level = level(GenAiSpans.level(spans));
+        String agent = GenAiSpans.text(span.attributes(), 
GenAiAttributes.AGENT_NAME);
+        String model = GenAiSpans.model(span.attributes());
+        GenAiTranscript transcript = GenAiTranscript.of(span, spans);
+        if (transcript.isEmpty()) {
+            return new Conversation(
+                    "GenAI level=" + level + ": no messages for run " + runId
+                                    + ". The messages are recorded at 
camel.aiObservability.level=full only.",
+                    level, runId, agent, model, null, null);
+        }
+        List<Message> messages = new ArrayList<>();
+        int total = 0;
+        int left = 0;
+        for (GenAiTranscript.Turn turn : transcript.turns()) {
+            for (GenAiTranscript.Part part : turn.parts()) {
+                if (total >= MAX_CONVERSATION) {
+                    left++;
+                    continue;
+                }
+                String text = cut(part.text(), Math.min(MAX_MESSAGE, 
MAX_CONVERSATION - total));
+                total += text != null ? text.length() : 0;
+                messages.add(new Message(turn.role(), type(part.kind()), 
part.toolName(), text, turn.finishReason()));
+            }
+        }
+        String cut = left > 0
+                ? left + " more message parts not shown (" + MAX_CONVERSATION 
+ " characters in all)"
+                : null;
+        return new Conversation(
+                "GenAI level=" + level + ": " + messages.size() + " message 
parts of run " + runId
+                                + (left > 0 ? ", " + left + " more cut" : "")
+                                + ". Texts over " + MAX_MESSAGE + " characters 
are cut and end with '...'.",
+                level, runId, agent, model, messages, cut);
+    }
+
+    private static List<SpanEntry> modelCallSpans(List<SpanEntry> spans, 
String routeFilter) {
+        return spans.stream().filter(GenAiSpans::isModelCall).filter(s -> 
matches(s, routeFilter)).toList();
+    }
+
+    private static List<AgentRun> runs(List<SpanEntry> spans, String 
routeFilter) {
+        return GenAiAgentRuns.agentRuns(spans).stream().filter(run -> 
matches(run.span(), routeFilter)).toList();
+    }
+
+    private static boolean matches(SpanEntry span, String routeFilter) {
+        return routeFilter == null || routeFilter.isBlank() || 
"*".equals(routeFilter)
+                || routeFilter.equals(span.routeId());
+    }
+
+    private static Set<String> models(List<SpanEntry> modelCalls) {
+        Set<String> models = new LinkedHashSet<>();
+        for (SpanEntry span : modelCalls) {
+            String model = GenAiSpans.model(span.attributes());
+            if (model != null && models.size() < MAX_MODELS_IN_SUMMARY) {
+                models.add(model);
+            }
+        }
+        return models;
+    }
+
+    private static List<ModelCalls> modelCalls(List<SpanEntry> modelCalls) {
+        Map<String, List<SpanEntry>> byModel = new LinkedHashMap<>();
+        for (SpanEntry span : modelCalls) {
+            String model = GenAiSpans.model(span.attributes());
+            byModel.computeIfAbsent(model != null ? model : "unknown", k -> 
new ArrayList<>()).add(span);
+        }
+        List<ModelCalls> result = new ArrayList<>();
+        byModel.forEach((model, calls) -> {
+            long in = 0;
+            long out = 0;
+            long cached = 0;
+            long ms = 0;
+            Set<String> finishReasons = new LinkedHashSet<>();
+            for (SpanEntry span : calls) {
+                Map<String, Object> attrs = span.attributes();
+                in += GenAiSpans.number(attrs, GenAiAttributes.INPUT_TOKENS);
+                out += GenAiSpans.number(attrs, GenAiAttributes.OUTPUT_TOKENS);
+                cached += GenAiSpans.number(attrs, 
GenAiAttributes.CACHE_READ_INPUT_TOKENS);
+                ms += Math.max(0, span.durationMs());
+                String finish = GenAiSpans.text(attrs, 
GenAiAttributes.FINISH_REASONS);
+                if (finish != null) {
+                    finishReasons.add(finish);
+                }
+            }
+            result.add(new ModelCalls(
+                    model, GenAiSpans.provider(calls.get(0).attributes()), 
calls.size(), in, out,
+                    cached > 0 ? cached : null, ms / calls.size(),
+                    finishReasons.isEmpty() ? null : String.join(",", 
finishReasons)));
+        });
+        return result;
+    }
+
+    private static Run run(AgentRun run, List<SpanEntry> spans) {
+        SpanEntry span = run.span();
+        List<RunStep> steps = 
run.steps().stream().map(GenAiTraceReport::step).toList();
+        return new Run(
+                span.spanId(), cut(GenAiAgentRuns.firstUserMessage(run, 
spans), MAX_QUESTION), run.agentName(),
+                run.model(), span.routeId(), GenAiAgentRuns.exchangeId(span, 
spans),
+                span.startEpochNanos() > 0 ? Instant.ofEpochSecond(0, 
span.startEpochNanos()).toString() : null,
+                run.durationMs(), run.modelCalls(), run.toolCalls(), 
run.inputTokens(), run.outputTokens(),
+                run.cachedTokens() > 0 ? run.cachedTokens() : null, steps);
+    }
+
+    private static RunStep step(Step step) {
+        if (step.tool()) {
+            return new RunStep(
+                    "tool call", step.name(), step.durationMs(), null, null, 
null, null,
+                    cut(step.arguments(), MAX_STEP_TEXT), cut(step.result(), 
MAX_STEP_TEXT));
+        }
+        return new RunStep(
+                "model call", step.name(), step.durationMs(), 
step.inputTokens(), step.outputTokens(),
+                step.cachedTokens() > 0 ? step.cachedTokens() : null, 
step.finishReason(), null, null);
+    }
+
+    private static String type(GenAiTranscript.Kind kind) {
+        return switch (kind) {
+            case TEXT -> "text";
+            case REASONING -> "reasoning";
+            case TOOL_CALL -> "tool call";
+            case TOOL_RESULT -> "tool result";
+        };
+    }
+
+    private static String level(GenAiObservabilityLevel level) {
+        return level != null ? level.name().toLowerCase(Locale.ROOT) : "basic";
+    }
+
+    /** The text on one line, cut at {@code max} characters with "...". */
+    static String cut(String text, int max) {
+        if (text == null) {
+            return null;
+        }
+        String line = text.replaceAll("\\s+", " ").strip();
+        if (line.endsWith(GenAiTranscript.TRUNCATED)) {
+            line = line.substring(0, line.length() - 
GenAiTranscript.TRUNCATED.length()) + "...";
+        }
+        return line.length() > max ? line.substring(0, Math.max(0, max - 3)) + 
"..." : line;
+    }
+}
diff --git 
a/dsl/camel-jbang/camel-jbang-mcp/src/test/java/org/apache/camel/dsl/jbang/core/commands/mcp/GenAiTraceReportTest.java
 
b/dsl/camel-jbang/camel-jbang-mcp/src/test/java/org/apache/camel/dsl/jbang/core/commands/mcp/GenAiTraceReportTest.java
new file mode 100644
index 000000000000..49f7a09b93a6
--- /dev/null
+++ 
b/dsl/camel-jbang/camel-jbang-mcp/src/test/java/org/apache/camel/dsl/jbang/core/commands/mcp/GenAiTraceReportTest.java
@@ -0,0 +1,255 @@
+/*
+ * 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.dsl.jbang.core.commands.mcp;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.camel.component.ai.observability.GenAiAttributes;
+import org.apache.camel.component.ai.observability.GenAiMessages;
+import org.apache.camel.dsl.jbang.core.common.genai.SpanEntry;
+import org.apache.camel.util.json.JsonArray;
+import org.apache.camel.util.json.JsonObject;
+import org.junit.jupiter.api.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+class GenAiTraceReportTest {
+
+    private static final String QUESTION
+            = "Order ORD-1003 has a Camel cap in it: is the order paid, and is 
the cap in stock?";
+
+    @Test
+    void summaryComesFirstAndFitsInWhatAChatHistoryKeeps() {
+        String summary = GenAiTraceReport.summary(run("run1", 1000, true), 
"*");
+
+        assertThat(summary).isEqualTo(
+                "GenAI level=full: 1 agent run, 2 model calls (granite4:3b), 2 
tool calls; runs newest first. "
+                                      + "camel_runtime_ai_conversation with a 
runId shows the messages of a run.");
+        assertThat(summary.length()).isLessThan(400);
+    }
+
+    @Test
+    void agentRunHasItsQuestionAndItsStepsInOrder() {
+        List<SpanEntry> spans = run("run1", 1000, true);
+
+        GenAiTraceReport.GenAi genAi = GenAiTraceReport.genAi(spans, null);
+
+        assertThat(genAi.level()).isEqualTo("full");
+        assertThat(genAi.modelCalls()).singleElement().satisfies(m -> {
+            assertThat(m.model()).isEqualTo("granite4:3b");
+            assertThat(m.calls()).isEqualTo(2);
+            assertThat(m.inputTokens()).isEqualTo(694);
+            assertThat(m.cachedTokens()).isEqualTo(585);
+            assertThat(m.finishReasons()).isEqualTo("tool_calls,stop");
+        });
+        GenAiTraceReport.Run run = genAi.agentRuns().get(0);
+        assertThat(run.runId()).isEqualTo("run1");
+        assertThat(run.question()).isEqualTo(QUESTION);
+        assertThat(run.exchangeId()).isEqualTo("EX-run1");
+        assertThat(run.routeId()).isEqualTo("customer-questions");
+        assertThat(run.steps()).extracting(GenAiTraceReport.RunStep::step)
+                .containsExactly("model call", "tool call", "tool call", 
"model call");
+        assertThat(run.steps().get(1)).satisfies(step -> {
+            assertThat(step.name()).isEqualTo("order_status");
+            
assertThat(step.arguments()).isEqualTo("{\"orderId\":\"ORD-1003\"}");
+            assertThat(step.result()).isEqualTo("Order ORD-1003 for customer 
C-134 in US is pending with 3 line(s)");
+            assertThat(step.inputTokens()).isNull();
+        });
+        assertThat(genAi.moreRuns()).isNull();
+    }
+
+    @Test
+    void newestFiveRunsAreShown() {
+        List<SpanEntry> spans = new ArrayList<>();
+        for (int i = 1; i <= 7; i++) {
+            spans.addAll(run("run" + i, i * 10_000, false));
+        }
+
+        GenAiTraceReport.GenAi genAi = GenAiTraceReport.genAi(spans, "*");
+
+        assertThat(genAi.level()).isEqualTo("detailed");
+        assertThat(genAi.agentRuns()).extracting(GenAiTraceReport.Run::runId)
+                .containsExactly("run7", "run6", "run5", "run4", "run3");
+        assertThat(genAi.moreRuns()).isEqualTo("+2 more runs");
+        // level detailed records no messages: no question, no tool arguments
+        assertThat(genAi.agentRuns().get(0).question()).isNull();
+        
assertThat(genAi.agentRuns().get(0).steps().get(1).arguments()).isNull();
+        assertThat(GenAiTraceReport.summary(spans, "*"))
+                .startsWith("GenAI level=detailed: 7 agent runs, 14 model 
calls (granite4:3b), 14 tool calls")
+                .endsWith("The messages need 
camel.aiObservability.level=full.");
+    }
+
+    @Test
+    void summarySaysWhatToDoAtLevelBasicOrWithoutSpans() {
+        SpanEntry chat = span("chat", null, "orders", 0, 100,
+                attrs("chat", GenAiAttributes.SYSTEM, "openai", 
GenAiAttributes.REQUEST_MODEL, "gpt-4.1"));
+
+        assertThat(GenAiTraceReport.summary(List.of(chat), "*"))
+                .isEqualTo("GenAI level=basic: 1 model call (gpt-4.1). Agent 
runs and tool calls are not traced: "
+                           + "set camel.aiObservability.level=detailed.");
+        assertThat(GenAiTraceReport.summary(List.of(), 
"*")).isEqualTo(GenAiTraceReport.NO_SPANS);
+        assertThat(GenAiTraceReport.genAi(List.of(), "*")).isNull();
+    }
+
+    @Test
+    void routeFilterKeepsTheRunsOfThatRoute() {
+        assertThat(GenAiTraceReport.genAi(run("run1", 1000, true), 
"other-route").agentRuns()).isNull();
+        assertThat(GenAiTraceReport.genAi(run("run1", 1000, true), 
"customer-questions").agentRuns()).hasSize(1);
+    }
+
+    @Test
+    void spansAreReadFromTheDump() {
+        JsonObject span = new JsonObject();
+        span.put("traceId", "t1");
+        span.put("spanId", "s1");
+        span.put("name", "chat");
+        JsonObject attributes = new JsonObject();
+        attributes.put(GenAiAttributes.OPERATION_NAME, "chat");
+        span.put("attributes", attributes);
+        JsonObject dump = new JsonObject();
+        dump.put("enabled", true);
+        dump.put("spans", new JsonArray(List.of(span)));
+
+        assertThat(GenAiTraceReport.spans(dump)).singleElement()
+                .satisfies(s -> 
assertThat(s.attributes()).containsEntry(GenAiAttributes.OPERATION_NAME, 
"chat"));
+        dump.put("enabled", false);
+        assertThat(GenAiTraceReport.spans(dump)).isEmpty();
+        assertThat(GenAiTraceReport.spans(null)).isEmpty();
+    }
+
+    @Test
+    void conversationListsTheMessagesOfTheRunInOrder() {
+        GenAiTraceReport.Conversation conversation = 
GenAiTraceReport.conversation(run("run1", 1000, true), "run1");
+
+        assertThat(conversation.level()).isEqualTo("full");
+        assertThat(conversation.summary()).startsWith("GenAI level=full: 7 
message parts of run run1.");
+        assertThat(conversation.messages())
+                .extracting(m -> m.role() + ":" + m.type() + (m.tool() != null 
? ":" + m.tool() : ""))
+                .containsExactly("system:text", "user:text", "assistant:tool 
call:order_status",
+                        "assistant:tool call:stock_level", "tool:tool 
result:order_status",
+                        "tool:tool result:stock_level", "assistant:text");
+        assertThat(conversation.messages().get(6).text())
+                .isEqualTo("Your order ORD-1003 is still pending and the Camel 
cap is currently out of stock.");
+        assertThat(conversation.cut()).isNull();
+    }
+
+    @Test
+    void conversationIsCapped() {
+        String longAnswer = "x".repeat(GenAiTraceReport.MAX_MESSAGE * 2);
+        List<SpanEntry> spans = new ArrayList<>();
+        SpanEntry agent = span("run1", "route1", "customer-questions", 0, 1000,
+                attrs("invoke_agent", GenAiAttributes.REQUEST_MODEL, 
"granite4:3b"));
+        GenAiMessages input = new GenAiMessages();
+        for (int i = 0; i < 10; i++) {
+            input.text(GenAiMessages.USER, "question " + i + " " + longAnswer);
+        }
+        spans.add(agent);
+        spans.add(span("chat1", "run1", "customer-questions", 10, 100,
+                attrs("chat", GenAiAttributes.REQUEST_MODEL, "granite4:3b",
+                        GenAiAttributes.INPUT_MESSAGES, input.toJson(8192))));
+
+        GenAiTraceReport.Conversation conversation = 
GenAiTraceReport.conversation(spans, "run1");
+
+        assertThat(conversation.messages()).allSatisfy(m -> 
assertThat(m.text().length())
+                .isLessThanOrEqualTo(GenAiTraceReport.MAX_MESSAGE));
+        assertThat(conversation.messages().stream().mapToInt(m -> 
m.text().length()).sum())
+                .isLessThanOrEqualTo(GenAiTraceReport.MAX_CONVERSATION);
+        assertThat(conversation.messages().get(0).text()).endsWith("...");
+        assertThat(conversation.cut()).isEqualTo("4 more message parts not 
shown (6000 characters in all)");
+    }
+
+    @Test
+    void conversationOfARunWithoutMessagesSaysTheLevel() {
+        GenAiTraceReport.Conversation conversation = 
GenAiTraceReport.conversation(run("run1", 1000, false), "run1");
+
+        assertThat(conversation.messages()).isNull();
+        assertThat(conversation.summary()).isEqualTo("GenAI level=detailed: no 
messages for run run1. "
+                                                     + "The messages are 
recorded at camel.aiObservability.level=full only.");
+        assertThat(GenAiTraceReport.conversation(run("run1", 1000, false), 
"nope")).isNull();
+    }
+
+    /**
+     * The agent run of question 3 of the ai/agent-tools example: a route 
span, the agent run, a model call asking for
+     * two tools, the two tool calls, and the model call that answers. {@code 
full} adds the messages.
+     */
+    private static List<SpanEntry> run(String id, long startMs, boolean full) {
+        List<SpanEntry> spans = new ArrayList<>();
+        spans.add(new SpanEntry(
+                "trace-" + id, "route-" + id, null, "file://questions", 
"INTERNAL", "OK",
+                startMs * 1_000_000L, (startMs + 1010) * 1_000_000L, 1010, 
"customer-questions", null, "camel",
+                Map.of("exchangeId", "EX-" + id)));
+        spans.add(span(id, "route-" + id, "customer-questions", startMs + 2, 
1002,
+                attrs("invoke_agent", GenAiAttributes.AGENT_NAME, 
"customer-questions",
+                        GenAiAttributes.REQUEST_MODEL, "granite4:3b", 
GenAiAttributes.PROVIDER_NAME, "openai")));
+        Map<String, Object> chat1 = attrs("chat", 
GenAiAttributes.REQUEST_MODEL, "granite4:3b",
+                GenAiAttributes.PROVIDER_NAME, "openai", 
GenAiAttributes.FINISH_REASONS, "tool_calls");
+        chat1.put(GenAiAttributes.INPUT_TOKENS, 300L);
+        chat1.put(GenAiAttributes.OUTPUT_TOKENS, 47L);
+        chat1.put(GenAiAttributes.CACHE_READ_INPUT_TOKENS, 271L);
+        Map<String, Object> chat2 = attrs("chat", 
GenAiAttributes.REQUEST_MODEL, "granite4:3b",
+                GenAiAttributes.PROVIDER_NAME, "openai", 
GenAiAttributes.FINISH_REASONS, "stop");
+        chat2.put(GenAiAttributes.INPUT_TOKENS, 394L);
+        chat2.put(GenAiAttributes.OUTPUT_TOKENS, 20L);
+        chat2.put(GenAiAttributes.CACHE_READ_INPUT_TOKENS, 314L);
+        Map<String, Object> tool1 = attrs("execute_tool", 
GenAiAttributes.TOOL_NAME, "order_status");
+        Map<String, Object> tool2 = attrs("execute_tool", 
GenAiAttributes.TOOL_NAME, "stock_level");
+        if (full) {
+            chat2.put(GenAiAttributes.INPUT_MESSAGES, new GenAiMessages()
+                    .text(GenAiMessages.SYSTEM, "You answer the customers of a 
web shop.")
+                    .text(GenAiMessages.USER, QUESTION)
+                    .text(GenAiMessages.ASSISTANT, null)
+                    .toolCall("c1", "order_status", 
"{\"orderId\":\"ORD-1003\"}")
+                    .toolCall("c2", "stock_level", "{\"sku\":\"CAMEL-CAP\"}")
+                    .toolResult("c1", "Order ORD-1003 for customer C-134 in US 
is pending with 3 line(s)")
+                    .toolResult("c2", "0 CAMEL-CAP in stock")
+                    .toJson(8192));
+            chat2.put(GenAiAttributes.OUTPUT_MESSAGES, new GenAiMessages()
+                    .text(GenAiMessages.ASSISTANT,
+                            "Your order ORD-1003 is still pending and the 
Camel cap is currently out of stock.")
+                    .finishReason("stop")
+                    .toJson(8192));
+            tool1.put(GenAiAttributes.TOOL_CALL_ARGUMENTS, 
"{\"orderId\":\"ORD-1003\"}");
+            tool1.put(GenAiAttributes.TOOL_CALL_RESULT, "Order ORD-1003 for 
customer C-134 in US is pending with 3 line(s)");
+            tool2.put(GenAiAttributes.TOOL_CALL_ARGUMENTS, 
"{\"sku\":\"CAMEL-CAP\"}");
+            tool2.put(GenAiAttributes.TOOL_CALL_RESULT, "0 CAMEL-CAP in 
stock");
+        }
+        spans.add(span(id + "-chat1", id, "customer-questions", startMs + 3, 
615, chat1));
+        spans.add(span(id + "-tool1", id, "customer-questions", startMs + 620, 
4, tool1));
+        spans.add(span(id + "-tool2", id, "customer-questions", startMs + 625, 
2, tool2));
+        spans.add(span(id + "-chat2", id, "customer-questions", startMs + 630, 
378, chat2));
+        return spans;
+    }
+
+    private static Map<String, Object> attrs(String operation, String... 
keyValues) {
+        Map<String, Object> attrs = new HashMap<>();
+        attrs.put(GenAiAttributes.OPERATION_NAME, operation);
+        for (int i = 0; i < keyValues.length; i += 2) {
+            attrs.put(keyValues[i], keyValues[i + 1]);
+        }
+        return attrs;
+    }
+
+    private static SpanEntry span(
+            String spanId, String parentSpanId, String routeId, long startMs, 
long ms, Map<String, Object> attributes) {
+        return new SpanEntry(
+                "trace-1", spanId, parentSpanId, spanId, "INTERNAL", "OK", 
startMs * 1_000_000L,
+                (startMs + ms) * 1_000_000L, ms, routeId, null, "camel", 
attributes);
+    }
+}
diff --git 
a/dsl/camel-jbang/camel-jbang-mcp/src/test/java/org/apache/camel/dsl/jbang/core/commands/mcp/RuntimeToolsWiringTest.java
 
b/dsl/camel-jbang/camel-jbang-mcp/src/test/java/org/apache/camel/dsl/jbang/core/commands/mcp/RuntimeToolsWiringTest.java
index 76b3d3c9a471..05f64223436f 100644
--- 
a/dsl/camel-jbang/camel-jbang-mcp/src/test/java/org/apache/camel/dsl/jbang/core/commands/mcp/RuntimeToolsWiringTest.java
+++ 
b/dsl/camel-jbang/camel-jbang-mcp/src/test/java/org/apache/camel/dsl/jbang/core/commands/mcp/RuntimeToolsWiringTest.java
@@ -403,6 +403,14 @@ class RuntimeToolsWiringTest {
 
         Method aiTrace = 
AiTraceTools.class.getDeclaredMethod("camel_runtime_ai_trace", String.class, 
String.class);
         
assertThat(aiTrace.getParameters()[0].getAnnotation(ToolArg.class).required()).isFalse();
+
+        // the conversation of a run: one argument a model must give, the 
runId from the trace
+        Method conversation = 
AiTraceTools.class.getDeclaredMethod("camel_runtime_ai_conversation", 
String.class,
+                String.class);
+        
assertThat(conversation.getParameters()[0].getAnnotation(ToolArg.class).required()).isFalse();
+        
assertThat(conversation.getParameters()[1].getAnnotation(ToolArg.class).required()).isTrue();
+        Tool.Annotations hints = 
conversation.getAnnotation(Tool.class).annotations();
+        assertThat(List.of(hints.readOnlyHint(), 
hints.destructiveHint())).containsExactly(true, false);
     }
 
     private static List<Boolean> hints(String tool, Class<?>... parameters) 
throws Exception {
diff --git 
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/AiPanel.java
 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/AiPanel.java
index bbe5c7000aa4..b79c92b6d771 100644
--- 
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/AiPanel.java
+++ 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/AiPanel.java
@@ -69,6 +69,7 @@ import 
org.apache.camel.dsl.jbang.core.commands.ai.AnswerChecks;
 import org.apache.camel.dsl.jbang.core.commands.ai.AppFeatures;
 import org.apache.camel.dsl.jbang.core.commands.ai.ToolConfirms;
 import org.apache.camel.dsl.jbang.core.common.ExampleHelper;
+import org.apache.camel.dsl.jbang.core.common.genai.SpanEntry;
 import org.apache.camel.dsl.jbang.run.common.Printer;
 import org.apache.camel.util.json.JsonObject;
 
diff --git 
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/AiUsageStats.java
 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/AiUsageStats.java
index 99f4deb7caab..ec2566aef039 100644
--- 
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/AiUsageStats.java
+++ 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/AiUsageStats.java
@@ -44,7 +44,9 @@ import dev.tamboui.widgets.table.Table;
 import dev.tamboui.widgets.table.TableState;
 import org.apache.camel.component.ai.observability.GenAiObservabilityLevel;
 import org.apache.camel.dsl.jbang.core.commands.LlmClient;
-import 
org.apache.camel.dsl.jbang.core.commands.tui.GenAiSpanUsageExtractor.GenAiActivity;
+import org.apache.camel.dsl.jbang.core.common.genai.GenAiSpans;
+import org.apache.camel.dsl.jbang.core.common.genai.GenAiSpans.GenAiActivity;
+import org.apache.camel.dsl.jbang.core.common.genai.SpanEntry;
 
 import static 
org.apache.camel.dsl.jbang.core.commands.tui.AiPanel.formatSeconds;
 
@@ -390,7 +392,7 @@ final class AiUsageStats {
 
     /** The agent runs and tool calls of the integration since the last reset, 
and its GenAI observability level. */
     GenAiActivity activity() {
-        return GenAiSpanUsageExtractor.activity(otelSpans.get(), usageResetAt);
+        return GenAiSpans.activity(otelSpans.get(), usageResetAt);
     }
 
     /**
diff --git 
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/DataRefreshService.java
 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/DataRefreshService.java
index fa0ad4584e6a..2e0f9b6e304c 100644
--- 
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/DataRefreshService.java
+++ 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/DataRefreshService.java
@@ -37,6 +37,7 @@ import java.util.stream.Collectors;
 
 import dev.tamboui.tui.TuiRunner;
 import org.apache.camel.dsl.jbang.core.common.CommandLineHelper;
+import org.apache.camel.dsl.jbang.core.common.genai.SpanEntry;
 import org.apache.camel.util.json.JsonArray;
 import org.apache.camel.util.json.JsonObject;
 import org.apache.camel.util.json.Jsoner;
diff --git 
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/GenAiSpanUsageExtractor.java
 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/GenAiSpanUsageExtractor.java
index dcfd1f8c2a22..8a5983a021a7 100644
--- 
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/GenAiSpanUsageExtractor.java
+++ 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/GenAiSpanUsageExtractor.java
@@ -18,95 +18,30 @@ package org.apache.camel.dsl.jbang.core.commands.tui;
 
 import java.time.Instant;
 import java.util.ArrayList;
-import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
-import java.util.Set;
 
 import org.apache.camel.component.ai.observability.GenAiAttributes;
-import org.apache.camel.component.ai.observability.GenAiObservabilityLevel;
-import org.apache.camel.component.ai.observability.GenAiOperationName;
+import org.apache.camel.dsl.jbang.core.common.genai.GenAiSpans;
+import org.apache.camel.dsl.jbang.core.common.genai.SpanEntry;
 
 /**
- * Converts OTel spans exported from monitored Camel integrations into AI 
usage entries for the TUI stats view.
+ * Converts the GenAI model calls among the OTel spans of a monitored Camel 
integration into AI usage entries for the
+ * TUI stats view. Which span is a model call is decided by {@link 
GenAiSpans}, shared with the MCP server.
  */
 final class GenAiSpanUsageExtractor {
 
-    /**
-     * The GenAI operations that are not a model call: an agent run and a tool 
call (observability level detailed and
-     * above), and {@code create_agent} of the OpenTelemetry conventions, 
which AI frameworks may record.
-     */
-    private static final Set<String> NON_MODEL_OPERATIONS = Set.of(
-            GenAiOperationName.INVOKE_AGENT.value(), 
GenAiOperationName.EXECUTE_TOOL.value(), "create_agent");
-
-    /** The attributes only recorded at observability level detailed and 
above. */
-    private static final List<String> DETAILED_ATTRIBUTES = List.of(
-            GenAiAttributes.PROVIDER_NAME, GenAiAttributes.AGENT_NAME, 
GenAiAttributes.TOOL_NAME,
-            GenAiAttributes.CONVERSATION_ID, 
GenAiAttributes.CACHE_READ_INPUT_TOKENS);
-
-    /** The attributes only recorded at observability level full. */
-    private static final List<String> FULL_ATTRIBUTES = List.of(
-            GenAiAttributes.INPUT_MESSAGES, GenAiAttributes.OUTPUT_MESSAGES, 
GenAiAttributes.SYSTEM_INSTRUCTIONS,
-            GenAiAttributes.TOOL_CALL_ARGUMENTS, 
GenAiAttributes.TOOL_CALL_RESULT);
-
-    private static final int MAX_PARENT_HOPS = 50;
-
-    /**
-     * The agent runs and tool calls among the GenAI spans, and the 
observability level they were recorded at.
-     *
-     * @param agentRuns       the {@code invoke_agent} spans
-     * @param agentModelCalls the model calls made inside an agent run
-     * @param toolCalls       the {@code execute_tool} spans
-     * @param level           the level the Camel GenAI spans show, or {@code 
null} when there are none
-     */
-    record GenAiActivity(int agentRuns, int agentModelCalls, int toolCalls, 
GenAiObservabilityLevel level) {
-
-        static final GenAiActivity NONE = new GenAiActivity(0, 0, 0, null);
-    }
-
     private GenAiSpanUsageExtractor() {
     }
 
-    /** Any GenAI span: a model call, an agent run or a tool call. */
-    static boolean isGenAiSpan(SpanEntry span) {
-        if (span == null || span.attributes() == null) {
-            return false;
-        }
-        return span.attributes().containsKey(GenAiAttributes.OPERATION_NAME);
-    }
-
-    /**
-     * A GenAI span of one model call (chat, embeddings, generate_content, 
...), not an agent run or a tool call. An
-     * operation the Camel observability does not know, such as one recorded 
by an AI framework, counts as a model call.
-     */
-    static boolean isModelCall(SpanEntry span) {
-        return isGenAiSpan(span) && 
!NON_MODEL_OPERATIONS.contains(operation(span));
-    }
-
-    /** The provider of a GenAI span: {@code gen_ai.system}, else the newer 
{@code gen_ai.provider.name}. */
-    static String provider(Map<String, Object> attrs) {
-        String provider = stringAttr(attrs, GenAiAttributes.SYSTEM);
-        if (isBlank(provider) || "unknown".equalsIgnoreCase(provider)) {
-            String name = stringAttr(attrs, GenAiAttributes.PROVIDER_NAME);
-            if (!isBlank(name)) {
-                return name;
-            }
-        }
-        return provider;
-    }
-
     static List<AiUsageEntry> extract(List<SpanEntry> spans) {
         if (spans == null || spans.isEmpty()) {
             return List.of();
         }
         List<AiUsageEntry> entries = new ArrayList<>();
         for (SpanEntry span : spans) {
-            if (!isModelCall(span)) {
-                continue;
-            }
-            AiUsageEntry entry = toUsageEntry(span);
-            if (entry != null) {
-                entries.add(entry);
+            if (GenAiSpans.isModelCall(span)) {
+                entries.add(toUsageEntry(span));
             }
         }
         return List.copyOf(entries);
@@ -114,145 +49,22 @@ final class GenAiSpanUsageExtractor {
 
     private static AiUsageEntry toUsageEntry(SpanEntry span) {
         Map<String, Object> attrs = span.attributes();
-        String requestModel = stringAttr(attrs, GenAiAttributes.REQUEST_MODEL);
-        String responseModel = stringAttr(attrs, 
GenAiAttributes.RESPONSE_MODEL);
-        String model = !isBlank(responseModel) ? responseModel : requestModel;
-        if (isBlank(model) || "unknown".equalsIgnoreCase(model)) {
+        String model = GenAiSpans.model(attrs);
+        if (model == null) {
             model = span.name() != null ? span.name() : "unknown";
         }
-
-        String provider = provider(attrs);
-        if (isBlank(provider)) {
+        String provider = GenAiSpans.provider(attrs);
+        if (provider == null) {
             provider = "unknown";
         }
-
-        int inputTokens = intAttr(attrs, GenAiAttributes.INPUT_TOKENS);
-        int outputTokens = intAttr(attrs, GenAiAttributes.OUTPUT_TOKENS);
-        int totalTokens = inputTokens + outputTokens;
-        int cachedInputTokens = intAttr(attrs, 
GenAiAttributes.CACHE_READ_INPUT_TOKENS);
-
-        long latencyMs = span.durationMs() > 0 ? span.durationMs() : 0;
-        String stopReason = stringAttr(attrs, GenAiAttributes.FINISH_REASONS);
-        Instant timestamp = span.startEpochNanos() > 0
-                ? Instant.ofEpochSecond(0, span.startEpochNanos())
-                : Instant.EPOCH;
-
+        int inputTokens = (int) GenAiSpans.number(attrs, 
GenAiAttributes.INPUT_TOKENS);
+        int outputTokens = (int) GenAiSpans.number(attrs, 
GenAiAttributes.OUTPUT_TOKENS);
+        int cachedInputTokens = (int) GenAiSpans.number(attrs, 
GenAiAttributes.CACHE_READ_INPUT_TOKENS);
+        long latencyMs = Math.max(0, span.durationMs());
+        Instant timestamp = span.startEpochNanos() > 0 ? 
Instant.ofEpochSecond(0, span.startEpochNanos()) : Instant.EPOCH;
         return new AiUsageEntry(
-                model,
-                provider,
-                inputTokens,
-                outputTokens,
-                totalTokens,
-                latencyMs,
-                stopReason,
-                timestamp,
-                AiUsageSource.ROUTE,
-                span.routeId(),
-                0,
-                cachedInputTokens);
-    }
-
-    /**
-     * Counts the agent runs, their model calls and the tool calls among the 
spans started at or after {@code since},
-     * and tells the observability level from the attributes of the Camel 
GenAI spans: the level is not exported with
-     * the spans, but each level records attributes the level below does not.
-     */
-    static GenAiActivity activity(List<SpanEntry> spans, Instant since) {
-        if (spans == null || spans.isEmpty()) {
-            return GenAiActivity.NONE;
-        }
-        long sinceNanos = since != null && since.isAfter(Instant.EPOCH)
-                ? since.getEpochSecond() * 1_000_000_000L + since.getNano() : 
0;
-        Map<String, SpanEntry> byId = new HashMap<>();
-        for (SpanEntry span : spans) {
-            if (span != null && span.spanId() != null) {
-                byId.put(span.spanId(), span);
-            }
-        }
-        int agentRuns = 0;
-        int agentModelCalls = 0;
-        int toolCalls = 0;
-        GenAiObservabilityLevel level = null;
-        for (SpanEntry span : spans) {
-            if (!isGenAiSpan(span) || span.startEpochNanos() < sinceNanos) {
-                continue;
-            }
-            String operation = operation(span);
-            if (GenAiOperationName.INVOKE_AGENT.value().equals(operation)) {
-                agentRuns++;
-            } else if 
(GenAiOperationName.EXECUTE_TOOL.value().equals(operation)) {
-                toolCalls++;
-            } else if (isModelCall(span) && insideAgentRun(span, byId)) {
-                agentModelCalls++;
-            }
-            if (span.isCamelSpan()) {
-                GenAiObservabilityLevel spanLevel = levelOf(span, operation);
-                if (level == null || spanLevel.includes(level)) {
-                    level = spanLevel;
-                }
-            }
-        }
-        return new GenAiActivity(agentRuns, agentModelCalls, toolCalls, level);
-    }
-
-    private static GenAiObservabilityLevel levelOf(SpanEntry span, String 
operation) {
-        Map<String, Object> attrs = span.attributes();
-        for (String key : FULL_ATTRIBUTES) {
-            if (attrs.containsKey(key)) {
-                return GenAiObservabilityLevel.FULL;
-            }
-        }
-        if (NON_MODEL_OPERATIONS.contains(operation)) {
-            return GenAiObservabilityLevel.DETAILED;
-        }
-        for (String key : DETAILED_ATTRIBUTES) {
-            if (attrs.containsKey(key)) {
-                return GenAiObservabilityLevel.DETAILED;
-            }
-        }
-        return GenAiObservabilityLevel.BASIC;
-    }
-
-    private static boolean insideAgentRun(SpanEntry span, Map<String, 
SpanEntry> byId) {
-        SpanEntry current = span;
-        for (int hops = 0; hops < MAX_PARENT_HOPS && current != null && 
!current.isRoot(); hops++) {
-            current = byId.get(current.parentSpanId());
-            if (current != null && 
GenAiOperationName.INVOKE_AGENT.value().equals(operation(current))) {
-                return true;
-            }
-        }
-        return false;
-    }
-
-    private static String operation(SpanEntry span) {
-        return span.attributes() != null ? stringAttr(span.attributes(), 
GenAiAttributes.OPERATION_NAME) : null;
-    }
-
-    private static String stringAttr(Map<String, Object> attrs, String key) {
-        Object value = attrs.get(key);
-        if (value == null) {
-            return null;
-        }
-        String text = value.toString();
-        return text.isBlank() ? null : text;
-    }
-
-    private static int intAttr(Map<String, Object> attrs, String key) {
-        Object value = attrs.get(key);
-        if (value == null) {
-            return 0;
-        }
-        if (value instanceof Number number) {
-            return number.intValue();
-        }
-        try {
-            return Integer.parseInt(value.toString());
-        } catch (NumberFormatException e) {
-            return 0;
-        }
-    }
-
-    private static boolean isBlank(String value) {
-        return value == null || value.isBlank();
+                model, provider, inputTokens, outputTokens, inputTokens + 
outputTokens, latencyMs,
+                GenAiSpans.text(attrs, GenAiAttributes.FINISH_REASONS), 
timestamp, AiUsageSource.ROUTE, span.routeId(),
+                0, cachedInputTokens);
     }
 }
diff --git 
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/GenAiSpanView.java
 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/GenAiSpanView.java
index 385a2863a75e..909feaca2ad8 100644
--- 
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/GenAiSpanView.java
+++ 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/GenAiSpanView.java
@@ -17,8 +17,6 @@
 package org.apache.camel.dsl.jbang.core.commands.tui;
 
 import java.util.ArrayList;
-import java.util.Comparator;
-import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
@@ -27,8 +25,11 @@ import dev.tamboui.text.CharWidth;
 import dev.tamboui.text.Line;
 import dev.tamboui.text.Span;
 import org.apache.camel.component.ai.observability.GenAiAttributes;
-import org.apache.camel.component.ai.observability.GenAiOperationName;
 import org.apache.camel.dsl.jbang.core.commands.LlmClient;
+import org.apache.camel.dsl.jbang.core.common.genai.GenAiAgentRuns.AgentRun;
+import org.apache.camel.dsl.jbang.core.common.genai.GenAiAgentRuns.Step;
+import org.apache.camel.dsl.jbang.core.common.genai.GenAiSpans;
+import org.apache.camel.dsl.jbang.core.common.genai.SpanEntry;
 
 /**
  * How the Spans tab shows GenAI spans: a label per span in the waterfall (an 
agent run, a model call with its tokens
@@ -43,81 +44,34 @@ final class GenAiSpanView {
 
     private static final int MAX_ARGUMENTS = 40;
     private static final int MAX_STEPS = 8;
-    private static final int MAX_PARENT_HOPS = 50;
-
-    /** A model call or tool call of an agent run. */
-    record Step(SpanEntry span, boolean tool, String name, long durationMs, 
long inputTokens, long outputTokens,
-            long cachedTokens, String finishReason) {
-    }
-
-    /** An agent run with its steps in the order they started. */
-    record AgentRun(String agentName, String model, String provider, String 
conversationId, long durationMs,
-            List<Step> steps) {
-
-        long modelCalls() {
-            return steps.stream().filter(s -> !s.tool()).count();
-        }
-
-        long toolCalls() {
-            return steps.stream().filter(Step::tool).count();
-        }
-
-        long inputTokens() {
-            return steps.stream().mapToLong(Step::inputTokens).sum();
-        }
-
-        long outputTokens() {
-            return steps.stream().mapToLong(Step::outputTokens).sum();
-        }
-
-        long cachedTokens() {
-            return steps.stream().mapToLong(Step::cachedTokens).sum();
-        }
-
-        long modelMs() {
-            return steps.stream().filter(s -> 
!s.tool()).mapToLong(Step::durationMs).sum();
-        }
-
-        long toolMs() {
-            return 
steps.stream().filter(Step::tool).mapToLong(Step::durationMs).sum();
-        }
-    }
 
     private GenAiSpanView() {
     }
 
-    static boolean isAgentRun(SpanEntry span) {
-        return GenAiOperationName.INVOKE_AGENT.value().equals(operation(span));
-    }
-
-    static boolean isToolCall(SpanEntry span) {
-        return GenAiOperationName.EXECUTE_TOOL.value().equals(operation(span));
-    }
-
     /** The waterfall label of a GenAI span. */
     static String label(SpanEntry span) {
         Map<String, Object> attrs = span.attributes();
-        if (isAgentRun(span)) {
-            String model = model(attrs);
-            return AGENT + " agent " + orElse(text(attrs, 
GenAiAttributes.AGENT_NAME), span.routeId())
+        if (GenAiSpans.isAgentRun(span)) {
+            String model = GenAiSpans.model(attrs);
+            return AGENT + " agent " + orElse(GenAiSpans.text(attrs, 
GenAiAttributes.AGENT_NAME), span.routeId())
                    + (model != null ? " · " + model : "");
         }
-        if (isToolCall(span)) {
-            String arguments = text(attrs, 
GenAiAttributes.TOOL_CALL_ARGUMENTS);
-            return TOOL + " tool " + orElse(text(attrs, 
GenAiAttributes.TOOL_NAME), span.name())
+        if (GenAiSpans.isToolCall(span)) {
+            String arguments = GenAiSpans.text(attrs, 
GenAiAttributes.TOOL_CALL_ARGUMENTS);
+            return TOOL + " tool " + orElse(GenAiSpans.text(attrs, 
GenAiAttributes.TOOL_NAME), span.name())
                    + (arguments != null ? " " + oneLine(arguments, 
MAX_ARGUMENTS) : "");
         }
-        StringBuilder sb = new StringBuilder(MODEL_CALL).append(' 
').append(operation(span));
-        String model = model(attrs);
+        StringBuilder sb = new StringBuilder(MODEL_CALL).append(' 
').append(GenAiSpans.operation(span));
+        String model = GenAiSpans.model(attrs);
         if (model != null) {
             sb.append(' ').append(model);
         }
-        long in = number(attrs, GenAiAttributes.INPUT_TOKENS);
-        long out = number(attrs, GenAiAttributes.OUTPUT_TOKENS);
+        long in = GenAiSpans.number(attrs, GenAiAttributes.INPUT_TOKENS);
+        long out = GenAiSpans.number(attrs, GenAiAttributes.OUTPUT_TOKENS);
         if (in > 0 || out > 0) {
             sb.append(" · 
").append(tokens(in)).append('→').append(tokens(out));
         }
-        String finish = text(attrs, GenAiAttributes.FINISH_REASONS);
+        String finish = GenAiSpans.text(attrs, GenAiAttributes.FINISH_REASONS);
         if (finish != null) {
             sb.append(" · ").append(finish);
         }
@@ -126,56 +80,11 @@ final class GenAiSpanView {
 
     /** The colour of a GenAI span in the waterfall: an agent run, a model 
call or a tool call. */
     static Style style(SpanEntry span, boolean selected) {
-        Style style = isAgentRun(span) ? Theme.label() : isToolCall(span) ? 
Theme.warning() : Theme.success();
+        Style style
+                = GenAiSpans.isAgentRun(span) ? Theme.label() : 
GenAiSpans.isToolCall(span) ? Theme.warning() : Theme.success();
         return selected ? style.bold() : style;
     }
 
-    /** The agent run with its model and tool calls: the GenAI spans whose 
nearest agent run is this one. */
-    static AgentRun agentRun(SpanEntry agent, List<SpanEntry> traceSpans) {
-        Map<String, SpanEntry> byId = new HashMap<>();
-        for (SpanEntry s : traceSpans) {
-            if (s.spanId() != null) {
-                byId.put(s.spanId(), s);
-            }
-        }
-        List<Step> steps = new ArrayList<>();
-        traceSpans.stream()
-                .filter(s -> s != agent && GenAiTranscript.isGenAiSpan(s) && 
!isAgentRun(s))
-                .filter(s -> agent.spanId() != null && 
agent.spanId().equals(nearestAgentRun(s, byId)))
-                .sorted(Comparator.comparingLong(SpanEntry::startEpochNanos))
-                .forEach(s -> steps.add(step(s)));
-        Map<String, Object> attrs = agent.attributes();
-        return new AgentRun(
-                orElse(text(attrs, GenAiAttributes.AGENT_NAME), 
agent.routeId()), model(attrs),
-                orElse(text(attrs, GenAiAttributes.PROVIDER_NAME), text(attrs, 
GenAiAttributes.SYSTEM)),
-                text(attrs, GenAiAttributes.CONVERSATION_ID), 
agent.durationMs(), steps);
-    }
-
-    private static Step step(SpanEntry span) {
-        Map<String, Object> attrs = span.attributes();
-        if (isToolCall(span)) {
-            return new Step(
-                    span, true, orElse(text(attrs, GenAiAttributes.TOOL_NAME), 
span.name()), span.durationMs(),
-                    0, 0, 0, null);
-        }
-        return new Step(
-                span, false, operation(span) + (model(attrs) != null ? " " + 
model(attrs) : ""),
-                span.durationMs(), number(attrs, GenAiAttributes.INPUT_TOKENS),
-                number(attrs, GenAiAttributes.OUTPUT_TOKENS), number(attrs, 
GenAiAttributes.CACHE_READ_INPUT_TOKENS),
-                text(attrs, GenAiAttributes.FINISH_REASONS));
-    }
-
-    private static String nearestAgentRun(SpanEntry span, Map<String, 
SpanEntry> byId) {
-        SpanEntry current = span;
-        for (int hops = 0; hops < MAX_PARENT_HOPS && current != null && 
!current.isRoot(); hops++) {
-            current = byId.get(current.parentSpanId());
-            if (current != null && isAgentRun(current)) {
-                return current.spanId();
-            }
-        }
-        return null;
-    }
-
     /** The lines of the detail panel for an agent run: model, steps, tokens, 
time, and the steps one by one. */
     static List<Line> agentRunLines(AgentRun run) {
         Style muted = Theme.muted();
@@ -202,7 +111,7 @@ final class GenAiSpanView {
                 Span.styled(tokens(run.inputTokens()) + " in / " + 
tokens(run.outputTokens()) + " out / "
                             + tokens(run.cachedTokens()) + " cached",
                         value)));
-        long other = Math.max(0, run.durationMs() - run.modelMs() - 
run.toolMs());
+        long other = run.otherMs();
         lines.add(Line.from(
                 Span.styled(" Time:   ", muted),
                 Span.styled(duration(run.durationMs()), value),
@@ -260,37 +169,7 @@ final class GenAiSpanView {
         return CharWidth.of(line) > max ? CharWidth.substringByWidth(line, max 
- 1) + "…" : line;
     }
 
-    private static String operation(SpanEntry span) {
-        return span != null ? text(span.attributes(), 
GenAiAttributes.OPERATION_NAME) : null;
-    }
-
-    private static String model(Map<String, Object> attrs) {
-        String model = orElse(text(attrs, GenAiAttributes.RESPONSE_MODEL), 
text(attrs, GenAiAttributes.REQUEST_MODEL));
-        return "unknown".equals(model) ? null : model;
-    }
-
     private static String orElse(String value, String fallback) {
         return value != null ? value : fallback;
     }
-
-    private static String text(Map<String, Object> attrs, String key) {
-        Object value = attrs != null ? attrs.get(key) : null;
-        if (value == null) {
-            return null;
-        }
-        String text = value.toString();
-        return text.isBlank() ? null : text;
-    }
-
-    private static long number(Map<String, Object> attrs, String key) {
-        Object value = attrs != null ? attrs.get(key) : null;
-        if (value instanceof Number n) {
-            return n.longValue();
-        }
-        try {
-            return value != null ? Long.parseLong(value.toString()) : 0;
-        } catch (NumberFormatException e) {
-            return 0;
-        }
-    }
 }
diff --git 
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/OllamaMonitor.java
 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/OllamaMonitor.java
index 5899edddbef3..8f443bb51950 100644
--- 
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/OllamaMonitor.java
+++ 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/OllamaMonitor.java
@@ -40,6 +40,8 @@ import java.util.concurrent.atomic.AtomicBoolean;
 import org.apache.camel.component.ai.observability.GenAiAttributes;
 import org.apache.camel.dsl.jbang.core.commands.LlmClient;
 import org.apache.camel.dsl.jbang.core.common.ExternalCommand;
+import org.apache.camel.dsl.jbang.core.common.genai.GenAiSpans;
+import org.apache.camel.dsl.jbang.core.common.genai.SpanEntry;
 import org.apache.camel.util.json.JsonArray;
 import org.apache.camel.util.json.JsonObject;
 import org.apache.camel.util.json.Jsoner;
@@ -645,10 +647,10 @@ final class OllamaMonitor {
         synchronized (lock) {
             for (SpanEntry span : spans) {
                 // agent runs and tool calls are not requests to Ollama 
(observability level detailed)
-                if (!GenAiSpanUsageExtractor.isModelCall(span) || 
span.spanId() == null) {
+                if (!GenAiSpans.isModelCall(span) || span.spanId() == null) {
                     continue;
                 }
-                String system = 
GenAiSpanUsageExtractor.provider(span.attributes());
+                String system = GenAiSpans.provider(span.attributes());
                 if (system == null || 
!system.toLowerCase(Locale.ROOT).contains("ollama")) {
                     continue;
                 }
diff --git 
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/SpansTab.java
 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/SpansTab.java
index ac8254872c89..f6bab48a2a6d 100644
--- 
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/SpansTab.java
+++ 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/SpansTab.java
@@ -52,6 +52,10 @@ import dev.tamboui.widgets.table.Row;
 import dev.tamboui.widgets.table.Table;
 import dev.tamboui.widgets.table.TableState;
 import org.apache.camel.dsl.jbang.core.commands.ai.ProjectOverview;
+import org.apache.camel.dsl.jbang.core.common.genai.GenAiAgentRuns;
+import org.apache.camel.dsl.jbang.core.common.genai.GenAiSpans;
+import org.apache.camel.dsl.jbang.core.common.genai.GenAiTranscript;
+import org.apache.camel.dsl.jbang.core.common.genai.SpanEntry;
 import org.apache.camel.util.json.JsonArray;
 import org.apache.camel.util.json.JsonObject;
 
@@ -570,7 +574,7 @@ class SpansTab extends AbstractTab {
         } else if (!camelSpan) {
             labelStyle = selected ? Theme.notice().bold() : Theme.notice();
             bandStyle = Theme.notice();
-        } else if (GenAiTranscript.isGenAiSpan(node.span)) {
+        } else if (GenAiSpans.isGenAiSpan(node.span)) {
             labelStyle = GenAiSpanView.style(node.span, selected);
             bandStyle = TuiHelper.colorForDuration(node.span.durationMs(), 
minDuration, maxDuration);
         } else {
@@ -634,12 +638,12 @@ class SpansTab extends AbstractTab {
             }
             lines.add(Line.from(ctx));
         }
-        if (GenAiTranscript.isGenAiSpan(span)) {
+        if (GenAiSpans.isGenAiSpan(span)) {
             lines.add(conversationLine(span));
         }
-        if (GenAiSpanView.isAgentRun(span)) {
+        if (GenAiSpans.isAgentRun(span)) {
             List<SpanEntry> trace = spans.get().stream().filter(s -> 
selectedTraceId.equals(s.traceId())).toList();
-            
lines.addAll(GenAiSpanView.agentRunLines(GenAiSpanView.agentRun(span, trace)));
+            
lines.addAll(GenAiSpanView.agentRunLines(GenAiAgentRuns.agentRun(span, trace)));
         }
 
         // Attributes as individual key: value lines
@@ -684,7 +688,7 @@ class SpansTab extends AbstractTab {
             return;
         }
         SpanEntry span = nodes.get(waterfallSelected).span;
-        if (!GenAiTranscript.isGenAiSpan(span)) {
+        if (!GenAiSpans.isGenAiSpan(span)) {
             return;
         }
         List<SpanEntry> trace = spans.get().stream().filter(s -> 
selectedTraceId.equals(s.traceId())).toList();
@@ -725,7 +729,7 @@ class SpansTab extends AbstractTab {
     private boolean selectedSpanIsGenAi() {
         List<WaterfallNode> nodes = renderedNodes;
         return waterfallSelected >= 0 && waterfallSelected < nodes.size()
-                && 
GenAiTranscript.isGenAiSpan(nodes.get(waterfallSelected).span);
+                && GenAiSpans.isGenAiSpan(nodes.get(waterfallSelected).span);
     }
 
     private List<TraceSummary> buildTraceSummaries() {
@@ -923,7 +927,7 @@ class SpansTab extends AbstractTab {
     }
 
     private static String spanLabel(SpanEntry span) {
-        if (GenAiTranscript.isGenAiSpan(span)) {
+        if (GenAiSpans.isGenAiSpan(span)) {
             return GenAiSpanView.label(span);
         }
         String name = span.name();
diff --git 
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/TranscriptOverlay.java
 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/TranscriptOverlay.java
index 9a29e084050c..b0049d955acc 100644
--- 
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/TranscriptOverlay.java
+++ 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/TranscriptOverlay.java
@@ -35,6 +35,7 @@ import dev.tamboui.widgets.block.Borders;
 import dev.tamboui.widgets.block.Title;
 import dev.tamboui.widgets.scrollbar.Scrollbar;
 import dev.tamboui.widgets.scrollbar.ScrollbarState;
+import org.apache.camel.dsl.jbang.core.common.genai.GenAiTranscript;
 
 import static org.apache.camel.dsl.jbang.core.commands.tui.TuiHelper.hint;
 import static org.apache.camel.dsl.jbang.core.commands.tui.TuiHelper.hintLast;
diff --git 
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/AiPanelGenAiUsageTest.java
 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/AiPanelGenAiUsageTest.java
index 17008e72a9ab..338aef5b1a22 100644
--- 
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/AiPanelGenAiUsageTest.java
+++ 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/AiPanelGenAiUsageTest.java
@@ -28,6 +28,7 @@ import dev.tamboui.terminal.Frame;
 import dev.tamboui.tui.event.KeyCode;
 import dev.tamboui.tui.event.KeyEvent;
 import org.apache.camel.component.ai.observability.GenAiAttributes;
+import org.apache.camel.dsl.jbang.core.common.genai.SpanEntry;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
diff --git 
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/GenAiSpanUsageExtractorTest.java
 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/GenAiSpanUsageExtractorTest.java
index fb9b2fc12208..6b2136ff2040 100644
--- 
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/GenAiSpanUsageExtractorTest.java
+++ 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/GenAiSpanUsageExtractorTest.java
@@ -23,6 +23,8 @@ import java.util.Map;
 
 import org.apache.camel.component.ai.observability.GenAiAttributes;
 import org.apache.camel.component.ai.observability.GenAiObservabilityLevel;
+import org.apache.camel.dsl.jbang.core.common.genai.GenAiSpans;
+import org.apache.camel.dsl.jbang.core.common.genai.SpanEntry;
 import org.junit.jupiter.api.Test;
 
 import static org.assertj.core.api.Assertions.assertThat;
@@ -34,9 +36,9 @@ class GenAiSpanUsageExtractorTest {
         SpanEntry genAi = span(Map.of(GenAiAttributes.OPERATION_NAME, "chat"));
         SpanEntry other = span(Map.of("http.method", "GET"));
 
-        assertThat(GenAiSpanUsageExtractor.isGenAiSpan(genAi)).isTrue();
-        assertThat(GenAiSpanUsageExtractor.isGenAiSpan(other)).isFalse();
-        assertThat(GenAiSpanUsageExtractor.isGenAiSpan(null)).isFalse();
+        assertThat(GenAiSpans.isGenAiSpan(genAi)).isTrue();
+        assertThat(GenAiSpans.isGenAiSpan(other)).isFalse();
+        assertThat(GenAiSpans.isGenAiSpan(null)).isFalse();
     }
 
     @Test
@@ -100,19 +102,19 @@ class GenAiSpanUsageExtractorTest {
 
     @Test
     void isModelCallLeavesOutAgentRunsAndToolCalls() {
-        
assertThat(GenAiSpanUsageExtractor.isModelCall(span(Map.of(GenAiAttributes.OPERATION_NAME,
 "chat")))).isTrue();
-        
assertThat(GenAiSpanUsageExtractor.isModelCall(span(Map.of(GenAiAttributes.OPERATION_NAME,
 "embeddings"))))
+        
assertThat(GenAiSpans.isModelCall(span(Map.of(GenAiAttributes.OPERATION_NAME, 
"chat")))).isTrue();
+        
assertThat(GenAiSpans.isModelCall(span(Map.of(GenAiAttributes.OPERATION_NAME, 
"embeddings"))))
                 .isTrue();
         // an operation recorded by an AI framework, unknown to the Camel 
observability, still is a model call
-        
assertThat(GenAiSpanUsageExtractor.isModelCall(span(Map.of(GenAiAttributes.OPERATION_NAME,
 "text_completion"))))
+        
assertThat(GenAiSpans.isModelCall(span(Map.of(GenAiAttributes.OPERATION_NAME, 
"text_completion"))))
                 .isTrue();
-        
assertThat(GenAiSpanUsageExtractor.isModelCall(span(Map.of(GenAiAttributes.OPERATION_NAME,
 "invoke_agent"))))
+        
assertThat(GenAiSpans.isModelCall(span(Map.of(GenAiAttributes.OPERATION_NAME, 
"invoke_agent"))))
                 .isFalse();
-        
assertThat(GenAiSpanUsageExtractor.isModelCall(span(Map.of(GenAiAttributes.OPERATION_NAME,
 "execute_tool"))))
+        
assertThat(GenAiSpans.isModelCall(span(Map.of(GenAiAttributes.OPERATION_NAME, 
"execute_tool"))))
                 .isFalse();
-        
assertThat(GenAiSpanUsageExtractor.isModelCall(span(Map.of(GenAiAttributes.OPERATION_NAME,
 "create_agent"))))
+        
assertThat(GenAiSpans.isModelCall(span(Map.of(GenAiAttributes.OPERATION_NAME, 
"create_agent"))))
                 .isFalse();
-        
assertThat(GenAiSpanUsageExtractor.isModelCall(span(Map.of("http.method", 
"GET")))).isFalse();
+        assertThat(GenAiSpans.isModelCall(span(Map.of("http.method", 
"GET")))).isFalse();
     }
 
     @Test
@@ -156,7 +158,7 @@ class GenAiSpanUsageExtractorTest {
                 GenAiAttributes.PROVIDER_NAME, "openai",
                 GenAiAttributes.REQUEST_MODEL, "gpt-4.1")));
 
-        GenAiSpanUsageExtractor.GenAiActivity activity = 
GenAiSpanUsageExtractor.activity(spans, Instant.EPOCH);
+        GenAiSpans.GenAiActivity activity = GenAiSpans.activity(spans, 
Instant.EPOCH);
 
         assertThat(activity.agentRuns()).isEqualTo(1);
         assertThat(activity.agentModelCalls()).isEqualTo(2);
@@ -179,20 +181,20 @@ class GenAiSpanUsageExtractorTest {
                 "trace-1", "s3", "", "chat", "CLIENT", "OK", 0, 0, 10, null, 
null, "dev.langchain4j",
                 Map.of(GenAiAttributes.OPERATION_NAME, "chat", 
GenAiAttributes.PROVIDER_NAME, "openai"));
 
-        assertThat(GenAiSpanUsageExtractor.activity(List.of(basic), 
Instant.EPOCH).level())
+        assertThat(GenAiSpans.activity(List.of(basic), Instant.EPOCH).level())
                 .isEqualTo(GenAiObservabilityLevel.BASIC);
-        assertThat(GenAiSpanUsageExtractor.activity(List.of(basic, full), 
Instant.EPOCH).level())
+        assertThat(GenAiSpans.activity(List.of(basic, full), 
Instant.EPOCH).level())
                 .isEqualTo(GenAiObservabilityLevel.FULL);
         // the spans of an AI framework do not tell the level of the Camel 
observability
-        assertThat(GenAiSpanUsageExtractor.activity(List.of(framework), 
Instant.EPOCH).level()).isNull();
-        assertThat(GenAiSpanUsageExtractor.activity(List.of(), 
Instant.EPOCH).level()).isNull();
+        assertThat(GenAiSpans.activity(List.of(framework), 
Instant.EPOCH).level()).isNull();
+        assertThat(GenAiSpans.activity(List.of(), 
Instant.EPOCH).level()).isNull();
     }
 
     @Test
     void activityLeavesOutSpansBeforeTheReset() {
         Instant afterTheRun = Instant.parse("2026-08-13T12:00:01Z");
 
-        GenAiSpanUsageExtractor.GenAiActivity activity = 
GenAiSpanUsageExtractor.activity(agentRun(), afterTheRun);
+        GenAiSpans.GenAiActivity activity = GenAiSpans.activity(agentRun(), 
afterTheRun);
 
         assertThat(activity.agentRuns()).isZero();
         assertThat(activity.toolCalls()).isZero();
diff --git 
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/GenAiSpanViewTest.java
 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/GenAiSpanViewTest.java
index c55dc7aa9e63..a76ccd11441d 100644
--- 
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/GenAiSpanViewTest.java
+++ 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/GenAiSpanViewTest.java
@@ -26,8 +26,10 @@ import dev.tamboui.text.CharWidth;
 import dev.tamboui.text.Line;
 import dev.tamboui.text.Span;
 import org.apache.camel.component.ai.observability.GenAiAttributes;
-import org.apache.camel.dsl.jbang.core.commands.tui.GenAiSpanView.AgentRun;
-import org.apache.camel.dsl.jbang.core.commands.tui.GenAiSpanView.Step;
+import org.apache.camel.dsl.jbang.core.common.genai.GenAiAgentRuns;
+import org.apache.camel.dsl.jbang.core.common.genai.GenAiAgentRuns.AgentRun;
+import org.apache.camel.dsl.jbang.core.common.genai.GenAiAgentRuns.Step;
+import org.apache.camel.dsl.jbang.core.common.genai.SpanEntry;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
@@ -72,7 +74,7 @@ class GenAiSpanViewTest {
 
     @Test
     void agentRunHasItsStepsInOrder() {
-        AgentRun run = GenAiSpanView.agentRun(agent(), trace());
+        AgentRun run = GenAiAgentRuns.agentRun(agent(), trace());
 
         assertThat(run.agentName()).isEqualTo("support-agent");
         assertThat(run.model()).isEqualTo("llama3.2");
@@ -96,13 +98,13 @@ class GenAiSpanViewTest {
         spans.add(inner);
         spans.add(innerChat);
 
-        assertThat(GenAiSpanView.agentRun(agent(), spans).steps()).hasSize(3);
-        assertThat(GenAiSpanView.agentRun(inner, 
spans).steps()).extracting(Step::span).containsExactly(innerChat);
+        assertThat(GenAiAgentRuns.agentRun(agent(), spans).steps()).hasSize(3);
+        assertThat(GenAiAgentRuns.agentRun(inner, 
spans).steps()).extracting(Step::span).containsExactly(innerChat);
     }
 
     @Test
     void agentRunLinesShowStepsTokensAndTime() {
-        String text = 
text(GenAiSpanView.agentRunLines(GenAiSpanView.agentRun(agent(), trace())));
+        String text = 
text(GenAiSpanView.agentRunLines(GenAiAgentRuns.agentRun(agent(), trace())));
 
         assertThat(text)
                 .contains("Agent:  support-agent  Model: llama3.2 (openai)  
Conversation id: conv-1")
diff --git 
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/OllamaMonitorTest.java
 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/OllamaMonitorTest.java
index 6489b4c76283..3b7c36757432 100644
--- 
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/OllamaMonitorTest.java
+++ 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/OllamaMonitorTest.java
@@ -36,6 +36,7 @@ import 
org.apache.camel.dsl.jbang.core.commands.tui.OllamaMonitor.RunnerInfo;
 import org.apache.camel.dsl.jbang.core.commands.tui.OllamaMonitor.ServerInfo;
 import org.apache.camel.dsl.jbang.core.commands.tui.OllamaMonitor.SlotState;
 import org.apache.camel.dsl.jbang.core.commands.tui.OllamaMonitor.Snapshot;
+import org.apache.camel.dsl.jbang.core.common.genai.SpanEntry;
 import org.apache.camel.util.json.JsonArray;
 import org.apache.camel.util.json.JsonObject;
 import org.junit.jupiter.api.Test;
diff --git 
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/OllamaTabRenderTest.java
 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/OllamaTabRenderTest.java
index fe465fa141f8..df2e726c9d1c 100644
--- 
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/OllamaTabRenderTest.java
+++ 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/OllamaTabRenderTest.java
@@ -37,6 +37,7 @@ import 
org.apache.camel.dsl.jbang.core.commands.tui.OllamaMonitor.RequestSource;
 import org.apache.camel.dsl.jbang.core.commands.tui.OllamaMonitor.RunnerInfo;
 import org.apache.camel.dsl.jbang.core.commands.tui.OllamaMonitor.ServerInfo;
 import org.apache.camel.dsl.jbang.core.commands.tui.OllamaMonitor.SlotState;
+import org.apache.camel.dsl.jbang.core.common.genai.SpanEntry;
 import org.apache.camel.util.json.JsonArray;
 import org.apache.camel.util.json.JsonObject;
 import org.junit.jupiter.api.BeforeEach;
diff --git 
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/SourceSizeTest.java
 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/SourceSizeTest.java
index 4b3ebcfd243e..ab08a284f92a 100644
--- 
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/SourceSizeTest.java
+++ 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/SourceSizeTest.java
@@ -56,7 +56,7 @@ class SourceSizeTest {
 
     /** The files and the methods (class.method) over the limits, and the most 
lines each may have. */
     private static final String OVER_THE_LIMITS = """
-            AiPanel.java 3070
+            AiPanel.java 3071
             AiPanel.runAgentLoop 156
             CamelMonitor.java 2632
             DiagramSupport.java 2360
diff --git 
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/SpansTabRenderTest.java
 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/SpansTabRenderTest.java
index ba6cb502ba21..bdabb1d3b464 100644
--- 
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/SpansTabRenderTest.java
+++ 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/SpansTabRenderTest.java
@@ -31,6 +31,7 @@ import dev.tamboui.tui.event.KeyEvent;
 import dev.tamboui.tui.event.KeyModifiers;
 import org.apache.camel.component.ai.observability.GenAiAttributes;
 import org.apache.camel.component.ai.observability.GenAiMessages;
+import org.apache.camel.dsl.jbang.core.common.genai.SpanEntry;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 

Reply via email to