gnodet-bot commented on code in PR #27714:
URL: https://github.com/apache/camel/pull/27714#discussion_r4245954129


##########
core/camel-api/src/main/java/org/apache/camel/ai/AiEvent.java:
##########
@@ -0,0 +1,110 @@
+/*
+ * 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.ai;
+
+import org.apache.camel.spi.CamelEvent;
+import org.jspecify.annotations.Nullable;
+
+/**
+ * Common contract for events fired by Camel AI components (tool calls, 
agentic loops, ...).
+ * <p>
+ * An {@code AiEvent} is a {@link CamelEvent.ExchangeEvent} of {@link 
CamelEvent.Type#Ai}: it carries the exchange it
+ * relates to (so it can be correlated by route id or exchange id) and is 
typed {@code Ai} rather than {@code Custom},
+ * so an {@link org.apache.camel.spi.EventNotifier} can recognise AI activity 
— and route it to metrics, tracing or a
+ * GenAI-observability backend — by type and by these sub-interfaces, without 
depending on any AI component or doing an
+ * {@code instanceof} against each component's own event class.
+ * <p>
+ * Concrete event classes live in the AI components (they implement these 
interfaces); the only thing shared across

Review Comment:
   ⚠️ **Design decision reversal — implicit side-effects to audit**
   
   The original `AiToolAuthorizationDeniedEvent` Javadoc (visible in the 
`camel-4.23.0` tag) said _"deliberately not a `CamelEvent.ExchangeEvent`, so it 
does not pollute generic exchange lifecycle metrics"_. This PR inverts that 
decision.
   
   The consequence is that all AI events now flow through code that branches on 
`instanceof ExchangeEvent`:
   
   - **`EventConsole`** routes them into the `exchangeEvents` ring buffer 
alongside regular exchange lifecycle events.
   - **`DefaultDebugger`** enables itself for `instanceof ExchangeEvent` — AI 
events trigger that path.
   - **`CamelEventJsonSupport`** serialises the `exchange` payload for 
`instanceof ExchangeEvent` events.
   
   If the goal is just to inherit `getSource()` / `getExchange()` defaults, 
consider keeping `AiEvent extends CamelEvent` and adding an explicit `Exchange 
getExchange()` method:
   
   ```suggestion
   public interface AiEvent extends CamelEvent {
   
       /** The exchange the event relates to (for route-id / exchange-id 
correlation). */
       Exchange getExchange();
   
   ```
   
   Either way, please confirm the `EventConsole` / `DefaultDebugger` / 
`CamelEventJsonSupport` side-effects are intentional and add a note to the 
upgrade guide.



##########
core/camel-api/src/main/java/org/apache/camel/ai/AiEvent.java:
##########
@@ -0,0 +1,110 @@
+/*
+ * 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.ai;
+
+import org.apache.camel.spi.CamelEvent;
+import org.jspecify.annotations.Nullable;
+
+/**
+ * Common contract for events fired by Camel AI components (tool calls, 
agentic loops, ...).
+ * <p>
+ * An {@code AiEvent} is a {@link CamelEvent.ExchangeEvent} of {@link 
CamelEvent.Type#Ai}: it carries the exchange it
+ * relates to (so it can be correlated by route id or exchange id) and is 
typed {@code Ai} rather than {@code Custom},
+ * so an {@link org.apache.camel.spi.EventNotifier} can recognise AI activity 
— and route it to metrics, tracing or a
+ * GenAI-observability backend — by type and by these sub-interfaces, without 
depending on any AI component or doing an
+ * {@code instanceof} against each component's own event class.

Review Comment:
   💡 **`@since` tag is incorrect — `AiEvent` does not exist in 4.23.0**
   
   The `camel-4.23.0` tag was created 2026-10-11 and does not contain this 
interface. Should be `@since 4.24` (same as the sub-interfaces and the 
`Type.Ai` enum value).
   
   ```suggestion
    * @since 4.24
   ```



##########
core/camel-api/src/main/java/org/apache/camel/spi/CamelEvent.java:
##########
@@ -81,6 +81,13 @@ enum Type {
         StepStarted,
         StepCompleted,
         StepFailed,
+        /**
+         * Events fired by Camel AI components (tool calls, agentic loops, 
...); see
+         * {@link org.apache.camel.ai.AiEvent}.
+         *
+         * @since 4.24
+         */
+        Ai,

Review Comment:
   ℹ️ **`Custom.ordinal()` changes — worth a note in the upgrade guide**
   
   Inserting `Ai` before `Custom` shifts `Custom.ordinal()` from its previous 
value (87) to 90. The upgrade guide mentions type-string matching, but not 
ordinal. Worth a brief sentence for users who serialise the enum as an integer 
(e.g. to a database column or a protocol buffer).



##########
components/camel-ai/camel-ai-tool/src/test/java/org/apache/camel/component/ai/tool/AiToolAuthorizationDeniedEventTest.java:
##########
@@ -140,7 +140,7 @@ void firesAnEventWhenThePolicyThrows() {
         // ...and the denial is now observable as a single event
         assertThat(events).hasSize(1);
         AiToolAuthorizationDeniedEvent event = events.get(0);
-        assertThat(event.getType()).isEqualTo(CamelEvent.Type.Custom);
+        assertThat(event.getType()).isEqualTo(CamelEvent.Type.Ai);
         assertThat(event.getToolName()).isEqualTo("guarded");
         assertThat(event.getExchange()).isSameAs(exchange);

Review Comment:
   💡 **Missing `getProvider()` assertion**
   
   The event now implements `AiEvent.ToolCallDeniedEvent.getProvider()`, which 
returns `"ai-tool"`. Consider asserting it here to guard against regressions:
   
   ```suggestion
           assertThat(event.getType()).isEqualTo(CamelEvent.Type.Ai);
           assertThat(event.getProvider()).isEqualTo("ai-tool");
           assertThat(event.getToolName()).isEqualTo("guarded");
   ```



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