Skip to content

Fix agentic-traffic reliability and enable provider prompt caching - #91

Open
veerareddyvishal144 wants to merge 1 commit into
mainfrom
fix/agentic-reliability-prompt-cache
Open

Fix agentic-traffic reliability and enable provider prompt caching#91
veerareddyvishal144 wants to merge 1 commit into
mainfrom
fix/agentic-reliability-prompt-cache

Conversation

@veerareddyvishal144

Copy link
Copy Markdown
Contributor

Problem

Agent loops through Lynkr were silently degraded in four ways, all observed and measured on ITSMBench / terminal-bench harnesses (pi agent, Azure gpt-5.6-sol):

  1. Episodes killed mid-task: upstream 429-retry exhaustion surfaced as a contentless 200 with finish_reason: stop; agent clients read that as "done" and stopped. Killed 6/7 benchmark episodes in one run.
  2. System prompt discarded after turn 1: continuations replaced the client agent's instructions with a generic one-liner.
  3. Reasoning never forwarded: reasoning_effort was dropped on the Azure Responses path; thinking requests silently ran at minimum effort. max_output_tokens was also unset for gpt-5.x (read from the wrong key).
  4. Provider prompt caching broken (0–3% hit rate): six code paths rewrote request bytes every turn — random tool-call fallback IDs (Date.now()+random), the system-prompt swap, conditional reminder-stripping, timestamped tee IDs in tool-result compression, tier-flapping compression thresholds — so prefixes never matched and every token billed at full price.

Fix

  • openai-router: guard that aborts the SSE stream (client retries) instead of serving a clean empty completion.
  • databricks: forward reasoning.effort; fix max_output_tokens; surface cache_read_input_tokens through both response conversions into telemetry; add prompt_cache_key (session id or first-user-message hash) on gpt-5.x requests.
  • Prefix stability: deterministic content-hash tool-call/tee IDs, one constant system prompt per conversation (full prompt, reminders stripped uniformly on every turn), fixed COMPLEX compression threshold.
  • config: new TOOL_RESULT_COMPRESSION_ENABLED env knob (was hardcoded).
  • nodemon.json: ignore self-written data/db files (dev restart storms).

Measured results

  • Provider cache hit rate: 0–3% → 92–95% on agent loops (~5× real cost reduction; ~$5.00/task → ~$0.87/task at reasoning=high on ITSMBench).
  • Through-proxy quality on ITSMBench now statistically equal to the same model direct (35.0% vs 35.51% Pass@1).
  • No Azure content-filter rejections across ~2,000 continuation requests with the full system prompt.

Behavior changes for review

  • Tool-result compression threshold is now fixed at COMPLEX (>2000 chars) instead of following the routed tier — determinism is required for caching; net effect is lighter compression for most traffic.
  • Continuations carry the client's full (reminder-stripped) system prompt instead of the generic replacement.

Known issue (follow-up, not addressed here)

Terminal-bench A/B shows Lynkr still costs significant quality on long compute-heavy coding tasks (direct 17/22 vs through-Lynkr 8/21), dominated by agent timeouts from per-turn latency (buffered non-streaming upstream calls). Fix is true streaming passthrough — proposed as a follow-up issue.

🤖 Generated with Claude Code

Measured on ITSMBench + terminal-bench via a pi-agent harness; each fix
addresses a defect observed in production-like agent loops:

- openai-router: never serve a clean empty completion. Upstream 429-retry
  exhaustion surfaced as a contentless 200 with finish_reason=stop, which
  agent clients read as "task complete" and terminated mid-task (observed
  killing 6/7 benchmark episodes). Abort the SSE stream instead so clients
  retry.

- databricks (Azure Responses): forward reasoning effort (was silently
  dropped — thinking requests never reached the model), fix
  max_output_tokens (read from max_completion_tokens for gpt-5.x), and
  surface cache_read_input_tokens through both response conversions so
  telemetry records provider cache hits (was always null).

- Prefix stability for provider prompt caching (measured 0-3% -> 92-95%
  cache hit rate, ~5x real cost cut on agent loops):
  * deterministic tool-call fallback IDs (were Date.now()+random — history
    re-randomized every turn)
  * one constant system prompt per conversation (continuations previously
    swapped in a generic prompt, which also silently discarded the client
    agent's instructions after turn 1)
  * uniform system-reminder stripping on every turn
  * content-hash tee IDs in the tool-result compressor (were timestamped —
    new bytes in old messages each turn)
  * fixed compression threshold (routed tier flaps between turns; COMPLEX
    keeps compression deterministic and lightly lossy)
  * prompt_cache_key on Azure gpt-5.x requests (session id or first-user-
    message hash)

- config: TOOL_RESULT_COMPRESSION_ENABLED env knob (was hardcoded)
- nodemon.json: ignore self-written data/db files (restart-storm fix)

Co-Authored-By: Claude Fable 5 <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