k-krawczyk opened a new pull request, #26707:
URL: https://github.com/apache/camel/pull/26707

   `openai:responses` has run a tool loop since CAMEL-24670, but without the 
agentic bookkeeping `chat-completion` does: the token headers described only 
the last model call, `maxAgenticTokens` was not enforced, and neither the trace 
nor the lifecycle events were produced. CAMEL-24721 asks for parity.
   
   ### What the loop does now
   
   * Sets `CamelOpenAIAgenticPromptTokens`, 
`CamelOpenAIAgenticCompletionTokens` and `CamelOpenAIAgenticTotalTokens` right 
after every model call, so they are readable even when the exchange ends with 
an exception. The per-call `CamelOpenAIPromptTokens` and friends keep 
describing the last response.
   * Refuses the next model call once `maxAgenticTokens` is spent, with the 
message `chat-completion` uses. The rule is the same one: an answer that goes 
over the budget is still returned, because no further spend follows it.
   * Records one `CamelOpenAIAgenticTrace` entry per model call, with the tool 
calls of that iteration - name, truncated arguments and result, duration and 
success flag.
   * Emits `OpenAIAgenticLoopStartedEvent`, 
`OpenAIAgenticToolCallExecutedEvent` and `OpenAIAgenticLoopCompletedEvent`. The 
stop reason is the finish status of the response, or `return_direct`, 
`token_budget_exceeded`, `max_iterations_exceeded`.
   
   ### Shared code
   
   `OpenAIAgenticObservability` needed no change: the loop already converts the 
function calls of a response into chat tool calls for the executor, which is 
what the trace takes. `OpenAIAgenticTokenTracker` gains an overload for 
`ResponseUsage`, which counts the same tokens under the input and output names, 
plus `setHeaders` and `exceedsBudget` - the two helpers `OpenAIProducer` kept 
privately. Both producers now share them, so the header and budget logic exists 
once.
   
   ### Tests
   
   `OpenAIResponsesAgenticTest`, 7 tests over `OpenAIMock`, with route tools 
rather than mocked MCP clients: cumulative headers across a two-call loop, the 
budget refusing the next call, the budget accumulating across iterations, the 
answer over the budget still returning, the trace, the lifecycle events, and 
the stop reason for the budget and for a tool that returns directly. Every one 
of them fails against the loop as it stood before this change - I reverted the 
producer and reran to check.
   
   328 unit tests of `camel-openai` pass and `-Psourcecheck` is clean.
   
   ### Docs
   
   `openai-responses.adoc` said `maxAgenticTokens`, the trace and the events 
were `chat-completion` only; that sentence is replaced by what the loop 
reports, including the note that the Responses API counts input and output 
tokens where the headers say prompt and completion. The agentic loop section of 
`openai-mcp.adoc` now points at the responses operation. The catalog copies are 
updated.
   
   _Reported by Claude Code on behalf of Karol Krawczyk_
   


-- 
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