feat: load the env file at start-up, trim schema lookups, remove legacy samples

Start-up
- Export the env file's variables for other libraries (the Cloud provider's
  client) into the process environment; the app's own settings and secrets
  are never exported, and a value already in the environment wins.
- Use GOOGLE_GENAI_USE_ENTERPRISE in place of the deprecated
  GOOGLE_GENAI_USE_VERTEXAI.

Target architect
- Look each distinct resource type up once instead of once per setting: in
  the run of 2026-10-07 it made 39 lookups for 8 types and exhausted its
  budget. terraform_schema's find takes several names; budget 30 to 45.
- A cut-off schema outline says so.

Removed, as leftovers of the original pipeline that nothing read
- terraform/ (no longer passed terraform validate), scripts/validate.sh,
  tests/test_package.py and the CI steps that ran on them.
- The sample outputs under docs/ and requirements.yaml.
- CI now pins Terraform 1.14.3, as the container image does.

Plans record the case 01 run: completed at 100% in 18 minutes with no
Revision, against 60 minutes and warnings before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-07 20:06:58 +01:00
parent 5bb22d984e
commit f1f6f1b83a
34 changed files with 161 additions and 402 deletions

View File

@@ -69,7 +69,7 @@ def default_model_factory(role: RoleSpec) -> BaseLlm:
"""Model for a role's LiteLLM-style id.
`gemini/<model>` uses ADK's native Gemini client, which targets Vertex AI when
GOOGLE_GENAI_USE_VERTEXAI=true (with GOOGLE_CLOUD_PROJECT and
GOOGLE_GENAI_USE_ENTERPRISE=true (with GOOGLE_CLOUD_PROJECT and
GOOGLE_CLOUD_LOCATION) and the Gemini API otherwise. Any other id goes through
LiteLLM, so other model providers need no code changes.
"""

View File

@@ -1,7 +1,10 @@
"""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
@@ -100,9 +103,38 @@ class Settings(BaseSettings):
_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."""
"""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

View File

@@ -187,7 +187,11 @@ class TerraformRunner:
label, root = loaded[resource_type]
title = f"{resource_type} ({label})"
if find:
return ToolResult(_clip(_find_in_schema(title, root, find)))
# Several names in one call: one answer each, and one model request.
names = [name for name in re.split(r"[,\s]+", find) if name]
return ToolResult(
_clip("\n".join(_find_in_schema(title, root, name) for name in names))
)
node = root
for step in [part for part in block.split(".") if part]:
nested = node.get("block_types", {}).get(step)
@@ -199,7 +203,13 @@ class TerraformRunner:
)
node = nested["block"]
heading = f"{title}, block {block}" if block else title
return ToolResult(_clip(_render_schema(heading, node)))
rendered = _render_schema(heading, node)
if len(rendered) > _MAX_OUTPUT:
rendered = (
rendered[:_MAX_OUTPUT]
+ "\n[cut short: use `block` or `find` for what is missing]"
)
return ToolResult(rendered)
def _provider_labels(self) -> str:
return (
@@ -502,8 +512,10 @@ LOCAL_TOOLS: dict[str, tuple[str, str]] = {
"general",
(
"Look up what a Terraform resource type accepts, from the provider's own "
"schema: its arguments and blocks, one block in full with `block`, or "
"whether an argument exists anywhere in it with `find`."
"schema. With `resource_type` alone: every argument and block it has, "
"which is enough to see whether a setting exists. `block` gives one "
"block in full. `find` says where named settings sit, or that the "
"resource type has none."
),
),
}
@@ -580,7 +592,10 @@ def local_tools(
},
"find": {
"type": "string",
"description": "An argument or block name to look for",
"description": (
"Argument or block names to look for; separate several "
"with commas to check them in one call"
),
},
},
"required": ["resource_type"],