Primera fase context

This commit is contained in:
Jordan Diaz
2026-04-09 18:27:36 +00:00
parent 993e7d3000
commit 4c73d848bb
8 changed files with 424 additions and 40 deletions

View File

@@ -38,10 +38,19 @@ class Settings(BaseSettings):
temperature: float = 0.3
# --- Context engine ---
context_max_tokens: int = 120_000
compaction_threshold_tokens: int = 80_000
model_context_window: int = 0 # 0 = use legacy fixed budget / explicit override
model_max_output_tokens: int = 4096
context_max_tokens: int = 0 # 0 = auto-budget from model window, fallback legacy 120k
compaction_threshold_tokens: int = 0 # 0 = derive from ratio
compaction_threshold_ratio: float = 0.80
context_reserve_ratio: float = 0.10
artifact_summary_max_chars: int = 2000
knowledge_base_max_tokens: int = 30_000
working_context_max_items: int = 20
tool_raw_output_max_chars: int = 2000
conversation_recent_raw_limit: int = 2
task_history_max_entries: int = 20
task_history_max_tokens: int = 1500
# --- MCP ---
mcp_config_path: str = "" # Path to mcp.json; empty = legacy single-server mode
@@ -64,5 +73,32 @@ class Settings(BaseSettings):
model_config = {"env_prefix": "AGENTIC_", "env_file": ".env", "extra": "ignore"}
@property
def reserve_tokens(self) -> int:
if self.model_context_window <= 0:
return 0
return max(0, int(self.model_context_window * self.context_reserve_ratio))
@property
def effective_context_budget(self) -> int:
if self.context_max_tokens > 0:
return self.context_max_tokens
if self.model_context_window > 0:
budget = (
self.model_context_window
- max(0, self.model_max_output_tokens)
- self.reserve_tokens
)
return max(1, budget)
return 120_000
@property
def effective_compaction_threshold(self) -> int:
if self.compaction_threshold_tokens > 0:
return min(self.compaction_threshold_tokens, self.effective_context_budget)
return max(1, int(self.effective_context_budget * self.compaction_threshold_ratio))
settings = Settings()