Repository navigation
Expand file tree
/
Copy pathsettings.py
More file actions
61 lines (48 loc) · 2.59 KB
/
Copy pathsettings.py
File metadata and controls
61 lines (48 loc) · 2.59 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
"""Settings for the Research Demo application."""
from pathlib import Path
from pydantic_settings import SettingsConfigDict
from agentic_cli import BaseSettings
class ResearchDemoSettings(BaseSettings):
"""Settings for the Research Demo application.
Demonstrates all P0/P1 features with memory, planning, and HITL.
Settings are loaded from (highest precedence first):
1. Constructor arguments
2. Environment variables (``RESEARCH_DEMO_*`` prefix)
3. Project config ``./.research_demo/settings.json`` — **untrusted**: a
cloned repo can ship one, so only an explicit allowlist of benign keys
is honoured and security-sensitive keys are dropped with a warning
4. User config ``~/.research_demo/settings.json`` (trusted)
5. ``~/.research_demo/.env`` — trusted because the path is absolute; a
cwd-relative ``.env`` would be filtered like the project config, so put
API keys here or in real environment variables
6. Field defaults (including the ones set in ``model_post_init`` below)
JSON sources are only consulted when the file exists.
"""
model_config = SettingsConfigDict(
env_file=str(Path.home() / ".research_demo" / ".env"),
env_prefix="RESEARCH_DEMO_",
extra="ignore",
)
def __init__(self, **kwargs):
kwargs.setdefault("app_name", "research_demo")
kwargs.setdefault("workspace_dir", Path.home() / ".research_demo")
super().__init__(**kwargs)
def model_post_init(self, __context):
"""Override verbose_thinking default without blocking JSON persistence.
kwargs.setdefault would inject at init level (highest priority),
overriding saved JSON values. model_post_init runs after all sources
are resolved, and model_fields_set tracks which fields were explicitly
set by any source (env, JSON, init kwargs). We only apply our custom
default when no source provided a value.
"""
if "verbose_thinking" not in self.model_fields_set:
object.__setattr__(self, "verbose_thinking", False)
if "sandbox_data_mounts" not in self.model_fields_set:
data_dir = Path(__file__).parent / "data"
object.__setattr__(self, "sandbox_data_mounts", [f"{data_dir}:samples"])
if "sandbox_outputs_dir" not in self.model_fields_set:
object.__setattr__(self, "sandbox_outputs_dir", str(Path(self.workspace_dir) / "artifacts"))
if "skills_dirs" not in self.model_fields_set:
object.__setattr__(
self, "skills_dirs", [str(Path(__file__).parent / "skills")]
)