Files
gcp_solution_architecture_a…/app/config.py
Jonathan Boniface 654370bb46 feat: all four evaluation cases pass; intake, checklist review, thresholds
Case 04 (interactive)
- A scripted answer may name who it is for, so facts written for
  requirements discovery are not given to a Specialist confirming a draft.
- A reply that restates what the agreed requirements already say is read
  as an answer, not a request for changes.
- With a user present, a first submission is refused until the user has
  been shown a draft of that Deliverable (CONFIRM_DRAFTS).

Routing and reviews
- Intake: a message that starts something is read first. A question is
  answered and starts nothing; a change to delivered work starts as a new
  request with a note, until Change requests are built.
- Requirements and recommendations list what infrastructure code can show
  (conditions) apart from what it cannot (outside_code); the latter needs
  no Check and validation proposes nothing for it.
- A requirements review, "names no products", behind its own switch (off).
- Each pillar advisor reviews its pillar's checklist; the engine writes the
  reviews into the design recommendations. The judged checklist check went
  from 9-45% a pillar to 100% in one run of case 04.

Evaluation
- Per-case thresholds for Revisions, seconds and tokens, set from every
  completed run on this build.
- A progress file after every agent run, so an interrupted run keeps its
  time and tokens.
- eval/calibrate_judge.py with a 32-question set awaiting a person's
  labels. Unlabelled: Jev stable at 1.00, Gemini 0.92, agreeing on 0.91.

Smaller
- An Execution that ends with warnings writes its Deliverables, with the
  warnings and each status in the manifest.
- CI installs the application's dependencies before linting and testing.
- A load-balancer pattern in the IaC patterns Skill.

Plans record nine runs of 2026-10-08. Iteration 6 is complete.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-09 09:32:57 +01:00

153 lines
6.3 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
# With a user present, a Specialist's first submission of a Deliverable is refused
# until it has put its draft to them. Off: Specialists are only told to.
CONFIRM_DRAFTS: bool = True
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
# Review the requirements at submission: does any name a cloud product? Off
# until a full case has run with it.
JEV_REQUIREMENTS_REVIEW: bool = False
JEV_REQUIREMENTS_THRESHOLD: float = 0.3
# 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