davsclaus opened a new pull request, #30539: URL: https://github.com/apache/camel/pull/30539
_Claude Code on behalf of Claus Ibsen_ ## What [CAMEL-27313](https://issues.apache.org/jira/browse/CAMEL-27313): a `genai` dev console in `camel-ai-observability` that lists the GenAI calls of the running application: - the totals since start: the model calls per provider and model (calls, failed calls, tokens in, out and cached, time), the agent runs and the tool calls - the newest top-level calls (agent runs, and model calls outside a run), newest first, each agent run with its model calls and tool calls in the order they started - the observability level in use Today the Camel TUI and the MCP server (#30525) work this out from the OpenTelemetry span dump. That needs `--observe`, guesses the level from the attributes, and loses older runs when route spans push them out of the ring buffer. The console gives every client the same JSON, and Kaoto or other tools that read the dev console can use it too. ## How - **No tracer needed:** `GenAiRecorder` records from the same `GenAiObservation` calls the producers already make, next to the spans and the metrics. It records only while the dev console is enabled (`camel.main.devConsoleEnabled`, which the dev profile turns on), so production is unchanged. When neither a tracer nor metrics are present and the dev console is off, `start()` still returns the no-op observation. - **Nesting:** a call goes under `GenAiObservationContext.parent()`, as with langchain4j-agent. Otherwise it goes under the agent run or tool call open on the exchange. The recorder keeps its own stack on the exchange, the way the camel-telemetry span stack does, so the model calls of a camel-openai agent run nest too, as do calls on the exchange copies made for tool calls. - **Bounded:** the console keeps the newest 50 top-level calls and 200 steps per call. The totals still count every call. - **Content:** messages, system instructions, tool definitions and tool arguments and results are only recorded at level `full`, capped at `camel.aiObservability.contentMaxLength` as on the spans. They are only in the answer when asked for with `content=true`, or for one call with `id`, along with the run's question (the first user message) and its answer (the last assistant message). - **Flat steps:** the steps are one list with a `parentId`. Besides being simpler for clients, this avoids a recursive record in the `Response` schema (the dev console generator would recurse forever on one). - **Text output:** the text answer is a short summary of the same data. ## Tried live I ran a camel-openai agent with an `ai-tool` route on Ollama (llama3.2), at level `full`, with `camel run --console`, without `--observe` and so without a tracer. Text answer from `curl http://localhost:8080/q/dev/genai?content=true`: ``` GenAI (level: full) Model calls: 4, agent runs: 2, tool calls: 2, errors: 0 Tokens: in 676 (cached 672), out 57 Models: openai/llama3.2: 4 calls (0 failed), in 676 (cached 672), out 57, 1122 ms Calls (newest first): #5 invoke_agent support-agent 406 ms, in 338 out 28, stop question: What is the status of order A-17? Use the lookupOrder tool, then answer in one sentence. #6 chat llama3.2 253 ms, in 196 out 15, tool_calls #7 execute_tool lookupOrder 1 ms #8 chat llama3.2 149 ms, in 142 out 13, stop answer: The status of order A-17 is DELIVERED. ``` The JSON answer carries the same calls, with ids, `parentId`, route, exchange, tool call ids and timings. ## Tests `GenAiDevConsoleTest`, 8 tests: - the console resolves by name - a model call is recorded without a tracer - an agent run lists its steps in order, both through `parent()` and through the exchange stack (camel-openai style, with a model call inside a tool call) - content appears only at level `full` and only when asked - the buffer keeps the newest calls while the totals count them all - nothing is recorded with the dev console off - the text answer All 59 tests of the module pass. The catalog (`dev-consoles.properties`, `dev-consoles/genai.json`, `dev-consoles-openapi.json`) and the doc copy are regenerated. ## Next A follow-up PR makes the Camel CLI read this console: a `genai` action in the CLI connector, then the TUI AI usage view and the MCP server tools of #30525 on top of it. There is no fallback to the span dump; this is for new Camel versions. 🤖 Generated with [Claude Code](https://claude.com/claude-code) -- 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]
