chore(context): refactor for consistency, optimize formatting, and simplify logic

- Cleaned up unnecessary comments in `__all__` definitions for better readability.
- Adjusted indentation and formatting across modules for improved clarity (e.g., long lines, logical grouping).
- Simplified conditional expressions and inline comments for context scoring and ranking.
- Replaced some hard-coded values with type-safe annotations (e.g., `ClassVar`).
- Removed unused imports and ensured consistent usage across test files.
- Updated `test_score_not_cached_on_context` to clarify caching behavior.
- Improved truncation strategy logic and marker handling.
This commit is contained in:
2026-01-04 15:23:14 +01:00
parent 9e54f16e56
commit 2bea057fb1
26 changed files with 226 additions and 273 deletions

View File

@@ -5,7 +5,7 @@ Abstract base class for model-specific context formatting.
"""
from abc import ABC, abstractmethod
from typing import Any
from typing import Any, ClassVar
from ..types import BaseContext, ContextType
@@ -19,7 +19,7 @@ class ModelAdapter(ABC):
"""
# Model name patterns this adapter handles
MODEL_PATTERNS: list[str] = []
MODEL_PATTERNS: ClassVar[list[str]] = []
@classmethod
def matches_model(cls, model: str) -> bool:
@@ -125,7 +125,7 @@ class DefaultAdapter(ModelAdapter):
Uses simple plain-text formatting with minimal structure.
"""
MODEL_PATTERNS: list[str] = [] # Fallback adapter
MODEL_PATTERNS: ClassVar[list[str]] = [] # Fallback adapter
@classmethod
def matches_model(cls, model: str) -> bool:

View File

@@ -5,7 +5,7 @@ Provides Claude-specific context formatting using XML tags
which Claude models understand natively.
"""
from typing import Any
from typing import Any, ClassVar
from ..types import BaseContext, ContextType
from .base import ModelAdapter
@@ -25,7 +25,7 @@ class ClaudeAdapter(ModelAdapter):
- Tool result wrapping with tool names
"""
MODEL_PATTERNS: list[str] = ["claude", "anthropic"]
MODEL_PATTERNS: ClassVar[list[str]] = ["claude", "anthropic"]
def format(
self,

View File

@@ -5,7 +5,7 @@ Provides OpenAI-specific context formatting using markdown
which GPT models understand well.
"""
from typing import Any
from typing import Any, ClassVar
from ..types import BaseContext, ContextType
from .base import ModelAdapter
@@ -25,7 +25,7 @@ class OpenAIAdapter(ModelAdapter):
- Code blocks for tool outputs
"""
MODEL_PATTERNS: list[str] = ["gpt", "openai", "o1", "o3"]
MODEL_PATTERNS: ClassVar[list[str]] = ["gpt", "openai", "o1", "o3"]
def format(
self,