Skip to content

feat(adaptive): add agent context propagation#281

Draft
ishandhanani wants to merge 1 commit into
NVIDIA:mainfrom
ishandhanani:idhanani/dyn-3207-nemo-relay-agentcontext-poc
Draft

feat(adaptive): add agent context propagation#281
ishandhanani wants to merge 1 commit into
NVIDIA:mainfrom
ishandhanani:idhanani/dyn-3207-nemo-relay-agentcontext-poc

Conversation

@ishandhanani

@ishandhanani ishandhanani commented Jun 16, 2026

Copy link
Copy Markdown

Overview

Adds opt-in adaptive agent context propagation for coding-agent gateway traffic. Producers attach canonical context to scope metadata, and the adaptive agent_context request intercept copies the nearest active context into model requests at the configured body path (nvext.agent_context by default).

This keeps the feature general: Codex is only one producer used for validation, while the adaptive intercept is reusable by any coding-agent integration that records the same scope metadata.

  • I confirm this contribution is my own work, or I have the right to submit it under this project's license.
  • I searched existing issues and open pull requests, and this does not duplicate existing work.

Details

  • Adds adaptive agent_context configuration and a request intercept that resolves /nemo_relay/agent_context from the nearest active scope, preserves caller-provided context, and no-ops when context or object request bodies are absent.
  • Updates CLI gateway session preparation to publish agent context on scope metadata for normalized coding-agent turns, including subagent lineage, instead of mutating OpenAI request bodies directly.
  • Removes the CLI-specific environment gate/body-injection implementation from the net change.
  • Exposes the adaptive config through Rust, Python, Node.js, WebAssembly wrappers, and Go bindings.
  • Documents the new adaptive plugin section and adds focused Rust, Python, Node.js, WebAssembly, and Go coverage for config shape and behavior.
  • Serializes adaptive global-runtime mutation tests through a shared test-only lock to keep Rust validation deterministic.

Validation run:

  • cargo fmt --all
  • git diff --check
  • cargo test -p nemo-relay-cli
  • cargo test -p nemo-relay-adaptive
  • just test-rust
  • PYO3_PYTHON=/ephemeral/NeMo-Relay/.venv/bin/python cargo clippy --workspace --all-targets -- -D warnings
  • cargo clippy -p nemo-relay-adaptive -p nemo-relay-cli --all-targets -- -D warnings
  • uv run pytest python/tests/test_adaptive.py python/tests/test_adaptive_config.py
  • uv run ty check python/nemo_relay/adaptive.py python/nemo_relay/adaptive.pyi
  • just test-python
  • Live smoke: headless Codex through nemo-relay run --agent codex against Dynamo GLM-4.7-Flash TP2 with adaptive agent_context enabled. The fixed run produced 3 Dynamo request-trace rows with agent_context.session_type_id = "codex".

Local toolchain blockers:

  • just test-node failed because local Node is v12.22.9; this repo requires Node 24 or newer.
  • just test-go failed because go is not installed on PATH.
  • just test-wasm failed because wasm-pack is not installed on PATH.
  • uv run pre-commit run --all-files was not rerun after this rework; the local Node/Go/WebAssembly blockers above would fail the relevant hooks.

Live smoke artifacts:

  • Request trace JSONL: /tmp/dyn-3207-codex-agent-context-fixed-request-trace.jsonl
  • Perfetto trace: /tmp/dyn-3207-codex-agent-context-fixed-request-trace.perfetto.json
  • Codex output: /tmp/dyn-3207-codex-agent-context-fixed-last.txt

Where should the reviewer start?

Start with crates/adaptive/src/agent_context_intercept.rs for the generic request intercept, then crates/cli/src/session.rs for the Codex gateway producer path. The most useful tests are crates/adaptive/tests/unit/agent_context_intercept_tests.rs and crates/cli/tests/coverage/session_tests.rs.

Related Issues: (use one of the action keywords Closes / Fixes / Resolves / Relates to)

@coderabbitai

coderabbitai Bot commented Jun 16, 2026

Copy link
Copy Markdown

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Enterprise

Run ID: 414747c2-27c8-4e70-a6e8-ff4cc8639b85

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions Bot added size:M PR is medium Feature a new feature lang:rust PR changes/introduces Rust code labels Jun 16, 2026
@willkill07

Copy link
Copy Markdown
Member

This would work for CLI-wrapped execution but wouldn't work in the general case (native OpenClaw plugin, DeepAgents integration, etc)

In the ideal case this should be a universal request intercept which is registered. Principle of least astonishment would probably result in opt-in behavior through the adaptive plugin with an added configuration option.

This would bring it inline with the existing adaptive runtime behavior

@ishandhanani ishandhanani force-pushed the idhanani/dyn-3207-nemo-relay-agentcontext-poc branch from dbb7cea to ea2f65a Compare June 17, 2026 09:04
@github-actions github-actions Bot added size:XL PR is extra large lang:go PR changes/introduces Go code lang:js PR changes/introduces Javascript/Typescript code lang:python PR changes/introduces Python code and removed size:M PR is medium labels Jun 17, 2026
@ishandhanani ishandhanani changed the title feat(cli): emit gateway agent context feat(adaptive): add agent context propagation Jun 17, 2026
@github-actions

github-actions Bot commented Jun 17, 2026

Copy link
Copy Markdown

Signed-off-by: Ishan Dhanani <ishandhanani@gmail.com>
@ishandhanani ishandhanani force-pushed the idhanani/dyn-3207-nemo-relay-agentcontext-poc branch from ea2f65a to 0d8a5c5 Compare June 17, 2026 09:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Feature a new feature lang:go PR changes/introduces Go code lang:js PR changes/introduces Javascript/Typescript code lang:python PR changes/introduces Python code lang:rust PR changes/introduces Rust code size:XL PR is extra large

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants