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
Compute level
Resources
What the paper used
Prerequisites
Scope
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.”
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.
- Inspect the CLI harness execution wrapper for tools like Claude Code or Copilot CLI to identify process input/output pipes.
- Write a Python wrapper implementing a pseudo-terminal (PTY) interceptor to capture and inject strings into running child processes.
- Extend the rule-based trigger and LLM judge to output corrective text directly to the active PTY input buffer.
- 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?
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.
- SagaLLM: Context Management, Validation, and Transaction Guarantees for Multi-Agent LLM Planning · 2025 · 121 citations
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 AgentsAaron 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
- Action-Semantic Privilege Isolation to Resist Indirect Prompt Injection in Autonomous AgentsK2-Horizon: A Frontier Fleet of Open Source Language Models🟠Medium
- Compressive Memory for Agentic ContextsGLM-5: from Vibe Coding to Agentic Engineering🟠Medium
- Affordance-Grounded Execution Filters to Bridge the Text-to-Action Refusal GapEnvisioning Agentic Robotics: A New Era of Robotic Systems🟡Fairly easy
- Off-Policy Correction for Asynchronous Agent RLGLM-5: from Vibe Coding to Agentic Engineering🟠Medium
- Automated Linter for Agent-Code SynchronizationAgent READMEs: An Empirical Study of Context Files for Agentic Coding🟡Fairly easy