From economist-agents
Python coding standards for the economist-agents multi-agent pipeline. Use when writing new Python code, when reviewing PRs for code quality, when configuring linting and type checking.
npx claudepluginhub oviney/economist-agentsThis skill uses the workspace's default tool permissions.
Coding standards for the economist-agents content pipeline. Type hints mandatory, docstrings required, `orjson` not `json`, `logger` not `print()`. All code must pass ruff, mypy, and pytest before commit.
Applies Acme Corporation brand guidelines including colors, fonts, layouts, and messaging to generated PowerPoint, Excel, and PDF documents.
Guides strict Test-Driven Development (TDD): write failing tests first for features, bugfixes, refactors before any production code. Enforces red-green-refactor cycle.
Share bugs, ideas, or general feedback.
Coding standards for the economist-agents content pipeline. Type hints mandatory, docstrings required, orjson not json, logger not print(). All code must pass ruff, mypy, and pytest before commit.
quality-gatestestingmcp-developmentdict[str, Any] for JSON, T | None for nullable. Run mypy.orjson for JSON serialization, never json.logger for output, never print(). Use logging.getLogger(__name__).except:. Catch APIError, JSONDecodeError, etc.with open(...).def f(items: list | None = None), never def f(items=[])..env + os.getenv() only.# Standard library
import logging
from pathlib import Path
from typing import Any
# Third-party
import orjson
from anthropic import Anthropic
# Local
from scripts.validation import validate_agent_output
logger = logging.getLogger(__name__)
AGENT_PROMPT = """You are a research agent..."""
def run_agent(client: Anthropic, topic: dict[str, Any]) -> dict[str, Any]:
"""Run agent with structured output.
Args:
client: Anthropic API client.
topic: Topic dictionary with title and description.
Returns:
Agent output with content and usage keys.
Raises:
APIError: If API call fails after retries.
"""
try:
response = client.messages.create(...)
return {"content": response.content, "usage": response.usage}
except APIError as e:
logger.error("Agent API call failed: %s", e)
raise
def save_output(data: dict[str, Any], path: Path) -> None:
"""Save agent output to JSON."""
with open(path, "wb") as f:
f.write(orjson.dumps(data, option=orjson.OPT_INDENT_2))
ruff format . # Format
ruff check . # Lint
mypy scripts/ # Type check
pytest tests/ -v --cov=scripts --cov-report=term-missing # Test
| Rationalization | Reality |
|---|---|
"json is in the stdlib, why add a dependency?" | orjson is 10x faster and handles bytes natively — agent pipelines serialize constantly |
"print() is fine for debugging" | print() in production code bypasses log levels, can't be filtered, and breaks structured logging |
"Any type is easier" | Any defeats the purpose of type checking — use specific types for agent inputs/outputs |
| "Docstrings are overhead for internal functions" | Internal functions become public when agents compose them — docstrings are the API contract |
| "We'll add type hints later" | Type hints later means mypy debt later; adding them at write time costs 5% more, removing debt costs 50% more |
import json instead of import orjsonprint() used for error reporting or loggingexcept: clausedef f(items=[]))from module import *)pandas used instead of polars for data framesbreakpoint() statementsmypy scripts/ passes with zero errorsdef without preceding docstringorjson used for JSON — evidence: grep -r "import json" scripts/ returns empty (excluding tests)logger used, not print() — evidence: grep -rn "print(" scripts/ returns only non-error outputgrep -rn "except:" scripts/ returns emptyruff format --check . && ruff check . exits 0pytest --cov output