[
https://issues.apache.org/jira/browse/CAMEL-27912?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Jiří Ondrušek updated CAMEL-27912:
----------------------------------
Description:
h3. Problem
LangChain4j guardrails are Java classes. In Camel they can only be attached by
class (`AgentConfiguration.withInputGuardrailClasses` /
`withOutputGuardrailClasses`); there is no way to write a guardrail as a route,
in the Java DSL or in YAML.
h3. Proposal
A new consumer component
`ai-guardrail:<name>?type=input|output&tags=..&order=..&timeout=..`: the route
is the guardrail, selected by tag like `ai-tool`, and a `guardrailTags` option
on `langchain4j-agent` that attaches the matching guardrails to an agent
(adapters `CamelRouteInputGuardrail` / `CamelRouteOutputGuardrail` in
`camel-langchain4j-agent-api`).
* The body is the text to check; type, name, memory id, user message and
invocation parameters are exchange properties.
* Outcome header `CamelAiGuardrailOutcome`: none or `success` passes, `rewrite`
(explicit only, body = new text), `failure`, `fatal`.
* Fail closed: a route exception, timeout, rejection, blank or unknown outcome,
rollback-only exchange, or a handled exception without an explicit outcome is
fatal. A stopped route rejects.
* `guardrailTags` attaches only the guardrail types a tag has routes for; a tag
with no route fails startup; the agent logs one line per tag.
* `configuration=` bean, an `AiGuardrailEvent` and JMX counters, like ai-tool.
Documentation with Java, YAML and XML examples, pitfalls, and the tool-result
prompt-injection risk (tool-level guardrails are out of scope).
h3. Follow-ups
Retry and reprompt outcomes (output only), an `ai-guardrail-source` Kamelet in
camel-kamelets, and a Camel Quarkus extension with an `@CamelGuardrails` bridge
for `@RegisterAiService`.
was:
h3. Problem
LangChain4j guardrails are Java classes. In Camel they can only be attached by
class (`AgentConfiguration.withInputGuardrailClasses` /
`withOutputGuardrailClasses`); there is no way to write a guardrail as a route,
in the Java DSL or in YAML.
h3. Proposal
A new consumer component
`ai-guardrail:<name>?type=input|output&tags=..&order=..&timeout=..`: the route
is the guardrail, selected by tag like `ai-tool`. Two adapter classes in
`camel-langchain4j-agent-api` (`CamelRouteInputGuardrail`,
`CamelRouteOutputGuardrail`) run the routes for LangChain4j.
* The body is the text to check; type, name, memory id, user message and
invocation parameters are exchange properties.
* Outcome header `CamelAiGuardrailOutcome`: none or `success` passes, `rewrite`
(explicit only, body = new text), `failure`, `fatal`.
* Fail closed: a route exception, timeout, rejection, blank or unknown outcome,
rollback-only exchange, or a handled exception without an explicit outcome is
fatal. A tag needs a route of the called type; a stopped route rejects.
* The documentation lists the pitfalls and the tool-result prompt-injection
risk (tool-level guardrails are out of scope).
h3. Follow-ups
A `guardrailTags` option on `langchain4j-agent`, retry and reprompt outcomes,
and a Camel Quarkus bridge for `@RegisterAiService`.
> camel-ai-guardrail: use Camel routes as LangChain4j guardrails
> --------------------------------------------------------------
>
> Key: CAMEL-27912
> URL: https://issues.apache.org/jira/browse/CAMEL-27912
> Project: Camel
> Issue Type: New Feature
> Components: camel-ai
> Reporter: Jiří Ondrušek
> Assignee: Jiří Ondrušek
> Priority: Major
>
> h3. Problem
> LangChain4j guardrails are Java classes. In Camel they can only be attached
> by class (`AgentConfiguration.withInputGuardrailClasses` /
> `withOutputGuardrailClasses`); there is no way to write a guardrail as a
> route, in the Java DSL or in YAML.
> h3. Proposal
> A new consumer component
> `ai-guardrail:<name>?type=input|output&tags=..&order=..&timeout=..`: the
> route is the guardrail, selected by tag like `ai-tool`, and a `guardrailTags`
> option on `langchain4j-agent` that attaches the matching guardrails to an
> agent (adapters `CamelRouteInputGuardrail` / `CamelRouteOutputGuardrail` in
> `camel-langchain4j-agent-api`).
> * The body is the text to check; type, name, memory id, user message and
> invocation parameters are exchange properties.
> * Outcome header `CamelAiGuardrailOutcome`: none or `success` passes,
> `rewrite` (explicit only, body = new text), `failure`, `fatal`.
> * Fail closed: a route exception, timeout, rejection, blank or unknown
> outcome, rollback-only exchange, or a handled exception without an explicit
> outcome is fatal. A stopped route rejects.
> * `guardrailTags` attaches only the guardrail types a tag has routes for; a
> tag with no route fails startup; the agent logs one line per tag.
> * `configuration=` bean, an `AiGuardrailEvent` and JMX counters, like
> ai-tool. Documentation with Java, YAML and XML examples, pitfalls, and the
> tool-result prompt-injection risk (tool-level guardrails are out of scope).
> h3. Follow-ups
> Retry and reprompt outcomes (output only), an `ai-guardrail-source` Kamelet
> in camel-kamelets, and a Camel Quarkus extension with an `@CamelGuardrails`
> bridge for `@RegisterAiService`.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)