-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.py
More file actions
99 lines (77 loc) · 3.22 KB
/
Copy pathconfig.py
File metadata and controls
99 lines (77 loc) · 3.22 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from __future__ import annotations
from dataclasses import dataclass
from pathlib import Path
from typing import Dict, List
import yaml
@dataclass(slots=True)
class RootConfig:
system_prompt: str
model_name: str
group_name: str
agent_name: str
context_window_limit: int
@dataclass(slots=True)
class RuntimePromptConfig:
approval_prompt_template: str
todo_prompt_template: str
approval_memory_compact_template: str
@dataclass(slots=True)
class RuntimeConfig:
max_rounds: int
initial_root_todos: List[str]
prompts: RuntimePromptConfig
@dataclass(slots=True)
class Settings:
root: RootConfig
models: List[str]
mcp_executor: str
runtime: RuntimeConfig
@dataclass(slots=True)
class Secrets:
model_bindings: Dict[str, Dict[str, str | int | float]]
def resolve_model_binding(secrets: Secrets, model_name: str) -> tuple[str, str, int, float]:
binding = secrets.model_bindings.get(model_name)
if binding is None:
raise KeyError(f"No model binding found for model '{model_name}' in secrets.yaml")
api_url = str(binding.get("api_url", ""))
api_key = str(binding.get("api_key", ""))
parameter_count = int(binding.get("parameter_count", 0))
price_per_million_tokens = float(binding.get("price_per_million_tokens", 0.0))
return api_url, api_key, parameter_count, price_per_million_tokens
def load_settings(settings_path: Path, secrets_path: Path) -> tuple[Settings, Secrets]:
settings_data = yaml.safe_load(settings_path.read_text(encoding="utf-8"))
secrets_data = yaml.safe_load(secrets_path.read_text(encoding="utf-8"))
root_data = settings_data.get("root", {})
models = list(settings_data.get("models", []))
default_model = str(root_data.get("model_name", models[0] if models else "gpt-5.3-codex"))
root = RootConfig(
system_prompt=str(root_data.get("system_prompt", "")),
model_name=default_model,
group_name=str(root_data.get("group_name", "sudo")),
agent_name=str(root_data.get("agent_name", "root")),
context_window_limit=int(root_data.get("context_window_limit", 8192)),
)
runtime_data = settings_data.get("runtime", {})
prompts_data = runtime_data.get("prompts", {})
initial_root_todos = runtime_data.get("initial_root_todos", [])
if not isinstance(initial_root_todos, list):
initial_root_todos = []
runtime = RuntimeConfig(
max_rounds=int(runtime_data.get("max_rounds", 25)),
initial_root_todos=[str(item) for item in initial_root_todos if str(item).strip()],
prompts=RuntimePromptConfig(
approval_prompt_template=str(prompts_data.get("approval_prompt_template", "")),
todo_prompt_template=str(prompts_data.get("todo_prompt_template", "")),
approval_memory_compact_template=str(prompts_data.get("approval_memory_compact_template", "")),
),
)
settings = Settings(
root=root,
models=models if models else [root.model_name],
mcp_executor=str(settings_data.get("mcp", {}).get("executor", "dry-run")),
runtime=runtime,
)
secrets = Secrets(model_bindings=dict(secrets_data.get("model_bindings", {})))
return settings, secrets