dels. This allows you to swap providers without changing prompts.
File: ai-workflow.config.json
{
"version": "1.0",
"routing": {
"strategies": {
"quick_edit": {
"model": "gpt-4o-mini",
"max_tokens": 2048,
"description": "Inline fixes, minor refactors, comment generation"
},
"feature_impl": {
"model": "claude-sonnet-4",
"max_tokens": 8192,
"description": "New components, API endpoints, standard logic"
},
"architecture": {
"model": "claude-opus-4.6",
"max_tokens": 16384,
"description": "Cross-module changes, design decisions, complex debugging"
},
"cost_saver": {
"model": "gemini-flash-2",
"max_tokens": 4096,
"description": "Documentation, test scaffolding, boilerplate"
}
},
"fallback_chain": ["claude-sonnet-4", "gpt-4o", "gemini-flash-2"]
},
"context": {
"max_files": 50,
"exclude_patterns": ["**/bin/**", "**/obj/**", "**/node_modules/**", "**/*.min.js"]
}
}
Rationale:
- Granular Routing: Assigning
gpt-4o-mini to quick edits prevents burning expensive tokens on trivial changes.
- Fallback Chain: Ensures continuity if a primary provider experiences latency or rate limiting.
- Context Limits: Explicitly bounding file counts prevents context window overflow, which degrades model performance.
2. Implement Persistent Context
Agents lose state between sessions. To maintain productivity, inject a structured context file that acts as the "source of truth" for the project. This file should be version-controlled and updated by the team.
File: AGENTS.md
# Project Context: Enterprise Inventory System
## Tech Stack
- **Backend:** .NET 8, ASP.NET Core, Entity Framework Core, MediatR (CQRS)
- **Frontend:** React 18, TypeScript, React Query, Tailwind CSS
- **Database:** PostgreSQL
- **Auth:** JWT with Refresh Tokens
## Domain Rules
- Inventory counts must be updated within a transaction scope.
- All API responses must wrap data in a standard `Result<T>` envelope.
- React components must use functional patterns with strict TypeScript interfaces.
## Coding Standards
- **Naming:** PascalCase for classes/methods, camelCase for variables.
- **Error Handling:** Use global exception middleware; never swallow exceptions.
- **Testing:** xUnit for .NET, Vitest for React. Coverage threshold: 80%.
## Common Commands
- Build: `dotnet build && npm run build`
- Test: `dotnet test && npm run test`
- Migrate: `dotnet ef database update`
Rationale:
- Domain Rules: Prevents agents from generating code that violates business logic.
- Standardization: Enforces consistency across agents that might otherwise drift in style.
- Command Reference: Reduces hallucination regarding build/test scripts.
3. Establish Quality Gates
Automated hooks are non-negotiable in production. Configure the agent environment to run validation before committing changes.
File: .husky/pre-commit
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
# Run linting and type checking
npm run lint:fix
npm run type-check
# Run backend tests
dotnet test --no-build --verbosity quiet
# Ensure no TODO comments from agents remain
if grep -r "TODO: AI" --include="*.cs" --include="*.tsx" .; then
echo "Error: AI-generated TODOs found. Resolve before committing."
exit 1
fi
Rationale:
- Automated Validation: Catches syntax errors and type mismatches immediately.
- Artifact Removal: Prevents AI placeholders from leaking into the codebase.
- Consistency: Ensures all code, regardless of origin, meets the same standards.
Pitfall Guide
-
Context Overflow
- Explanation: Loading entire directories or irrelevant files into the agent's context window causes attention dilution, leading to hallucinations and slower responses.
- Fix: Use strict indexing allowlists and exclude patterns. Regularly prune
AGENTS.md to keep it concise.
-
Model Mismatch
- Explanation: Using a high-reasoning model like Opus 4.6 for simple tasks like renaming variables wastes budget and increases latency.
- Fix: Implement the routing strategy defined in the Core Solution. Audit token usage weekly to identify misrouted tasks.
-
Parallel Race Conditions
- Explanation: When using multi-agent systems that spawn subagents, concurrent edits to the same file can cause merge conflicts or overwrites.
- Fix: Enforce file ownership rules. Use sequential pipelines for interdependent changes, or configure the orchestrator to lock files during agent operations.
-
Prompt Drift
- Explanation: Vague instructions like "improve performance" lead to unpredictable changes. Agents may optimize the wrong metrics or break existing functionality.
- Fix: Use structured prompts with acceptance criteria. Example: "Optimize the
GetInventory query to reduce execution time by 20% without altering the return schema."
-
Hook Bypass
- Explanation: Agents may attempt to skip tests or linting to complete tasks faster, especially under token constraints.
- Fix: Configure agent permissions to disallow skipping hooks. Enforce hooks at the CI/CD level as a secondary safety net.
-
Vendor Lock-in via Hardcoded Keys
- Explanation: Embedding API keys directly in configuration files or prompts creates security risks and limits flexibility.
- Fix: Use environment variables and secret management tools. Abstract provider configuration so models can be swapped without code changes.
-
Ignoring LSP Intelligence
- Explanation: Relying solely on text completion without leveraging Language Server Protocol (LSP) data results in code that doesn't integrate well with the existing type system.
- Fix: Ensure your agent setup supports LSP integration. This provides real-time type checking and symbol resolution, reducing integration errors.
Production Bundle
Action Checklist
Decision Matrix
| Scenario | Recommended Approach | Why | Cost Impact |
|---|
| Visual UI Tweaks | Cursor Composer | Inline diff review and visual feedback accelerate frontend iteration. | Low (Pro subscription) |
| Deep Refactoring | Claude Code | Opus 4.6 handles complex cross-file dependencies with high reliability. | Medium ($20/mo + API) |
| Cost-Sensitive Scaling | OpenCode + OmO | Native routing to cheaper models reduces per-task cost significantly. | Low (Free + API costs) |
| Strict Compliance | Claude Code + Hooks | Built-in hook system enforces quality gates automatically. | Medium |
| Multi-Provider Strategy | OpenCode | Supports 75+ providers; avoids dependency on a single vendor. | Variable |
Configuration Template
Use this template to bootstrap your workflow configuration. Adapt the models and paths to your environment.
{
"workflow": {
"name": "fullstack-orchestrator",
"version": "1.0.0",
"providers": {
"anthropic": { "env_var": "ANTHROPIC_API_KEY" },
"openai": { "env_var": "OPENAI_API_KEY" },
"google": { "env_var": "GOOGLE_API_KEY" }
},
"routing": {
"default": "claude-sonnet-4",
"rules": [
{ "pattern": "**/*.css", "model": "gpt-4o-mini" },
{ "pattern": "**/*.test.{ts,tsx}", "model": "gemini-flash-2" },
{ "pattern": "**/Migrations/**", "model": "claude-opus-4.6" }
]
},
"context": {
"file": "AGENTS.md",
"max_tokens": 12000,
"strategy": "semantic_chunking"
},
"hooks": {
"pre_commit": "npm run lint && dotnet test",
"post_edit": "npm run type-check"
}
}
}
Quick Start Guide
-
Initialize Configuration:
Create ai-workflow.config.json in your project root using the template above. Update provider keys and routing rules.
-
Generate Context File:
Run npx ai-context-gen --output AGENTS.md to scaffold your context file. Review and customize domain rules and commands.
-
Install Hooks:
Execute npx husky install and add the pre-commit script from the Core Solution to enforce quality gates.
-
Verify Routing:
Run a test task: npx ai-agent --task "Add a comment to src/utils/helpers.ts" --dry-run. Check logs to confirm the correct model was selected.
-
Start Development:
Launch your preferred agent interface. The routing configuration and context file will automatically guide the workflow. Monitor token usage via your provider dashboard.