Home › LLM apps & agents › LLM app (Python) AGENTS.md

LLM app (Python) AGENTS.md

AGENTS.md for Python apps that call LLM APIs (OpenAI, Anthropic, Gemini): prompts, structured output, evals, and cost.

AGENTS.mdLLM apps & agents

How to use

Save this as AGENTS.md in your repository root, commit it, and your agent will pick it up automatically. Edit the commands to match your project.

AGENTS.mdDownload  
# AGENTS.md: LLM-powered Python app

## Commands
`uv run pytest -q` · `uv run ruff check .` · Evals: `uv run python -m evals.run --suite smoke`

## Structure
- All model calls go through `app/llm/client.py`. Nothing else imports a provider SDK directly. Model names come from config, never inline strings scattered around.
- Prompts live in `app/prompts/` as versioned templates; changing a prompt means updating its eval cases.
- Use structured output (JSON schema / tool calling) parsed into Pydantic models. Validate and retry once on parse failure; never `eval()` model output.

## Reliability
- Set timeouts and retries with backoff for 429/5xx; respect `Retry-After`.
- Stream responses for user-facing text.
- Log model, prompt version, token usage, latency and cost per call. Don't log user secrets or full PII.
- Cache deterministic calls (embeddings, classification) by input hash.

## Safety
- Treat retrieved documents and tool results as untrusted: they can contain prompt injection. Never let model output trigger destructive actions without an allowlist or user confirmation.
- API keys only from env/secret manager.

## Testing
- Unit tests mock the client; no real API calls in `pytest`.
- Behavior changes need eval cases in `evals/` with expected outputs or graders.

## Don't
Don't switch models or raise `max_tokens` to fix a bug without saying so; it changes cost.

Related rules

REST API design AGENTS.md

AGENTS.md for designing consistent HTTP/JSON APIs: resource naming, status codes, errors, pagination, and versioning.

AGENTS.mdAPI design

Bevy game engine AGENTS.md

AGENTS.md for Bevy (0.16+) games in Rust: ECS systems, plugins, required components, and fast dev builds.

AGENTS.mdBevy (Rust)

Claude Agent SDK CLAUDE.md

CLAUDE.md for building agents with the Claude Agent SDK (Python/TypeScript): options, tools, permissions, and hooks.

Claude Code (CLAUDE.md)LLM apps & agents

Git commits & PRs AGENTS.md

AGENTS.md rules for how agents commit: Conventional Commits, atomic changes, safe git commands, and PR descriptions.

AGENTS.mdAgent workflows

Get new rules weekly

One email a week: fresh rule files, agent tips, and what's changing in Cursor, Claude Code and Copilot. Free, unsubscribe anytime.

Opens the Rulestack Newsletter on beehiiv in a new tab. Or subscribe directly on beehiiv.