Skip to content

feat(adapters): request-rewriting interceptors - #1651

Closed
Glorf wants to merge 1 commit into
feat/adapter-basefrom
feat/adapter-rewrites
Closed

feat(adapters): request-rewriting interceptors#1651
Glorf wants to merge 1 commit into
feat/adapter-basefrom
feat/adapter-rewrites

Conversation

@Glorf

@Glorf Glorf commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Adapter interceptor follow-up on feat/adapter-base. Adds 6 interceptors that mutate the outbound request body:

  • drop_params — remove named parameters
  • payload_modifier — add / remove / rename body fields
  • system_message — inject a system message (prepend / append / replace)
  • consolidate_system — merge displaced system messages to position 0 (required by Qwen3)
  • modify_tools — strip / add tools[].function.parameters properties
  • turn_counter — per-session turn budget; raises GracefulError (→429) on exhaustion; warn/urgent system messages at 80%/95%

All registered as builtins. Tests: per-interceptor behavior, consolidate-system edge cases, parity replay (6 scenarios) — 39 added.

Supersedes Glorf#4 (fork discontinued; rebased clean onto upstream feat/adapter-base).

@copy-pr-bot

copy-pr-bot Bot commented Jun 22, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@github-actions

Copy link
Copy Markdown
Contributor

🌿 Preview your docs: https://nvidia-preview-feat-adapter-rewrites.docs.buildwithfern.com/nemo/gym

Here are the markdown pages you've updated:

@Glorf
Glorf force-pushed the feat/adapter-base branch from 8e7dee2 to 4916143 Compare June 23, 2026 09:06
@Glorf
Glorf requested a review from a team as a code owner June 23, 2026 09:06
@Glorf
Glorf force-pushed the feat/adapter-rewrites branch 2 times, most recently from 42204e5 to 1963f57 Compare June 23, 2026 10:57
@Glorf
Glorf force-pushed the feat/adapter-base branch from 2399ce2 to 45c8b8c Compare June 23, 2026 11:54
@Glorf
Glorf force-pushed the feat/adapter-rewrites branch from 1963f57 to 0bdc72e Compare June 23, 2026 11:54
@Glorf
Glorf force-pushed the feat/adapter-base branch from 45c8b8c to 73051c7 Compare June 23, 2026 12:29
@Glorf
Glorf force-pushed the feat/adapter-rewrites branch from 0bdc72e to 9ce8c25 Compare June 23, 2026 12:30
@Glorf
Glorf force-pushed the feat/adapter-base branch from 73051c7 to c4313fb Compare June 23, 2026 12:38
PR 4 of 4 — request-rewriting family. Built on feat/adapter-base
(independent of the observability and caching PRs).

Adds 6 interceptors that mutate the outbound request body before it
reaches the upstream:

  - drop_params         remove named parameters from outbound body
  - payload_modifier    add / remove / rename body fields
  - system_message      inject a system message (prepend / append /
                        replace)
  - consolidate_system  merge displaced system messages into one at
                        position 0 (Qwen3 requires this; other models
                        tolerate it)
  - modify_tools        strip or add properties on
                        tools[].function.parameters
  - turn_counter        per-session turn budget; raises GracefulError
                        (-> 429) on exhaustion; injects warn/urgent
                        system messages at 80%/95% of budget

All six are registered as builtins in InterceptorRegistry._BUILTIN.

Tests

  test_adapter_interceptors.py       drop_params, modify_tools,
                                     system_message (prepend / replace),
                                     payload_modifier (add / remove),
                                     turn_counter (basic + session
                                     isolation)
  test_adapter_consolidate_system.py displaced-system-message merging
                                     edge cases
  test_adapter_parity_replay.py      6 captured-fixture scenarios

81 tests pass (42 from feat/adapter-base + 39 added).

Docs

  fern/.../model-server/adapters.mdx  appends Request-Rewriting section
                                      with per-interceptor YAML config
                                      snippets.

Signed-off-by: Michal Bien <mbien@nvidia.com>
@Glorf
Glorf force-pushed the feat/adapter-rewrites branch from 9ce8c25 to f2121b8 Compare June 23, 2026 12:38
@anwithk
anwithk requested a review from ffrujeri June 23, 2026 16:07
@Glorf Glorf closed this Jun 24, 2026
Glorf added a commit that referenced this pull request Jul 8, 2026
ECS Fargate `SandboxProvider` on top of the sandbox API (#1377, now
merged to `main`). Auto-mirrors public images to ECR on demand; SSH
reverse-tunnel for exec / file-transfer / model egress.

Rebased onto `main` now that the sandbox base (#1377) has landed — this
PR stands on its own and is ready for review.

**Sandbox-bound agents line of work:**
**ECS Fargate (this PR)** → adapter middleware base (#1646) →
sandbox-bound CLI agents + capture (#1647). Interceptor follow-ups on
the adapter base: #1649 (caching), #1650 (observability), #1651
(rewrites).

3 commits, +5974: ECS provider + engine, on-demand ECR mirroring + conda
activation fix, and 233 unit tests (engine.py to 99%). `uv.lock`
reconciled with main's security upgrades (#1657).

---------

Signed-off-by: Michal Bien <mbien@nvidia.com>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant