Files
gcp_solution_architecture_a…/app/config.py
Jonathan Boniface 5adc911a82 feat: keep an unchanged description, list conditions, review coverage with Jev
After case 02 (completed at 100%, but with two Revisions of the Target
architecture for gaps validation found one pass at a time):

- A Deliverable stands while what it was written from is unchanged. The
  architecture description is written from the Elements and Relationships,
  so a Revision that only adds or rewords Checks no longer runs the describer.
- Non-functional requirements and recommendations list their conditions,
  one entry per separate thing that must be true; submission requires them.
- A coverage review at submission (JEV_COVERAGE_REVIEW, off by default):
  for each condition, Jev chooses which Check verifies it, or none. Asked as
  one broad yes-or-no per requirement it could not tell a complete design
  from one with known gaps; asked as a choice per condition it raised all
  four known gaps of case 02 and nothing on the complete graph. An opt-in
  live test (LIVE_JEV=1) repeats that.
- The validator is told to report every gap in its first pass.

Plans record the case 02 run and both forms of the review with figures.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-07 20:58:38 +01:00

146 lines
5.9 KiB
Python

"""Typed settings for GCP Solution Architecture Agent."""
import os
from collections.abc import MutableMapping
from pathlib import Path
from dotenv import dotenv_values
from pydantic_settings import BaseSettings, SettingsConfigDict
class Settings(BaseSettings):
"""Application Settings."""
model_config = SettingsConfigDict(
env_file=".env",
env_file_encoding="utf-8",
extra="ignore",
)
# Agent Identity
AGENT_NAME: str = "gcp_solution_architecture_agent"
AGENT_VERSION: str = "1.0.0"
LOG_LEVEL: str = "INFO"
# Database & Storage Settings (External PostgreSQL, SQLite fallback)
POSTGRES_HOST: str = "localhost"
POSTGRES_PORT: int = 5432
POSTGRES_DB: str = "gcp_agent_db"
POSTGRES_USER: str = "postgres"
POSTGRES_PASSWORD: str = "postgres"
DATABASE_URL: str | None = None
SQLITE_FALLBACK_DB: str = "gcp_agent_local.db"
# Cloud Provider Bundle (providers/<name>.yaml) & Remote MCP Servers
CLOUD_PROVIDER: str = "gcp"
MCP_ENABLED: bool = True
MCP_ENABLE_PREVIEW: bool = True
MCP_QUOTA_PROJECT: str | None = None # defaults to the ADC project
MCP_TIMEOUT_SECONDS: float = 30
# Local Terraform tools (fmt, validate, plan; never apply)
TERRAFORM_BINARY: str = "terraform"
TERRAFORM_TIMEOUT_SECONDS: float = 300
# Where Terraform providers are kept between checks, so they download once.
# Relative paths are under the repository root. Set it empty to disable the cache.
TF_PLUGIN_CACHE_DIR: str = ".cache/terraform-plugins"
# Models: a request with no response in this time is abandoned and retried
MODEL_TIMEOUT_SECONDS: float = 180
# Hierarchical Execution Engine (LangGraph state, ReAct agents)
A2A_HOST: str = "0.0.0.0"
A2A_PORT: int = 8000
A2A_PUBLIC_URL: str | None = None # advertised in the agent card
ORCHESTRATOR_BUDGET: int = 40
SPECIALIST_BUDGET: int = 15
MAX_REVISIONS: int = 3
MAX_ORCHESTRATOR_TURNS: int = 100
# How an Orchestrator turn is decided (ADR-0007): "router" reads the Execution
# and follows its playbook, with Jev for the judgements; "model" has a language
# model choose the tool calls, as before, and is kept for comparison.
ORCHESTRATOR: str = "router"
# Agent runs in flight at once, pillar advisors included (model rate limits)
MAX_PARALLEL_SPECIALISTS: int = 4
CHECKPOINTER: str = "sqlite" # memory | sqlite | postgres
CHECKPOINT_DB_PATH: str = "checkpoints.db"
# Jev decision service (ADR-0007), reached through TypeSafe AI's Python SDK.
# With no key, every decision takes its fallback and the agent behaves as it does
# without Jev. The key comes from the environment or a secret store, never from
# the provider bundle or the repository.
TYPESAFE_API_KEY: str | None = None
TYPESAFE_BASE_URL: str | None = None # None: the SDK's default endpoint
TYPESAFE_DEFAULT_MODEL: str | None = None # None: the SDK's default model
JEV_TIMEOUT_SECONDS: float = 5.0 # one request
JEV_REQUESTS_PER_SECOND: float = 5.0
JEV_MAX_IN_FLIGHT: int = 8
JEV_BUDGET_CALLS: int = 500 # per Execution
JEV_BUDGET_TOKENS: int = 1_000_000 # per Execution
# A probability at or above ACT is acted on; at or below CLOSE is dropped; in
# between, the user is asked. A choice below CONFIDENCE is not relied on.
JEV_ACT_THRESHOLD: float = 0.75
JEV_CLOSE_THRESHOLD: float = 0.15
JEV_CONFIDENCE_THRESHOLD: float = 0.6
# Review a design's coverage at submission: for each condition a requirement
# lists, which Check verifies it. Off until a full case has run with it.
JEV_COVERAGE_REVIEW: bool = False
# How likely "no Check verifies this" must be before the condition is raised.
JEV_COVERAGE_THRESHOLD: float = 0.6
# Paths
BASE_DIR: Path = Path(__file__).resolve().parent.parent
def terraform_plugin_cache(self) -> str | None:
"""The provider cache directory as an absolute path; None when disabled."""
if not self.TF_PLUGIN_CACHE_DIR.strip():
return None
path = Path(self.TF_PLUGIN_CACHE_DIR).expanduser()
return str(path if path.is_absolute() else self.BASE_DIR / path)
def get_database_url(self) -> str:
"""Construct database connection URL (PostgreSQL or SQLite fallback)."""
if self.DATABASE_URL:
return self.DATABASE_URL
return f"postgresql://{self.POSTGRES_USER}:{self.POSTGRES_PASSWORD}@{self.POSTGRES_HOST}:{self.POSTGRES_PORT}/{self.POSTGRES_DB}"
_settings: Settings | None = None
def export_env_file(
path: str | Path = ".env", environ: MutableMapping[str, str] | None = None
) -> list[str]:
"""Put the env file's other variables into the process environment.
Settings reads its own fields from the env file. Everything else in it is for a
library that reads the environment itself, such as a Cloud provider's client
looking for its project and credentials, and would otherwise be ignored. A
variable already set in the environment is left alone, and Settings' own fields
are never exported, so the secrets among them do not reach child processes.
Returns the names it set.
"""
environ = os.environ if environ is None else environ
path = Path(path)
if not path.is_file():
return []
own = {name.upper() for name in Settings.model_fields}
exported = []
for name, value in dotenv_values(path).items():
if value is None or name.upper() in own or name in environ:
continue
environ[name] = value
exported.append(name)
return exported
def get_settings() -> Settings:
"""Get singleton Settings instance, loading the env file at first use."""
global _settings
if _settings is None:
# Tests switch this off so they never depend on a developer's env file.
if os.environ.get("ENV_FILE_EXPORT", "true").lower() != "false":
export_env_file()
_settings = Settings()
return _settings