Skip to content

feat: provider-aware context window auto-detection#38

Merged
xinhuagu merged 1 commit into
mainfrom
fix/issue-30-context-window-autodetect
Feb 20, 2026
Merged

feat: provider-aware context window auto-detection#38
xinhuagu merged 1 commit into
mainfrom
fix/issue-30-context-window-autodetect

Conversation

@xinhuagu

@xinhuagu xinhuagu commented Feb 20, 2026

Copy link
Copy Markdown
Owner

Summary

  • Add contextWindowTokens field to ProviderCapabilities with per-provider defaults (Anthropic 200K, OpenAI 128K, CODEX 400K, OPENAI_COMPAT 128K)
  • Change AceClawConfig.DEFAULT_CONTEXT_WINDOW from 200K to 0 (auto-detect)
  • Daemon resolves effective context window from llmClient.capabilities() when config doesn't set it explicitly (value > 0 wins)

Test plan

  • New ProviderCapabilitiesTest — verifies all 4 constants + custom construction
  • Existing daemon E2E tests pass (MockLlmClient inherits OPENAI_COMPAT default)
  • Manual: ./dev.sh copilot now shows context xx/400K instead of xx/200K

Closes #30

Summary by CodeRabbit

  • New Features

    • Context window token capacities now intelligently determined—uses explicit configuration when available, otherwise derives from LLM provider capabilities.
    • Skill descriptions automatically included in system prompts when skills are registered.
  • Tests

    • Added comprehensive test coverage for provider capabilities, including context window tokens and feature support verification.

Add contextWindowTokens to ProviderCapabilities with per-provider defaults
(Anthropic 200K, OpenAI 128K, Codex 400K). Change AceClawConfig default to
0 (auto-detect). Daemon resolves effective context window from provider
capabilities when config doesn't set it explicitly.
@coderabbitai

coderabbitai Bot commented Feb 20, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

The PR implements provider-aware context window auto-detection by adding a contextWindowTokens field to ProviderCapabilities with provider-specific values (ANTHROPIC: 200k, OPENAI: 128k, CODEX: 400k), changing the default config value to 0 for auto-detection, and modifying AceClawDaemon to resolve effective context window from provider capabilities when not explicitly configured.

Changes

Cohort / File(s) Summary
Provider Capabilities Enhancement
aceclaw-core/src/main/java/dev/aceclaw/core/llm/ProviderCapabilities.java, aceclaw-core/src/test/java/dev/aceclaw/core/llm/ProviderCapabilitiesTest.java
Added contextWindowTokens field to ProviderCapabilities record, updated all provider constants with appropriate token limits, and added comprehensive unit tests verifying provider constants and context window values.
Configuration & Runtime Resolution
aceclaw-daemon/src/main/java/dev/aceclaw/daemon/AceClawConfig.java, aceclaw-daemon/src/main/java/dev/aceclaw/daemon/AceClawDaemon.java
Changed default context window from 200k to 0 (enabling auto-detection). Implemented adaptive context window resolution in daemon that prefers explicit config values but falls back to provider capabilities; updated SystemPromptBudget, CompactionConfig, and router initialization to use resolved context window. Added skill description injection into system prompt composition.

Sequence Diagram(s)

sequenceDiagram
    participant Config as AceClawConfig
    participant Daemon as AceClawDaemon
    participant LLM as LLMClient
    participant Caps as ProviderCapabilities
    participant Budget as SystemPromptBudget
    participant Router as Router

    Daemon->>Config: Load configuration<br/>(contextWindowTokens=0 by default)
    Daemon->>LLM: Create LLM client
    LLM->>Caps: Get provider capabilities
    Caps-->>LLM: Return capabilities with<br/>contextWindowTokens
    Daemon->>Daemon: Resolve effective contextWindow:<br/>config value > 0?<br/>YES → use config<br/>NO → use provider capability
    Daemon->>Budget: Initialize with resolved<br/>contextWindow
    Daemon->>Router: Set provider info with<br/>resolved contextWindow
    Daemon->>Daemon: Compose system prompt<br/>+ inject skill descriptions
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 16.67% 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 clearly and concisely describes the main change: implementing provider-aware context window auto-detection as the core feature of this PR.
Linked Issues check ✅ Passed All objectives from issue #30 are implemented: contextWindowTokens field added to ProviderCapabilities with correct per-provider values, AceClawConfig default changed to 0, and AceClawDaemon resolves and uses effective context window everywhere.
Out of Scope Changes check ✅ Passed All changes are directly scoped to resolving issue #30; no unrelated modifications are present in the ProviderCapabilities, AceClawConfig, AceClawDaemon, or new test file.

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

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/issue-30-context-window-autodetect

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

@xinhuagu

Copy link
Copy Markdown
Owner Author

@greptile review

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
aceclaw-daemon/src/main/java/dev/aceclaw/daemon/AceClawConfig.java (1)

223-228: Consider updating the Javadoc example.

The Javadoc mentions "e.g. 200,000 for Claude" but the default is now 0 (auto-detect). Consider updating to clarify that 0 means auto-detect from provider capabilities.

📝 Suggested documentation update
     /**
-     * Returns the context window size in tokens (e.g. 200,000 for Claude).
+     * Returns the context window size in tokens, or 0 if auto-detecting from provider capabilities.
      */
     public int contextWindowTokens() {
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@aceclaw-daemon/src/main/java/dev/aceclaw/daemon/AceClawConfig.java` around
lines 223 - 228, Update the Javadoc for AceClawConfig.contextWindowTokens() to
clarify that the default value 0 means "auto-detect from provider capabilities"
and adjust the example: keep a concrete example like "e.g., 200,000 for Claude"
but explicitly state that non-zero values override auto-detection and 0 triggers
provider-based detection; reference the contextWindowTokens field and the
contextWindowTokens() method in the comment for clarity.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@aceclaw-core/src/main/java/dev/aceclaw/core/llm/ProviderCapabilities.java`:
- Around line 23-37: Update the inline comments for the ProviderCapabilities
constants to remove ambiguity: clarify that CODEX refers specifically to
OpenAI's Codex/Responses models with a 400K context (not GitHub Copilot Chat) by
changing the comment on the CODEX constant to explicitly name "OpenAI Codex /
Responses API (400K)"; and update the OPENAI_COMPAT comment for the
OPENAI_COMPAT constant to state that 128K is a nominal/default value for
OpenAI-compatible providers and that some vendors (e.g., Ollama) expose
configurable windows (roughly 4K–256K) so actual context may vary.

---

Nitpick comments:
In `@aceclaw-daemon/src/main/java/dev/aceclaw/daemon/AceClawConfig.java`:
- Around line 223-228: Update the Javadoc for
AceClawConfig.contextWindowTokens() to clarify that the default value 0 means
"auto-detect from provider capabilities" and adjust the example: keep a concrete
example like "e.g., 200,000 for Claude" but explicitly state that non-zero
values override auto-detection and 0 triggers provider-based detection;
reference the contextWindowTokens field and the contextWindowTokens() method in
the comment for clarity.

Comment on lines +23 to +37
/** Anthropic Claude: full feature support, 200K context. */
public static final ProviderCapabilities ANTHROPIC =
new ProviderCapabilities(true, true, true, 0);
new ProviderCapabilities(true, true, true, 0, 200_000);

/** OpenAI (GPT-4o, o1, etc.): image support, no extended thinking or prompt caching. */
/** OpenAI (GPT-4o, o1, etc.): image support, no extended thinking or prompt caching, 128K context. */
public static final ProviderCapabilities OPENAI =
new ProviderCapabilities(false, false, true, 0);
new ProviderCapabilities(false, false, true, 0, 128_000);

/** Generic OpenAI-compatible providers (Groq, Together, Ollama, etc.): minimal feature set. */
/** Generic OpenAI-compatible providers (Groq, Together, Ollama, etc.): minimal feature set, 128K context. */
public static final ProviderCapabilities OPENAI_COMPAT =
new ProviderCapabilities(false, false, false, 0);
new ProviderCapabilities(false, false, false, 0, 128_000);

/** GitHub Copilot Codex models (Responses API): no extended thinking, no caching, no images. */
/** GitHub Copilot Codex models (Responses API): no extended thinking, no caching, no images, 400K context. */
public static final ProviderCapabilities CODEX =
new ProviderCapabilities(false, false, false, 0);
new ProviderCapabilities(false, false, false, 0, 400_000);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🌐 Web query:

Claude 3.5 context window tokens 2025 Anthropic

💡 Result:

In 2025, Anthropic’s Claude 3.5 models (including Claude 3.5 Sonnet and Claude 3.5 Haiku) have a 200,000-token context window (“200K”). [1]

Anthropic’s 1,000,000-token (1M) context window in 2025 was a separate beta feature available for newer models (e.g., Claude Sonnet 4) via a beta header (e.g., context-1m-2025-08-07), not Claude 3.5. [2]

Sources:
[1] Anthropic Docs – Models overview (context window table) [1]
[2] Anthropic Docs – Context windows / 1M token beta header [2]


🌐 Web query:

GPT-4o context window tokens 2025 OpenAI

💡 Result:

OpenAI’s GPT-4o has a 128,000-token context window (and 16,384 max output tokens per request) in the OpenAI API docs. [1]

Related 4o-family variants (different context sizes):

  • GPT-4o Audio (preview): 128,000 context tokens. [7]
  • GPT-4o Realtime (preview): 32,000 context tokens. [8]
  • GPT-4o Transcribe: 16,000 context tokens. [4]
  • GPT-4o mini: 128,000 context tokens. [5]

🌐 Web query:

GitHub Copilot Codex context window 2025

💡 Result:

  • GitHub Copilot Chat (GitHub.com / Mobile / CLI / supported IDEs): 64k-token context window (when using OpenAI GPT‑4o) per GitHub’s Dec 6, 2024 changelog update (this was the Copilot Chat context-window spec going into 2025). VS Code Insiders could use up to 128k tokens (the max supported by GPT‑4o). [1]
  • OpenAI Codex (Codex agent / Codex CLI / IDE extension): GitHub’s “OpenAI Codex” integration is a Copilot-powered coding agent experience (public preview). [2] The GPT‑5.1‑Codex model used for Codex is documented by OpenAI as having a 400,000-token context window. [3]

Sources: [1] [2] [3]


🌐 Web query:

Groq Together Ollama context window OpenAI compatible 2025

💡 Result:

OpenAI-compatible endpoints (base_url)

  • Groq (GroqCloud): https://api.groq.com/openai/v1 (console.groq.com)
  • Together AI: https://api.together.xyz/v1 (docs.together.ai)
  • Ollama (local): OpenAI-compatible endpoints include /v1/chat/completions (served from your local Ollama host, e.g. http://localhost:11434) (docs.ollama.com)

Context window (what you can expect in/around 2025)

Groq (varies by model; many popular large-context models are 128K):

  • Qwen-2.5-32B: 128K context (groq.com)
  • DeepSeek-r1-distill-qwen-32B: 128K context (groq.com)
  • openai/gpt-oss-120B and openai/gpt-oss-20B: 128K context (groq.com)

Together AI (published per-model; serverless table shows many long-context options):

  • openai/gpt-oss-120b, openai/gpt-oss-20b: 128K context (docs.together.ai)
  • Example of longer options in their serverless catalog (if you need >128K): Moonshot Kimi models listed at 262,144 context (docs.together.ai)

Ollama (depends on the model and your configured/runtime context allocation):

  • Ollama documents default context allocations that scale with VRAM (e.g., <24GiB → 4K; 24–48GiB → 32K; ≥48GiB → 256K) and supports setting context via OLLAMA_CONTEXT_LENGTH=... when serving. (docs.ollama.com)
  • OpenAI-compat endpoints are supported (e.g. /v1/chat/completions). (docs.ollama.com)

Citations:


Clarify CODEX context window claim and OPENAI_COMPAT variability.

Current values are largely accurate for 2025:

  • ANTHROPIC 200K: ✅ Correct (Claude 3.5 standard context)
  • OPENAI 128K: ✅ Correct (GPT-4o documented context)
  • CODEX 400K: The OpenAI Codex model has 400K context, but the comment "GitHub Copilot Codex models (Responses API)" is ambiguous—GitHub Copilot Chat uses 64K (based on GPT-4o), while OpenAI's Codex model itself has 400K. Clarify which service this constant represents.
  • OPENAI_COMPAT 128K: Reasonable baseline (Groq, Together AI offer 128K), but Ollama's context window is configurable (4K–256K range depending on hardware/settings). Consider documenting that 128K is a nominal default for this category.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@aceclaw-core/src/main/java/dev/aceclaw/core/llm/ProviderCapabilities.java`
around lines 23 - 37, Update the inline comments for the ProviderCapabilities
constants to remove ambiguity: clarify that CODEX refers specifically to
OpenAI's Codex/Responses models with a 400K context (not GitHub Copilot Chat) by
changing the comment on the CODEX constant to explicitly name "OpenAI Codex /
Responses API (400K)"; and update the OPENAI_COMPAT comment for the
OPENAI_COMPAT constant to state that 128K is a nominal/default value for
OpenAI-compatible providers and that some vendors (e.g., Ollama) expose
configurable windows (roughly 4K–256K) so actual context may vary.

@greptile-apps

greptile-apps Bot commented Feb 20, 2026

Copy link
Copy Markdown

Greptile Summary

This PR implements provider-aware context window auto-detection by adding a contextWindowTokens field to ProviderCapabilities and defaulting AceClawConfig.DEFAULT_CONTEXT_WINDOW to 0. When the daemon starts, it resolves the effective context window by preferring explicit config values over provider defaults from llmClient.capabilities().

Key changes:

  • Added contextWindowTokens parameter to ProviderCapabilities record with sensible defaults (Anthropic 200K, OpenAI/OPENAI_COMPAT 128K, CODEX 400K)
  • Changed DEFAULT_CONTEXT_WINDOW from 200K to 0 to enable auto-detection
  • Daemon resolves context window via config.contextWindowTokens() > 0 ? config.contextWindowTokens() : llmClient.capabilities().contextWindowTokens()
  • All downstream uses (SystemPromptBudget, CompactionConfig, router) correctly use the resolved value
  • Comprehensive test coverage for all provider constants and custom construction
  • Includes unrelated skill description injection feature (lines 247-254 in AceClawDaemon.java) not mentioned in PR description

The implementation is clean, well-tested, and backward compatible (explicit config still wins). The auto-detection logic is straightforward and correctly propagated throughout the daemon initialization.

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • Clean implementation with comprehensive test coverage, backward compatibility maintained, and all existing integration tests should pass (MockLlmClient inherits OPENAI_COMPAT default of 128K)
  • No files require special attention - all changes are straightforward and well-tested

Important Files Changed

Filename Overview
aceclaw-core/src/main/java/dev/aceclaw/core/llm/ProviderCapabilities.java Added contextWindowTokens field with provider-specific defaults (Anthropic 200K, OpenAI 128K, OPENAI_COMPAT 128K, CODEX 400K)
aceclaw-core/src/test/java/dev/aceclaw/core/llm/ProviderCapabilitiesTest.java Comprehensive test coverage for all provider constants and custom construction with contextWindowTokens field
aceclaw-daemon/src/main/java/dev/aceclaw/daemon/AceClawConfig.java Changed DEFAULT_CONTEXT_WINDOW from 200K to 0 to enable auto-detection from provider capabilities
aceclaw-daemon/src/main/java/dev/aceclaw/daemon/AceClawDaemon.java Implements context window auto-detection from llmClient.capabilities(), uses resolved value throughout daemon initialization, includes unrelated skill description injection

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    Start[Daemon Startup] --> LoadConfig[Load AceClawConfig]
    LoadConfig --> CheckConfig{config value > 0?}
    CheckConfig -->|Yes| UseConfig[Use explicit config]
    CheckConfig -->|No DEFAULT=0| CreateClient[Create LlmClient]
    CreateClient --> GetCap[Get capabilities]
    GetCap --> ExtractCtx[Extract contextWindowTokens]
    ExtractCtx --> UseProvider[Use provider default]
    UseConfig --> SetCtx[contextWindow variable]
    UseProvider --> SetCtx
    SetCtx --> LogSrc[Log source: config or auto-detected]
    LogSrc --> UseBudget[SystemPromptBudget]
    UseBudget --> UseCompact[CompactionConfig]
    UseCompact --> UseRouter[router.setProviderInfo]
    UseRouter --> Ready[Daemon Ready]
Loading

Last reviewed commit: 704d07f

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

4 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Comment on lines +247 to +254
// 5b. Inject skill descriptions into system prompt so the LLM knows
// what each skill does and when to invoke it proactively.
if (!skillRegistry.isEmpty()) {
String skillDescriptions = skillRegistry.formatDescriptions();
if (!skillDescriptions.isEmpty()) {
systemPrompt = systemPrompt + "\n\n" + skillDescriptions;
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

unrelated change - skill description injection (lines 247-254) is not mentioned in PR description and should be in a separate commit

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@xinhuagu xinhuagu merged commit 7da343a into main Feb 20, 2026
2 checks passed
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.

Provider-aware context window auto-detection (Codex 400K shows as 200K)

1 participant