Skip to content

fix: LLM provider works with subscription proxies + honor SUMMARIZE_CHUNK_SIZE from .env#742

Open
caioniehues wants to merge 2 commits into
rohitg00:mainfrom
caioniehues:fix/llm-provider-proxy-compat-and-chunk-env
Open

fix: LLM provider works with subscription proxies + honor SUMMARIZE_CHUNK_SIZE from .env#742
caioniehues wants to merge 2 commits into
rohitg00:mainfrom
caioniehues:fix/llm-provider-proxy-compat-and-chunk-env

Conversation

@caioniehues
Copy link
Copy Markdown

@caioniehues caioniehues commented May 31, 2026

Summary

Two independent robustness fixes for non-standard / local LLM endpoints, both surfaced while running agentmemory's compression + summarization through a self-hosted Claude Code subscription proxy and against local Ollama models.

1. fix(providers) — fold the Anthropic system prompt into the user message

AnthropicProvider.call() passes the prompt via the system field. Some Anthropic-compatible proxies — notably Claude Code subscription bridges — inject their own agent system prompt and override the caller's system. The model then ignores agentmemory's structured-output instructions and replies conversationally (e.g. "I'll look at the auth code…"), so content.find(b => b.type === 'text') returns prose with no <summary> → every summarize/compress call fails as empty_provider_response / too_many_chunks_skipped.

Folding the instructions into the user message survives the override and behaves identically against the official Anthropic API.

Evidence: the same bulk run that produced 0/84 parseable summaries through such a proxy produced 83/84 (quality 50–100) after this change.

2. fix(summarize) — honor SUMMARIZE_CHUNK_SIZE / SUMMARIZE_CHUNK_CONCURRENCY from .env

getChunkSize() / getChunkConcurrency() read process.env directly, so the documented values placed in ~/.agentmemory/.env are silently ignored — every other setting flows through getEnvVar() / getMergedEnv(). For small-context local models (e.g. an 8k-context Ollama model) the default 400-observation chunk (~44k tokens) overflows the window and all chunks fail to parse.

Routing both through getEnvVar() honors the file. process.env still wins (getMergedEnv spreads it last), so existing overrides are unaffected.

Test plan

Both fixes are small and independent; happy to split into two PRs if preferred.

Summary by CodeRabbit

  • Chores
    • Summarization chunk sizing and concurrency configuration now supported via environment files with fallback defaults.
    • Updated Anthropic provider implementation to improve compatibility with certain proxy services.

Caio Niehues added 2 commits May 31, 2026 08:45
Some Anthropic-compatible proxies (e.g. Claude Code subscription bridges)
inject their own agent system prompt and override the caller's `system`
field. Structured-output instructions placed in `system` are then ignored
and the model replies conversationally ("I'll look at the files..."),
producing no parseable output — observed as empty_provider_response /
too_many_chunks_skipped on every summarize/compress call through such a proxy.

Fold the system prompt into the user message instead. It survives the
override and behaves identically against the official Anthropic API.

Signed-off-by: Caio Niehues <caioniehues@MacBook-Pro.local>
…emory/.env

getChunkSize()/getChunkConcurrency() read process.env directly, so the
documented SUMMARIZE_CHUNK_SIZE / SUMMARIZE_CHUNK_CONCURRENCY values set in
~/.agentmemory/.env were silently ignored — every other setting flows through
getEnvVar()/getMergedEnv(). This matters for small-context local models, where
the default 400-observation chunk overflows the window and all chunks fail to
parse.

Route both through getEnvVar() so the .env file is honored; process.env still
wins (getMergedEnv spreads it last), so existing overrides and tests are
unaffected.

Signed-off-by: Caio Niehues <caioniehues@MacBook-Pro.local>
@vercel
Copy link
Copy Markdown

vercel Bot commented May 31, 2026

Someone is attempting to deploy a commit to the rohitg00's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 31, 2026

Review Change Stack

📝 Walkthrough

Walkthrough

Two independent configuration and integration changes: summarization configuration now respects the merged environment helper (getEnvVar) instead of direct process.env access for chunk sizing and concurrency; Anthropic API requests prepend system prompts into user messages instead of using the separate system parameter for proxy compatibility.

Changes

Environment Configuration Refactoring

Layer / File(s) Summary
Merged environment helper for summarization config
src/functions/summarize.ts
Import of getEnvVar added; getChunkSize and getChunkConcurrency now read SUMMARIZE_CHUNK_SIZE and SUMMARIZE_CHUNK_CONCURRENCY via merged environment helper instead of direct process.env, preserving existing parse validation and defaults.

Anthropic API Integration Fix

Layer / File(s) Summary
System prompt handling in Anthropic API calls
src/providers/anthropic.ts
Request payload now sends systemPrompt prepended into a single user message content (with \n\n separator when non-empty) instead of using the separate system parameter; inline comments document that some Anthropic-compatible proxies override structured system instructions.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Suggested reviewers

  • rohitg00

Poem

A rabbit hops through env and API,
Merging configs with newfound glee,
Prepending prompts with care and grace,
Two fixes that find their rightful place! 🐰

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main changes: fixing LLM provider compatibility with subscription proxies and honoring SUMMARIZE_CHUNK_SIZE from .env, matching the core objectives of the PR.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

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

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint skipped: no ESLint configuration detected in root package.json. To enable, add eslint to devDependencies.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
src/functions/summarize.ts (1)

40-49: 💤 Low value

Trim the explanatory comment block.

The logic change is correct, and routing through getEnvVar preserves process.env precedence (it is spread last in getMergedEnv), so the existing process.env-based tests remain valid. However, the 4-line comment at Lines 41-44 narrates what the code does and its history; prefer letting getEnvVar convey intent and drop the WHAT portion.

♻️ Suggested trim
 function getChunkSize(): number {
-  // Read via the merged env (file + process.env) so ~/.agentmemory/.env works,
-  // consistent with every other config var. process.env still wins (getMergedEnv
-  // spreads it last). Previously read process.env only, so the .env file value
-  // was silently ignored — a problem for small local-LLM context windows.
   const raw = getEnvVar("SUMMARIZE_CHUNK_SIZE");

As per coding guidelines: "No code comments explaining WHAT — use clear naming instead".

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/functions/summarize.ts` around lines 40 - 49, Remove the explanatory
history-style comment inside getChunkSize and replace it with a single-line
comment (or no comment) that states intent succinctly; specifically, trim the
multi-line block that references merged env and process.env precedence and leave
either nothing or a brief note like "Read SUMMARIZE_CHUNK_SIZE via getEnvVar"
near the getChunkSize function which uses getEnvVar, parseInt, and
CHUNK_SIZE_DEFAULT so the behavior remains unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@src/functions/summarize.ts`:
- Around line 40-49: Remove the explanatory history-style comment inside
getChunkSize and replace it with a single-line comment (or no comment) that
states intent succinctly; specifically, trim the multi-line block that
references merged env and process.env precedence and leave either nothing or a
brief note like "Read SUMMARIZE_CHUNK_SIZE via getEnvVar" near the getChunkSize
function which uses getEnvVar, parseInt, and CHUNK_SIZE_DEFAULT so the behavior
remains unchanged.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 76b485cb-3f65-4b7a-b0a6-c05119a9bfc9

📥 Commits

Reviewing files that changed from the base of the PR and between fd9e3bd and 0658ad9.

📒 Files selected for processing (2)
  • src/functions/summarize.ts
  • src/providers/anthropic.ts

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