davsclaus commented on code in PR #30525:
URL: https://github.com/apache/camel/pull/30525#discussion_r4651106324
##########
dsl/camel-jbang/camel-jbang-mcp/src/main/java/org/apache/camel/dsl/jbang/core/commands/mcp/AiTraceTools.java:
##########
@@ -109,6 +117,48 @@ public AiTraceResult camel_runtime_ai_trace(
}
}
+ @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) {
+ return List.of();
+ }
Review Comment:
Thanks, done in ea09cad1e428: `loadSpans()` now logs the reason at debug
before it returns no spans.
_Claude Code on behalf of Claus Ibsen_
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]