Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
4b3ef30
feat(agent-gateway): authorize tools from trusted identities
BobSong-dev Oct 18, 2026
6788e7b
feat(agent-gateway): authorize tools from trusted identities
BobSong-dev Oct 19, 2026
19eea6f
feat(agent-gateway): unify request context and terminal observation
BobSong-dev Oct 19, 2026
3c09a39
merge: reconcile master retry policy with agent observation
BobSong-dev Oct 20, 2026
dd6d878
merge: reconcile agent context tests with latest master
BobSong-dev Oct 20, 2026
f4392ce
feat(agent-gateway): add runtime governance observability
BobSong-dev Oct 21, 2026
5d97d96
Merge remote-tracking branch 'origin/master' into integration/agent-g…
BobSong-dev Oct 21, 2026
e451ec6
Merge remote-tracking branch 'origin/master' into feat/agent-gateway-…
BobSong-dev Oct 23, 2026
8aba05c
feat(agent-gateway): add unified invocation auditing
BobSong-dev Oct 23, 2026
4721203
Merge remote-tracking branch 'origin/master' into feat/agent-gateway-…
BobSong-dev Oct 23, 2026
19d83df
feat(agent-gateway): add bounded mcp resource admission
BobSong-dev Oct 24, 2026
4a9544d
merge: reconcile agent observation with latest master
BobSong-dev Oct 25, 2026
2324714
ci: re-run agent gateway checks
BobSong-dev Oct 25, 2026
b015555
test(agent-gateway): locate migration null fixture structurally
BobSong-dev Oct 25, 2026
c343fb4
Merge remote-tracking branch 'origin/master' into feat/agent-gateway-…
BobSong-dev Oct 25, 2026
423278e
test(agent-gateway): harden migration null fixture
BobSong-dev Oct 26, 2026
4736952
test(agent-gateway): harden migration null fixture
BobSong-dev Oct 26, 2026
1664140
fix(agent-gateway): address observation and ordering review
BobSong-dev Oct 26, 2026
be45a5f
Merge remote-tracking branch 'fork/integration/agent-gateway-p003' in…
BobSong-dev Oct 26, 2026
020fd64
Merge remote-tracking branch 'origin/master' into integration/agent-g…
BobSong-dev Oct 26, 2026
cad1e72
merge: reconcile agent integration with latest master
BobSong-dev Oct 26, 2026
5b0a459
fix(agent-gateway): preserve metrics and tracing compatibility
BobSong-dev Oct 26, 2026
5e72769
Merge commit 'cad1e72320a4c2bf7c9e952762450feca8599a81' into feat/age…
BobSong-dev Oct 26, 2026
fa79ddd
Merge commit '5b0a4597c0a3a3fba57a622a18d1aed2fe3a702b' into feat/age…
BobSong-dev Oct 26, 2026
e69b7cc
fix(agent-gateway): align audit module version
BobSong-dev Oct 26, 2026
c8b7a32
chore: retrigger checks
BobSong-dev Oct 26, 2026
e1f4692
Merge remote-tracking branch 'origin/master' into feat/agent-gateway-…
BobSong-dev Oct 26, 2026
f9eb7ba
fix(agent-gateway): preserve released upgrade migrations
BobSong-dev Oct 27, 2026
a34127b
test(admin): cover plugin tables in migration contract fixtures
BobSong-dev Oct 27, 2026
3f417a3
merge: reconcile governance observability with latest master
BobSong-dev Oct 27, 2026
0fac12d
Merge commit 'a34127bc8a492e6de33efdb48285b3abd6c476e6' into HEAD
BobSong-dev Oct 27, 2026
6e1486e
Merge commit '3f417a358a0f5c4f37016235f7a564fdcc3c8456' into HEAD
BobSong-dev Oct 27, 2026
1b68fcb
Merge remote-tracking branch 'origin/master' into HEAD
BobSong-dev Oct 27, 2026
d093d0e
fix(ai-proxy): preserve audit mapping after master merge
BobSong-dev Oct 27, 2026
cb82930
Merge commit 'a34127bc8a492e6de33efdb48285b3abd6c476e6' into integrat…
BobSong-dev Oct 27, 2026
89a2fe2
Merge remote-tracking branch 'origin/master' into integration/agent-g…
BobSong-dev Oct 27, 2026
4f58def
merge: reconcile agent admission with latest master
BobSong-dev Oct 27, 2026
cb5c276
fix(agent-gateway): align migration baseline fixes
BobSong-dev Oct 27, 2026
9545498
Merge remote-tracking branch 'origin/master' into feat/agent-gateway-…
BobSong-dev Oct 28, 2026
d25e1bb
Merge commit 'a34127bc8a492e6de33efdb48285b3abd6c476e6' into feat/age…
BobSong-dev Oct 28, 2026
361ee75
fix(agent-gateway): preserve admission state across reloads
BobSong-dev Oct 28, 2026
0b7bfb3
Merge remote-tracking branch 'origin/master' into feat/agent-gateway-…
BobSong-dev Oct 28, 2026
220521a
fix(agent-gateway): drain admission queues after limit reloads
BobSong-dev Oct 28, 2026
98b1f42
fix(agent-gateway): synchronize admission queue promotion
BobSong-dev Oct 28, 2026
8fe70c2
Merge remote-tracking branch 'origin/master' into feat/agent-gateway-…
BobSong-dev Oct 28, 2026
6b1207c
Merge remote-tracking branch 'origin/master' into integration/agent-g…
BobSong-dev Oct 28, 2026
1a05008
Merge remote-tracking branch 'fork/integration/agent-gateway-p003' in…
BobSong-dev Oct 28, 2026
e9dc976
Merge remote-tracking branch 'fork/integration/agent-gateway-p105' in…
BobSong-dev Oct 28, 2026
4c6d01b
fix(agent-gateway): preserve rejection audits across master merge
BobSong-dev Oct 30, 2026
504d5bd
fix(agent-gateway): serialize admission reloads and reject expired work
BobSong-dev Oct 30, 2026
6c14893
fix(agent-gateway): record local attempts only after admission
BobSong-dev Oct 30, 2026
6cda864
Merge latest master into audit publication base
BobSong-dev Nov 5, 2026
83645b7
feat(common): add shared governance decisions
BobSong-dev Nov 5, 2026
c19a068
Merge current audit publication baseline into admission baseline
BobSong-dev Nov 5, 2026
63b02d3
fix(metrics): preserve single registration when reconciling audit bas…
BobSong-dev Nov 5, 2026
c2eeb87
Merge branch 'integration/audit-publication-20261105' into feat/agent…
BobSong-dev Nov 5, 2026
a73d8b2
Merge branch 'integration/audit-publication-20261105' into integratio…
BobSong-dev Nov 5, 2026
0dff19b
Merge branch 'feat/agent-gateway-governance-7956-publication' into fe…
BobSong-dev Nov 5, 2026
b9a5bdc
fix(ai-proxy): remove stale transport import from integration baseline
BobSong-dev Nov 5, 2026
79a060e
fix(metrics): retain runtime registration after baseline synchronization
BobSong-dev Nov 5, 2026
b26fd8e
Merge branch 'integration/audit-publication-20261105' into integratio…
BobSong-dev Nov 5, 2026
3457056
feat(agent-gateway): add distributed MCP invocation and concurrency q…
BobSong-dev Nov 5, 2026
1ef59b0
fix(ai-proxy): remove stale import from quota integration baseline
BobSong-dev Nov 5, 2026
6fa0abc
ci: rerun admission checks after intermittent admin failures
BobSong-dev Nov 5, 2026
ab421f7
test(admin): await recorded master selection failures
BobSong-dev Nov 5, 2026
c3487f5
test(agent-gateway): clarify logical audit target propagation
BobSong-dev Nov 5, 2026
0b3fb8e
fix(agent-gateway): make MCP quota admission cluster-safe
BobSong-dev Nov 6, 2026
594fead
fix(ci): reconcile MCP admission with master test fixes
BobSong-dev Nov 9, 2026
39c6035
fix(agent-gateway): reconcile quota review cleanup with master
BobSong-dev Nov 9, 2026
2c4288d
ci: retrigger checks for MCP resource admission
BobSong-dev Nov 9, 2026
1a6ded2
ci: retry checks after Kubernetes download timeouts
BobSong-dev Nov 9, 2026
41c792d
merge: reconcile audit integration with current master
BobSong-dev Nov 12, 2026
226f40e
merge: reconcile resource admission with current audit baseline
BobSong-dev Nov 12, 2026
2a1ae26
merge: synchronize MCP quota prerequisites with master
BobSong-dev Nov 12, 2026
0e49f78
test(agent-gateway): cover Redis quota failure and lease recovery
BobSong-dev Nov 12, 2026
a52a671
chore: reconcile MCP quotas with accepted audit baseline
BobSong-dev Nov 20, 2026
973e749
fix(audit): separate governance decisions from invocation terminals
BobSong-dev Nov 20, 2026
5ed95a2
test(agent-gateway): enforce one terminal audit with MCP quotas
BobSong-dev Nov 20, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions .github/workflows/agent-mcp-quota.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# 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.

name: Agent MCP Redis quota

on:
pull_request:
paths:
- 'shenyu-plugin/shenyu-plugin-agent-gateway/**'
- '.github/workflows/agent-mcp-quota.yml'
workflow_dispatch:

permissions:
contents: read

jobs:
redis-quota:
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: temurin
java-version: '17'
cache: maven
- name: Start Redis with cluster slot enforcement
run: |
docker run -d --name quota-redis -p 6379:6379 redis:7-alpine redis-server --cluster-enabled yes --cluster-config-file /tmp/nodes.conf
for attempt in $(seq 1 30); do
docker exec quota-redis redis-cli ping && break
sleep 1
done
docker exec quota-redis redis-cli cluster addslotsrange 0 16383
for attempt in $(seq 1 30); do
if docker exec quota-redis redis-cli cluster info | grep -q 'cluster_state:ok'; then exit 0; fi
sleep 1
done
exit 1
- name: Require real Redis quota regressions
run: >-
./mvnw -B -ntp -pl shenyu-plugin/shenyu-plugin-agent-gateway -am test
-Dtest=AgentMcpQuotaRedisStoreTest,AgentMcpQuotaGovernorTest,AgentMcpDispatcherTest
-Dsurefire.failIfNoSpecifiedTests=false -DskipRemoteResources=true
-Dshenyu.agent.mcp-quota.redis.required=true
- name: Redis diagnostics
if: failure()
run: docker logs quota-redis
- name: Stop Redis
if: always()
run: docker rm -f quota-redis
137 changes: 137 additions & 0 deletions docs/agent-gateway-mcp-quotas.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
<!--
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.
-->

# Agent Gateway distributed MCP quotas

Agent Gateway can enforce a shared invocation-count window and concurrency
limit for actual MCP `tools/call` requests. The first policy dimensions are
trusted tenant and subject, each using `invocation-limit`. Local and federated tools use the same admission
boundary. Tool discovery, resource reads, and other MCP methods do not consume
these quotas.

The feature is opt-in. The application owns the Redis connection and supplies
one `ReactiveRedisTemplate<String, String>` bean; Agent Gateway does not create
a second Redis client or lifecycle.

## Configuration

```yaml
shenyu:
plugins:
agent:
gateway:
mcp-quota:
enabled: true
mode: shadow # shadow or enforce
invocation-limit: 1000
invocation-window: 60s
concurrency-limit: 100
lease-ttl: 60s
fail-open: false
policy-version: mcp-quota-v1
```

The policy is an immutable startup snapshot. Changing these properties requires
an application restart or recreation of the owning Spring context; runtime rule
updates do not partially replace a running policy. `policy-version` is bounded
diagnostic metadata and does not shard Redis state.

`shadow` evaluates and records isolated would-deny decisions but never rejects
the call and never debits enforce state. `enforce` rejects at the actual tool
execution boundary. A denied tool is never executed. Missing or invalid tenant or
subject is an explicit identity rejection (403 / `-32027`), including in shadow
mode; unrelated callers never share an `unknown` tenant bucket.

## Redis semantics

Admission is one Lua operation. Redis `TIME` controls fixed windows and lease
expiry; gateway clocks never select windows or reclaim live leases.
It atomically checks the tenant and subject invocation counters,
removes expired concurrency leases, checks concurrency, debits the count, and
adds a unique lease token. Redis returns one of invocation-limited,
concurrency-limited, or admitted-with-lease; it never debits or acquires a
lease for a rejected request.

All admission keys share one Redis Cluster hash tag derived from mode and
base64url-encoded tenant; subject components are encoded independently:

- `shenyu:agent:mcp-quota:invocation:{mode:encodedTenant}`;
- `shenyu:agent:mcp-quota:invocation:{mode:encodedTenant}:encodedSubject`;
- `shenyu:agent:mcp-quota:concurrency:{mode:encodedTenant}:encodedSubject`.

Window hashes store the server-computed window and count and expire just after
that window. The concurrency sorted set stores one member per in-flight lease
and expires just after its lease TTL. Cardinality is bounded by active tenant and
subject identities, one active invocation hash per identity,
and at most the configured concurrency count per identity.

Completion, error, cancellation, or subscriber cancellation releases only the
opaque lease returned for that admission. Release is idempotent and cannot
remove another request's lease. Invocation count is never refunded: a retry is
a new admitted invocation, cancellation releases concurrency only, and an
unknown upstream outcome consumes the invocation because its side effect may
have occurred.

There is no lease renewal in this first policy. A lease carries one immutable
expiry and cannot be resurrected. If a gateway disappears, its lease is ignored
and removed after at most the configured `lease-ttl`, plus the documented
key-expiration buffer. Tool deadlines longer than `lease-ttl` are rejected as
policy errors before Redis admission. Set `lease-ttl` at least as high as the
largest tool timeout; enforced execution is also bounded by the lease TTL.
Local and remote capacity admission precede quota consumption, so overload
rejection never consumes an invocation.

## Outages and observability

Redis admission failure is explicit. `fail-open: false` rejects with a policy
error (HTTP 503 / JSON-RPC `-32027`) rather than guessing that admission was
granted. `fail-open: true` executes without a synthetic lease and records a
policy-error decision; concurrency release is not attempted for that request.

Allowed, would-deny, deny, and policy-error outcomes use the Agent governance
decision contract. Metrics expose only bounded decision labels:

```text
shenyu_agent_governance_decisions_total{consumer,mode,result,reason}
```

Tenant, subject, tool name, endpoint, request id, and trace id are not metric
labels. Non-allow decisions can also be emitted as metadata-only audit events
through the application-provided audit observer.
These are schema-version-3 `GOVERNANCE` observations, not invocation terminals.
Their outcomes are `ALLOW`, `WOULD_DENY`, or `DENY`; the HTTP handler still emits
one logical terminal result, plus an attempt only when the tool actually executes.
Audit consumers must exclude governance records from call counts and failure ratios.
Would-deny decisions are also counted in the governor's bounded, generation-owned
`AgentGovernanceShadowLedger`, available through `shadowSnapshot()`, separately
from enforce Redis state.

## Redis regression checks

The `Agent MCP Redis quota` workflow starts a real Redis node with Cluster slot
enforcement and assigns all slots to it. It requires the Redis tests to run
without skipped cases. Tests use independent connections, skewed gateway times,
actual Redis window/lease boundaries, tenant aggregate limits and tenant
isolation. This verifies script slot correctness; it does not simulate
multi-node Cluster failover.

## Non-goals

This is not a second general-purpose rate-limiter platform. It does not bill
elapsed time, enforce LLM token or cost budgets, replay side-effecting tools,
or add per-tool and per-server dimensions. Those require an explicit policy
extension so key cardinality and isolation remain bounded.
60 changes: 60 additions & 0 deletions docs/agent-gateway-resource-admission.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<!--
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.
-->

# Agent Gateway resource admission

Agent Gateway applies deterministic admission around every `tools/call` execution. Admission is deliberately not a retry or circuit-breaking layer: a call still executes at most once.

## Configuration

The trusted plugin configuration may contain one `admission` object:

```json
{
"admission": {
"globalInFlight": 128,
"globalQueued": 64,
"localInFlight": 32,
"localQueued": 16,
"remoteInFlight": 8,
"remoteQueued": 16
}
}
```

Omitting the object or supplying an empty object selects these defaults. Admin and gateway reject unknown fields and values outside the hard maxima (`128`, `256`, `64`, `128`, `32`, and `128` respectively).

## Semantics

- `global*` bounds all concurrent local and remote tool executions and their waiting work.
- `local*` bounds startup and request-local HTTP tool providers together.
- `remote*` is applied independently for each configured remote MCP server name.
- Admission checks the absolute request deadline before granting each global/local/remote permit, before reporting queue overflow, and immediately before subscribing to execution. An already-expired request never executes its provider, even with free capacity. Time spent waiting counts against execution time.
- Queue overflow returns HTTP `429` and JSON-RPC `-32026`; an expired request returns HTTP `504` and `-32026`.
- Every success, business error, gateway error, cancellation, timeout, configuration withdrawal and shutdown releases each acquired permit once.
- Local validation runs before resource admission. The execution-attempt callback and provider invocation run only when the admitted action is subscribed. Overload, queue timeout and cancellation before admission produce no execution-attempt audit record; their logical terminal record remains available.
- Existing byte limits, transport concurrency, catalog generation leases and no-retry behavior remain in force.

Configuration reload preserves active and queued accounting. All scope limits are installed before newly available slots are drained. Reload draining, terminal release and shutdown follow the same controller-promotion-monitor then scope-monitor order, including synchronous completion of promoted actions. Remote scope collections are copied under their registry monitor before callbacks or snapshot reads acquire scope monitors.

## Metrics

The Prometheus exporter publishes payload-free aggregates by fixed scope (`global`, `local`, `remote`): `shenyu_agent_admission_inflight`, `shenyu_agent_admission_queued`, `shenyu_agent_admission_inflight_limit`, `shenyu_agent_admission_queue_limit` and `shenyu_agent_admission_rejections_total`. Tool names, subjects, tenants and endpoints are never labels.

## Sizing guidance

Keep the global budget at or below the gateway process's sustainable CPU and response-memory budget. Reserve a separate remote in-flight budget for each latency-critical MCP server, and keep remote queues small: queued remote calls consume a shared global slot while waiting. Increase queue sizes only when clients can tolerate waiting until the existing request deadline; admission does not extend deadlines.
46 changes: 46 additions & 0 deletions docs/agent-governance-decision.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<!--
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.
-->

# Agent governance decision contract

Agent Gateway governance consumers use one versioned decision contract before introducing MCP quotas or LLM budgets. A decision identifies its consumer, policy/configuration versions, shadow or enforce mode, result, bounded reason, correlation id, ledger generation and effective time. Tenant, subject and trace id are not labels; they remain in the existing trusted request context and metadata-only audit event.

## Results and modes

- `ALLOW` means policy permits the call.
- `WOULD_DENY` is valid only in shadow mode. It is reported and counted in an isolated shadow ledger but must not reject traffic or debit production quota/budget state.
- `DENY` is valid only in enforce mode and is the only result that may reject traffic.

Authentication, authorization and fundamental resource-limit failures are mandatory denies in both modes. They are represented as enforce decisions even when the policy itself is shadow, so shadow mode cannot bypass security or base resource protection.

## Isolated shadow state and transitions

Each shadow ledger generation is immutable. Configuration replacement creates a new generation and closes the old ledger to new evaluations; existing in-flight reservations continue settling or cancelling against the generation that admitted them, and no state is moved or double-settled between ledgers. The bounded reference ledger reserves capacity for shadow `ALLOW` evaluations and records subsequent `WOULD_DENY` evaluations with bounded reason counters, accepted/observed/overflow/settled/cancelled/expired values, and explicit close. Overflow drops only shadow evaluation state, never traffic. Actual usage continues through the existing metering and terminal-event owners.

Shadow reservations have a bounded TTL. Expiry only releases that reservation's capacity and records an expired count; it does not reject traffic or debit a production policy. Cancellation and settlement are idempotent and mutually exclusive for the same reservation.

Shadow/enforce comparison is explicit: `SAME_EFFECT`, `SHADOW_STRICTER`, or `ENFORCE_STRICTER`. Comparisons require the same consumer, versions, ledger generation and correlation id, and are observations for rollout; they do not retroactively change an execution decision.

`AgentGovernanceContractLabels` is the metric boundary and exposes only consumer, mode, result and reason. `AgentGovernanceAuditAdapter` emits schema-version-3 `GOVERNANCE` records, not logical or attempt terminal results. Their outcome is the policy result (`ALLOW`, `WOULD_DENY`, or `DENY`), and their timestamp is the decision's effective time. Shadow would-deny retains an `ALLOWED` traffic decision with a `SHADOW_*` reason; enforce deny uses `REJECTED`. Policy allowance never asserts that tool execution succeeded. Version-1 `LOGICAL`/`ATTEMPT` records remain unchanged; version 2 is reserved for the separate usage-enrichment contract. The existing terminal owner emits the sole logical outcome. Consumers must route by schema version and record type and exclude governance observations from call counts and failure ratios.

## Non-goals

This document defines the shared vocabulary and bounded shadow state. The MCP
consumer and its Redis admission, execution-point wiring and decision audit are
described in [distributed MCP quotas](agent-gateway-mcp-quotas.md).
Token reservation, cost settlement and provider usage parsing remain separate
consumers and are not implemented by this contract.
21 changes: 20 additions & 1 deletion docs/agent-invocation-audit.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,29 @@
<!--
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.
-->

# Agent invocation audit

Agent Gateway and AI Proxy can emit metadata-only invocation audit events when `shenyu.plugins.agent.audit.enabled=true`.

## Record contract

Every event has schema version `1`, a logical request id, selector/rule ids, configuration version, policy version, target, decision, bounded outcome/reason, optional HTTP status, and timestamp. Logical records are terminal results; attempt records are separately numbered and correlated by the same request id.
Logical and attempt events have schema version `1`, a logical request id, selector/rule ids, configuration version, policy version, target, decision, bounded outcome/reason, optional HTTP status, and timestamp. Logical records are terminal results; attempt records are separately numbered and correlated by the same request id.

Schema version `3` adds non-terminal `GOVERNANCE` observations; version 2 is reserved for the separate usage-enrichment contract. Their outcome is a policy result (`ALLOW`, `WOULD_DENY`, `DENY`), not execution success or failure. They share the request id for correlation but must not be counted as logical calls, attempts, or billable usage. Existing version-1 terminal records and their single owner remain unchanged. Consumers that do not support version 3 must skip these records rather than treating every non-attempt as a terminal result.

Trusted tenant and subject are included when a server-side identity adapter resolves them. No prompt, arguments, response body, credential, raw API key, header map, or trace id is stored. W3C trace ids are correlation-only when used by tracing, never identity.

Expand Down
Loading
Loading