> This page is for NeMo Relay, version v1.0.0.
> For other versions, use one of these documentation indexes:
> - Latest (v0.11.2) (default): https://docs.nvidia.com/nemo/relay/latest/llms.txt
> - dev: https://docs.nvidia.com/nemo/relay/dev/llms.txt
> - v1.0.0: https://docs.nvidia.com/nemo/relay/v1.0.0/llms.txt
> - v0.11.2: https://docs.nvidia.com/nemo/relay/v0.11.2/llms.txt
> - v0.10.4: https://docs.nvidia.com/nemo/relay/v0.10.4/llms.txt
> - v0.9.4: https://docs.nvidia.com/nemo/relay/v0.9.4/llms.txt
> - v0.8.4: https://docs.nvidia.com/nemo/relay/v0.8.4/llms.txt

> For clean Markdown of any page, append .md to the page URL. For a task-oriented documentation index, fetch https://docs.nvidia.com/nemo/relay/llms.txt. Use the documentation version matching the installed NeMo Relay package: latest follows the latest stable release, vX.Y.Z identifies a retained release snapshot, and dev documents development changes. Preserve the selected version when following links; do not mix examples or API contracts from different versions. Fetch the relevant section's /llms.txt before individual pages instead of loading a complete version index.

# Adaptive Cache Governor (ACG)

> Configure Adaptive Cache Governor for provider-aware prompt-cache planning.

Use the Adaptive Cache Governor (ACG) when repeated LLM requests contain stable
prompt sections that can benefit from provider prompt caching.

ACG decomposes LLM requests into Prompt IR, scores block stability across
observed runs, and plans provider-specific prompt-cache breakpoints. The `acg`
section is optional. Omit it to keep cache planning disabled.

## `plugins.toml` Example

Add the following Adaptive Cache Governor configuration to `plugins.toml`:

```toml
version = 1

[[components]]
kind = "adaptive"
enabled = true

[components.config]
version = 1
agent_id = "planner"

[components.config.state.backend]
kind = "in_memory"

[components.config.telemetry]
subscriber_name = "adaptive.telemetry"
learners = ["acg"]

[components.config.acg]
provider = "anthropic"
observation_window = 100
priority = 50

[components.config.acg.stability_thresholds]
stable_threshold = 0.95
semi_stable_threshold = 0.50
min_observations_for_full_confidence = 20
```

This configuration enables adaptive telemetry and configures ACG to plan cache
breakpoints for Anthropic-style request surfaces after it has enough observed
prompt samples.

## Plugin Configuration

Use plugin configuration when the application should let NeMo Relay own the
Adaptive Cache Governor (ACG) runtime lifecycle. The following examples
configure and activate ACG through each supported language binding.

`validate()` resolves the same configuration layers as `initialize()` without
loading plugin code or acquiring the activation lease. Use Python/Rust
`validate_exact()`, Node.js `validateExact()`, or Go `ValidateExact()` when only
the supplied static configuration should be checked. For complete
layering rules, refer to [Configure](/nemo/relay/v1.0.0/configure-plugins/plugin-configuration-files).

#### Python

```python
import asyncio

import nemo_relay

adaptive_config = nemo_relay.adaptive.AdaptiveConfig(
    agent_id="planner",
    state=nemo_relay.adaptive.StateConfig(
        backend=nemo_relay.adaptive.BackendSpec.in_memory(),
    ),
    telemetry=nemo_relay.adaptive.TelemetryConfig(learners=["acg"]),
    acg=nemo_relay.adaptive.AcgConfig(provider="anthropic"),
)

plugin_config = nemo_relay.plugin.PluginConfig(
    components=[nemo_relay.adaptive.ComponentSpec(adaptive_config)]
)

report = nemo_relay.plugin.validate(plugin_config)["config"]
if any(diagnostic["level"] == "error" for diagnostic in report["diagnostics"]):
    raise RuntimeError(report["diagnostics"])

async def main() -> None:
    async with nemo_relay.plugin.activate(plugin_config):
        # Run instrumented application work here.
        pass

asyncio.run(main())
```

#### Node.js

```js
const adaptive = require("nemo-relay-node/adaptive");
const plugin = require("nemo-relay-node/plugin");

const adaptiveConfig = adaptive.defaultConfig();
adaptiveConfig.agent_id = "planner";
adaptiveConfig.state = { backend: adaptive.inMemoryBackend() };
adaptiveConfig.telemetry = adaptive.telemetryConfig({ learners: ["acg"] });
adaptiveConfig.acg = adaptive.acgConfig({ provider: "anthropic" });

const pluginConfig = plugin.defaultConfig();
pluginConfig.components = [adaptive.ComponentSpec(adaptiveConfig)];

const report = plugin.validate(pluginConfig).config;
if (report.diagnostics.some((diagnostic) => diagnostic.level === "error")) {
  throw new Error(JSON.stringify(report.diagnostics));
}

void (async () => {
  const activation = await plugin.initialize(pluginConfig);
  try {
    // Run instrumented application work here.
  } finally {
    await activation.close();
  }
})().catch((error) => {
  console.error(error);
  process.exitCode = 1;
});
```

#### Rust

```rust
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
use nemo_relay::plugin::PluginConfig;
use nemo_relay::plugin::{initialize, validate};
use nemo_relay_adaptive::plugin_component::ComponentSpec;
use nemo_relay_adaptive::{
    AcgComponentConfig, AdaptiveConfig, BackendSpec, StateConfig, TelemetryComponentConfig,
};

let mut adaptive = AdaptiveConfig::default();
adaptive.agent_id = Some("planner".into());
adaptive.state = Some(StateConfig {
    backend: BackendSpec::in_memory(),
});
adaptive.telemetry = Some(TelemetryComponentConfig {
    learners: vec!["acg".into()],
    ..TelemetryComponentConfig::default()
});
adaptive.acg = Some(AcgComponentConfig {
    provider: "anthropic".into(),
    ..AcgComponentConfig::default()
});

let mut plugin_config = PluginConfig::default();
plugin_config.components.push(ComponentSpec::new(adaptive).into());

let report = validate(plugin_config.clone(), None)?;
assert!(!report.config.has_errors());

let mut activation = initialize(plugin_config, None).await?;

// Run instrumented application work here.

activation.close()?;
Ok(())
}
```

## Manual API

For manual runtime construction and lifecycle examples, refer to
[Manual API](/nemo/relay/v1.0.0/reference/api/adaptive#acg-manual-api).

## Fields

The following table describes Adaptive Cache Governor settings:

| Field                                                       | Default       | Notes                                                       |
| ----------------------------------------------------------- | ------------- | ----------------------------------------------------------- |
| `provider`                                                  | `passthrough` | `passthrough`, `anthropic`, or `openai`.                    |
| `observation_window`                                        | `100`         | Rolling Prompt IR sample window for stability analysis.     |
| `priority`                                                  | `50`          | LLM execution intercept priority. Lower values run earlier. |
| `stability_thresholds.stable_threshold`                     | `0.95`        | Minimum effective score classified as stable.               |
| `stability_thresholds.semi_stable_threshold`                | `0.50`        | Minimum effective score classified as semi-stable.          |
| `stability_thresholds.min_observations_for_full_confidence` | `20`          | Observation count required for full confidence.             |

Use `passthrough` when you want ACG observations without provider-specific hint
translation. Set `provider` to the backend API surface the agent actually calls
when you are ready to apply cache planning.

## Expected Output

When ACG is active, instrumented LLM calls still return the same application
result. ACG records observations and, when enough stable prompt structure is
available, emits adaptive diagnostics and cache-planning decisions through the
adaptive runtime.

Prompt analysis uses borrowed normalized content views with separate policies
for profile fingerprints and prompt IR. It retains existing message/block
boundaries. Plain prose is whitespace-normalized; structured input is canonical
JSON whose payload string values keep their whitespace. Media and provider-native
parts contribute typed fingerprints rather than disappearing from stability
analysis or being treated as prose. Tool-result identities retain the inner
content type, so a structured result is distinct from literal text containing
its serialized JSON. These analysis representations are not sent to the provider.

Media and opaque blocks require supplied token metadata for token-based cache
planning. Without it, economics stops considering prefixes at that block, and
Anthropic translation declines cache breakpoints spanning it. Character counts
of fingerprints are not used as token counts. The full source-request fingerprint
guard for prefixes beyond the leading scaffold remains in place.

ACG now stores learning observations and the agent bootstrap seed under the
`::acg-ir=2` namespace. Existing unversioned state is retained but is not loaded
or mixed with the new representation; upgraded agents warm up from new samples.
This does not change the configured agent ID, storage backend APIs, or grouping of
growing conversations. Rust consumers matching `BlockContentType` must handle
the new `StructuredInput` and `Opaque` variants.

Provider-specific cache hints are useful only when the request surface supports
them. Validate against representative LLM traffic before enabling ACG in
production.

## Common Configuration and Runtime Issues

* `provider` is not one of `passthrough`, `anthropic`, or `openai`.
* Stability thresholds are outside the supported numeric range.
* ACG is enabled before the application emits managed LLM events.
* The configured provider does not match the real model API surface.