davsclaus opened a new pull request, #30521:
URL: https://github.com/apache/camel/pull/30521

   _Claude Code on behalf of Claus Ibsen_
   
   ## What
   
   First part of 
[CAMEL-27135](https://issues.apache.org/jira/browse/CAMEL-27135), the follow-up 
to CAMEL-27131 (#30291).
   
   At GenAI observability level `detailed`, an agent run is an `invoke_agent` 
span, with a `chat` span per model call and an `execute_tool` span per tool 
call. The camel-jbang AI usage view (Ctrl+U in the AI panel) and the Ollama 
view counted every span with `gen_ai.operation.name` as a model call. That had 
three effects:
   
   - agent runs showed as calls with 0 tokens
   - tool calls showed as calls with 0 tokens, with the span name as the model 
and `unknown` as the provider
   - the AI time counted each run's whole duration on top of its model calls
   
   This PR:
   
   - counts only model calls. It leaves out `invoke_agent`, `execute_tool` and 
`create_agent`; an operation from an AI framework that Camel doesn't know still 
counts as a call.
   - falls back to `gen_ai.provider.name` for the provider.
   - adds a CACHED column and a cached total, from 
`gen_ai.usage.cache_read.input_tokens`.
   - adds a summary line with the agent runs, their model and tool calls, and 
the level the spans were recorded at. The level is not exported with the spans, 
so it is worked out from the attributes each level adds. At level `basic`, 
where agent runs and tool calls are not traced, the line says how to see them.
   - moves `AiUsageEntry` and `AiUsageSource` out of `AiPanel`, and the model 
table out of `AiUsageStats.render`, so both stay under the limits of 
`SourceSizeTest`.
   
   The next PRs of CAMEL-27135 show the messages as a conversation and group 
the agent runs in the Spans tab.
   
   ## Tried live
   
   Two integrations ran, each a camel-openai agent on Ollama (`llama3.2`) with 
one `ai-tool` route tool, one at `camel.aiObservability.level=detailed` and one 
at `basic`.
   
   Before (main), at `detailed`, after 19 agent runs:
   
   | Model | Reqs | Input | Output |
   |---|---|---|---|
   | `[route:support-agent] llama3.2 (openai)` | 57 | 6.4k | 543 |
   | `[route:support-agent] execute_tool lookupOrder (unknown)` | 19 | 0 | 0 |
   
   That is 76 requests and 20.3s of AI time. The 57 is 38 model calls plus the 
19 agent runs.
   
   After, at `detailed`, 20 runs: 40 model calls, 20 tool calls, 10.4s of AI 
time, and the cached tokens Ollama reports:
   
   ![AI usage view at level 
detailed](https://raw.githubusercontent.com/apache/camel/CAMEL-27135-genai-model-calls/docs/user-manual/modules/ROOT/images/jbang/camel-tui-ai-usage-agent-runs.png)
   
   At `basic` the line reads `GenAI level: basic   agent runs and tool calls 
are not traced; camel.aiObservability.level=detailed adds them`.
   
   ## Tests
   
   - `GenAiSpanUsageExtractorTest`: model calls only, provider fallback, cached 
tokens, agent-run counts, level detection, the reset
   - `AiPanelGenAiUsageTest`: the view and `/usage` for an agent run, and the 
hint at level `basic`
   - `OllamaMonitorTest`: agent-run and tool spans are not Ollama requests
   - `camel-jbang-plugin-tui`: all 2646 tests pass
   
   The doc page `camel-jbang-tui-ai.adoc` describes the new line and the 
column, with the screenshot.
   
   🤖 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]

Reply via email to