luigidemasi commented on code in PR #27714: URL: https://github.com/apache/camel/pull/27714#discussion_r4246140125
########## 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 + * components is this contract. + * + * @since 4.23 + */ +public interface AiEvent extends CamelEvent.ExchangeEvent { Review Comment: Please keep the root independent of a live Exchange: `AiEvent extends CamelEvent`, with Exchange access on the exchange-backed subinterfaces. This is needed for an existing Semantic API, not just a future monitoring feature: [SemanticLanguage.evaluate](https://github.com/apache/camel/blob/044b4b4c29c6cbdb51af08ec900d9125a993a68b/components/camel-ai/camel-semantic/src/main/java/org/apache/camel/language/semantic/SemanticLanguage.java#L154) calls `audit.begin(null, ...)`, and [SemanticObserver](https://github.com/apache/camel/blob/044b4b4c29c6cbdb51af08ec900d9125a993a68b/components/camel-ai/camel-semantic/src/main/java/org/apache/camel/semantic/SemanticObserver.java#L19) receives bounded snapshots rather than exchanges. A population-level drift signal likewise has no single Exchange. A mandatory `getExchange()` on the root would retain the same limitation even without the ExchangeEvent inheritance. A small change that preserves the current tool/loop contracts: - Make `AiEvent` extend `CamelEvent`, retaining `getProvider()` and the `Type.Ai` default. - Add `ExchangeAiEvent extends AiEvent, CamelEvent.ExchangeEvent` (or directly extend both interfaces on each existing subtype). - Move the four existing tool/loop subinterfaces and `AbstractOpenAIExchangeEvent` onto that exchange-backed contract, retaining their current members and accessors. - Add a test dispatching an AiEvent without an Exchange through the new helper. Semantic can then implement its own snapshot events without constructing a fake Exchange, weakening ExchangeEvent to allow null, or moving semantic record/result types into core. This split deliberately leaves the PR's proposed ExchangeEvent behavior on the four existing events; the listener compatibility work already requested still applies. _AI-assisted review generated by Codex on behalf of Luigi De Masi (@luigidemasi)._ ########## 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 + * components is this contract. + * + * @since 4.23 + */ +public interface AiEvent extends CamelEvent.ExchangeEvent { + + /** + * The AI provider the event originates from, e.g. {@code openai} or {@code ai-tool}. Intended as a low-cardinality + * label for metrics and spans. Review Comment: **Optional:** clarify that this identifies a stable publishing integration/provider family. The current `ai-tool` value already has that meaning; it is not an inference vendor. That lets a Semantic bridge consistently use `semantic`, while its domain payload retains the actual adapter provider, expert and model identity. It also gives route-decision and aggregate events a truthful label. Suggested wording, if that convention is intended: ```suggestion * The integration or provider family publishing the event, e.g. {@code openai}, {@code ai-tool}, or * {@code semantic}. Intended as a stable, low-cardinality label for metrics and spans; not an expert instance, * model revision, invocation ID, or an indication that the event necessarily involved inference. ``` _AI-assisted review generated by Codex on behalf of Luigi De Masi (@luigidemasi)._ -- 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]
