Generate Architectural Guardrails for Autonomous Code Agents

Create a strictly defined AGENTS.md file that forces autonomous coding agents like Codex to adhere to your project's specific architectural constraints and style rules.

Agent prompt for ChatGPT and Cursor

Prompt

Prompt
Act as a Senior Software Architect. Your task is to write a technical AGENTS.md document that defines hard constraints for an autonomous coding agent refactoring a repository. Ask me these 3 questions first: 1. What is the primary programming language and framework? 2. What are 3 specific architectural rules (e.g., no global state, specific folder depth)? 3. What are the strict naming conventions for files and classes? After I answer, provide the guide. Rules: 1. Use imperative, unambiguous language for each constraint. 2. Define exactly one forbidden pattern and one mandatory pattern per section. 3. Include a section on AST-verifiable rules that a linter could check. 4. Do not include introductory fluff. Output format: # Agent Architectural Constraints, ## 1. Code Structure Rules, ## 2. Naming and Pattern Standards, ## 3. Forbidden Dependencies, ## 4. Automated Verification Criteria. This guide is for technical guidance and does not replace human code review.

Example output

Example for: a Python FastAPI project with strict modularity requirements.

Agent Architectural Constraints

1. Code Structure Rules

  • Modules must not exceed 300 lines of code. Split logic into sub-modules if limits are reached.
  • Maintain a flat dependency graph: Services may only import Repositories and Schemas. Direct cross-service imports are prohibited.
  • All business logic must reside in the services layer. Controllers must only handle request validation and response formatting.

2. Naming and Pattern Standards

  • File names must follow snake_case format (e.g., user_service.py).
  • Class names must use PascalCase (e.g., UserAuthenticationService).
  • Private helper methods must start with a single underscore.
  • Use Type Hinting for all function arguments and return types.

3. Forbidden Dependencies

  • Do not import the 'os' module directly; use 'pathlib' for all filesystem interactions.
  • External API clients must be wrapped in a dedicated 'infrastructure' adapter; do not call 'requests' or 'httpx' inside core domain models.
  • Avoid global variables or module-level state constants; use configuration objects instead.

4. Automated Verification Criteria

  • AST Linter Check: Ensure no file contains more than 10 imports.
  • AST Linter Check: Verify that all classes inherit from a base class if defined in the domain layer.
  • AST Linter Check: Scan for 'import os' and flag as a blocking error.
  • Cyclomatic Complexity: No function shall have a complexity score higher than 5.
Written by AI from this prompt. Your results will vary.

Tips and common edits

Why this works

  • Forces the AI to define clear, verifiable rules rather than vague suggestions.
  • Categorizes constraints into structural, naming, and dependency domains for clarity.
  • Includes a section specifically for AST-verifiable rules to enable automated compliance.

Use this prompt when preparing a repository for autonomous refactoring or AI-assisted coding in ChatGPT or Cursor. Paste the output into the root directory as AGENTS.md to ensure the AI agent follows your project's specific architectural guardrails.

Common edits

  • Adjust the line count limits based on your team's specific complexity preferences.
  • Add specific security rules if the agent is working on sensitive authentication modules.

Reuse it: Use in a workflowAdapt in the builder

Prompt details

By
Prompts-GPT editors
Published
How prompts are written and checked

Did this prompt work?

More in Codex
Agent Orchestration

Create Error Handling Contracts for AI Agents

This prompt transforms raw stack traces into structured error envelopes that provide agents with specific remediation steps and valid parameter constraints for self-correction.

Generate Scoped Cursor Rules for Project Architecture

Create targeted .cursorrules files that enforce strict architectural boundaries between frontend, API, and database layers to prevent code leaks.

Compare Three Feature Architectures Against Module Boundaries

Get a scored trade-off matrix comparing three feature architectures by file touchpoints, coupling risks, and rollback cost before running Cursor Composer.

Agentic AIClaude

Incident Recovery Playbook for Rogue AI Agent Loops

Generate a three-tier operational escalation matrix to stop runaway AI agent loops, manage costs, and communicate with stakeholders during a production incident.

Turn Sentry Errors into Reproducible Codex Test Cases

Transforms a production Sentry stack trace and context payload into a self-contained failing unit test designed for Codex repo tasks.