Skip to content
AI-generated research idea🟠Medium💡Moderate InnovationNo close match found

In-Flight Context-Preserving Intervention via Interactive Agent Stream Injection

Develop harness-native pseudo-terminal and stdin interceptors to inject steerage feedback directly as unexpected user turns into active agent sessions.

Time

2 to 3 weeks to build reliable PTY/stdin interceptors across the CLI harnesses and complete multi-seed SWE-Bench evaluations.

Compute level

Single GPU or less

Resources

API credits for Claude Code, Codex, and Copilot CLI with frontier models across 277 SWE-Bench tasks (3 seeds) in Docker containers, plus harness engineering for PTY/stdin interception and rolling context-window compression across the three CLI tools.

What the paper used

Hardware and dollar spend are not stated in the paper; experiments run containerized commercial CLI agents across 5 agent-model settings (Claude Code 2.1.170 with Sonnet 5 and Opus 4.8, Copilot CLI 1.0.84-7 with Sonnet 5, Codex 0.153.1 with GPT-5.6 Terra and GPT-5.6 Sol) on 60 SWE-Bench profiling tasks and 579 main evaluation tasks (277 SWE-Bench, 102 Web-Bench, 100 CredData, 100 ReposVul) with 3 seeds per setting.

Prerequisites

Operating systems process control (PTY, IPC, signal handling) and agent harness architectures.

Scope

Build an adapter layer from scratch for target CLIs or patch harness communication channels.

The Gap

In Section 3.3 and Appendix J, when the failure-loop guard decides to redirect an agent, it forcibly kills the active CLI process (Claude Code, Codex, or Copilot CLI) and launches an entirely new process invocation inside the container, passing the redirect message in the launch prompt while retaining disk modifications.

“To redirect, it stops the CLI and starts a new invocation in the same container, with the redirect in its prompt and the agent’s edits still on disk.”
From the paper, Appendix J, page 26. Matched against the PDF text.

Limitation

Process termination clears the agent's short-term reasoning scratchpad and dialogue state. The fresh restart requires the agent to re-read and re-bill the entire system prompt, tool definitions, and re-explore on-disk changes, significantly reducing the net token savings gained by the intervention.

Proposed Solution

Develop harness-native pseudo-terminal (PTY) and stdin interceptors that inject steerage feedback directly as an unexpected user turn into the existing running session rather than aborting the process. Extend the rule-based trigger and LLM judge to inject corrective guidance dynamically into the agent's active session history while maintaining rolling window context compression over older turns.

Why This Matters

Eliminates the token re-initialization penalty of process respawning, saves hundreds of cache-read and uncached prefix tokens per intervention, and allows multiple adaptive nudges instead of being constrained to a single redirect.

How to Get Started

How to test it: Hypothesis: injecting failure-loop redirects into the live session via PTY/stdin instead of terminating and restarting the CLI preserves dialogue context and prompt caching, reducing post-redirect token spend compared to standard TokenEconomizer's restart-based intervention. Measure cache-aware cost and Pass@1 on redirected trajectories and full SWE-Bench streams; stop if in-flight PTY injection fails to lower net token cost on redirected tasks or degrades post-redirect Pass@1.

  1. Inspect the CLI harness execution wrapper for tools like Claude Code or Copilot CLI to identify process input/output pipes.
  2. Write a Python wrapper implementing a pseudo-terminal (PTY) interceptor to capture and inject strings into running child processes.
  3. Extend the rule-based trigger and LLM judge to output corrective text directly to the active PTY input buffer.
  4. Benchmark task success recovery rates when injecting real-time feedback versus restarting the agent process entirely.

Code linked to this paper on Hugging Face: github.com/microsoft/TokenEconomizer

Suggested by AI. Adapt it to your setup.

Has This Been Done?

No close match in 10 results

The provided literature covers prompt injection threats and context management such as SagaLLM, but none of the papers implement harness-native pseudo-terminal and stdin interceptors to inject steerage feedback directly into an active running session as an unexpected user turn.

We searched OpenAlex and arXiv for “Develop harness-native pseudo-terminal and stdin interceptors to inject steerage feedback directly as unexpected user turns into active agent sessions.” and “In-Flight Context-Preserving Intervention via Interactive Agent Stream Injection” and an AI compared the idea with the top 10 results. A small search can miss relevant work.

Source Paper

TokenEconomizer: Experience-Driven Black-Box Cost Control for Coding Agents

Aaron J. Li, Weijia Xu, Chandan Singh +8 more · 2026

This paper addresses the excessive token costs incurred by frontier coding agents when executing sequential software engineering tasks within shared environments. The authors introduce TokenEconomizer, an external, black-box controller that monitors execution traces to adaptively inject environment-specific micro-skills, prune unused tool definitions from agent contexts, and interrupt unproductive failure loops. Evaluated across Claude Code, Codex, and GitHub Copilot CLI on benchmarks including SWE-Bench, Web-Bench, and security auditing datasets, TokenEconomizer achieves an 18.4% to 30.9% token cost reduction while preserving or improving task success rates.

Related Ideas

Is this a good idea?

Share onXLinkedIn