-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.py
More file actions
83 lines (67 loc) · 3.12 KB
/
config.py
File metadata and controls
83 lines (67 loc) · 3.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
from __future__ import annotations
import os
from dataclasses import dataclass
from dotenv import load_dotenv
@dataclass(frozen=True)
class CortexConfig:
anthropic_api_key: str
# "Decider" is used for early gate tests / cheaper loops; "heavy" for dense FL tasks.
model_decider: str
model_heavy: str
# Critic is used by posttask reflection/patch proposal. Default to heavy model for quality.
model_critic: str
# Dedicated visual judge for FL end-of-run screenshot adjudication.
model_visual_judge: str
# What the model sees as the "screen" coordinate space.
display_width_px: int
display_height_px: int
# Prompt caching beta.
enable_prompt_caching: bool
# Computer Use tool + beta flags vary by model family.
# Current mapping in agent.py: Opus 4.6/4.5 -> computer_20251124 (zoom),
# Sonnet/Haiku lines -> computer_20250124 (no zoom).
computer_tool_type_decider: str
computer_tool_type_heavy: str
computer_use_beta_decider: str
computer_use_beta_heavy: str
prompt_caching_beta: str
token_efficient_tools_beta: str
def _getenv_int(name: str, default: int) -> int:
raw = os.getenv(name, "").strip()
if not raw:
return default
return int(raw)
def load_config(*, require_api_key: bool = True) -> CortexConfig:
# Local .env is gitignored; allow it to exist without leaking into git.
load_dotenv(override=False)
api_key = os.getenv("ANTHROPIC_API_KEY", "").strip()
if require_api_key and not api_key:
raise RuntimeError("ANTHROPIC_API_KEY is missing (set it in .env).")
display_width_px = _getenv_int("CORTEX_DISPLAY_WIDTH_PX", 1024)
display_height_px = _getenv_int("CORTEX_DISPLAY_HEIGHT_PX", 768)
model_decider = os.getenv("CORTEX_MODEL_DECIDER", "claude-haiku-4-5").strip()
model_heavy = os.getenv("CORTEX_MODEL_HEAVY", "claude-opus-4-6").strip()
model_critic = os.getenv("CORTEX_MODEL_CRITIC", model_heavy).strip()
model_visual_judge = os.getenv("CORTEX_MODEL_VISUAL_JUDGE", model_heavy).strip()
enable_prompt_caching = os.getenv("CORTEX_ENABLE_PROMPT_CACHING", "1").strip() not in (
"",
"0",
"false",
"False",
)
return CortexConfig(
anthropic_api_key=api_key,
model_decider=model_decider,
model_heavy=model_heavy,
model_critic=model_critic,
model_visual_judge=model_visual_judge,
display_width_px=display_width_px,
display_height_px=display_height_px,
enable_prompt_caching=enable_prompt_caching,
computer_tool_type_decider=os.getenv("CORTEX_COMPUTER_TOOL_DECIDER", "computer_20250124").strip(),
computer_tool_type_heavy=os.getenv("CORTEX_COMPUTER_TOOL_HEAVY", "computer_20251124").strip(),
computer_use_beta_decider=os.getenv("CORTEX_COMPUTER_BETA_DECIDER", "computer-use-2025-01-24").strip(),
computer_use_beta_heavy=os.getenv("CORTEX_COMPUTER_BETA_HEAVY", "computer-use-2025-11-24").strip(),
prompt_caching_beta="prompt-caching-2024-07-31",
token_efficient_tools_beta=os.getenv("CORTEX_TOKEN_EFFICIENT_TOOLS_BETA", "token-efficient-tools-2025-02-19").strip(),
)