Skip to content
SunnyWriteUps
Go back

How can coding agents be used productively in software development?

Edit page

An unconstrained LLM writing code quickly degrades into hallucinated APIs, broken imports, and architectural drift. To achieve high autonomy with production-grade reliability, engineering teams wrap agents in deterministic feedback loops, strictly bounded context architectures, and formal specification contracts.


1. Context & Loop Engineering

The core engine of any coding agent is the Evaluation-Action Loop (ReAct: Reason, Act, Observe). The engineering challenge is preventing infinite loops, drift, and context decay.

┌─────────────────────────────────────────────────────────────┐
│                 The Controlled Agent Loop                   │
│                                                             │
│   ┌──────────────┐      Tool Call      ┌────────────────┐   │
│   │  Reasoning   │ ──────────────────> │  Environment   │   │
│   │  (LLM Core)  │ <────────────────── │ (LSP, FS, Bash)│   │
│   └──────────────┘      Observation    └────────────────┘   │
│          │                                      │           │
│          ▼ [Context Pruning & Compaction]       │           │
│   ┌─────────────────────────────────────────────▼───────┐   │
│   │  Bounded Window: System Rules + Plan + Active Step  │   │
│   └─────────────────────────────────────────────────────┘   │
└─────────────────────────────────────────────────────────────┘

Preventing Drift and Saturation


2. Spec-Driven Development (SDD)

Coding agents thrive when given clear boundaries, unambiguous contracts, and non-negotiable success criteria. Spec-Driven Development turns ambiguity into verifiable interfaces before writing application logic.

The Spec-First Workflow

  1. Interface Contract Definition: The agent first drafts OpenAPI schemas, TypeScript interface types, or gRPC definitions.
  2. Deterministic Test Scaffolding: Unit and contract tests are generated directly from the specification (test-first).
  3. Implementation to Pass Contracts: The agent writes minimal code strictly to satisfy the generated specs and test suites.
<!-- Example: Feature Spec Contract (feature-spec.md) -->
## Goal
Implement a distributed idempotent deduplication cache for incoming Webhooks.

## Invariants
- Must use Redis `SET NX EX` with a TTL of 86400 seconds.
- Must return `409 Conflict` if the key exists.
- Zero mutations to existing authentication middleware.

## Acceptance Tests
- `pnpm test tests/unit/webhook-dedup.test.ts` must exit with code 0.

By decoupling the spec from the execution, human engineers review the intent and invariants rather than micromanaging thousands of lines of generated syntax.


3. Modular Skills

Rather than stuffing entire engineering runbooks into system instructions, teams organize capabilities into Skills: discrete, load-on-demand task playbooks stored directly in the repository.

.agent/skills/
├── drizzle-migration/
│   ├── rules.md              # Checklists (e.g., "Always use non-blocking schema alters")
│   └── template.sql          # Standardized template
└── trpc-router/
    ├── procedure-sop.md      # Step-by-step route wiring instructions
    └── error-handling.md     # Error mapping standards

4. Sub-Agent Orchestration

Single monolithic agents struggle when juggling high-level system architecture, complex refactorings, and line-level bug fixes simultaneously. Dividing responsibilities across specialized sub-agents isolates complexity.

                   ┌──────────────────┐
                   │ Planner / Leader │
                   └────────┬─────────┘
                            │ Dispatches subtasks
          ┌─────────────────┼─────────────────┐
          ▼                 ▼                 ▼
   ┌─────────────┐   ┌─────────────┐   ┌─────────────┐
   │ Code Writer │   │ Reviewer /  │   │ Test & Run  │
   │ (Scoped FS) │   │ Sec-Audit   │   │ (Sandbox)   │
   └─────────────┘   └─────────────┘   └─────────────┘

5. Hooks: Enforcing Deterministic Invariants

Hooks are programmatic scripts executed immediately before an agent takes an action or after it modifies files. They create non-negotiable boundaries that the model cannot bypass.

# Example: Post-Tool Hook (.agent/hooks/post-file-write.sh)
#!/usr/bin/env bash
TARGET_FILE="$1"

# 1. Automatic formatting to eliminate formatting noise
npx prettier --write "$TARGET_FILE" --log-level warn

# 2. Fast AST & Lint Gate
ERRORS=$(npx eslint "$TARGET_FILE" --format compact 2>&1)
if [ $? -ne 0 ]; then
  # Inject the error directly into the agent's next observation turn
  echo "LINT_VIOLATIONS_DETECTED in $TARGET_FILE:"
  echo "$ERRORS"
  exit 1
fi

# 3. Type check scope
npx tsc --noEmit --project tsconfig.json || exit 1

6. Model Context Protocol (MCP): Dynamic System Integration

The Model Context Protocol provides an open, standardized interface for agents to query live development environments, remote tools, and enterprise knowledge safely.

Instead of pasting documentation or log dumps manually, agents connect to lightweight local or remote MCP servers:

MCP ServerPractical Engineering Use Case
Language Server Protocol (LSP)Enables symbol search, “Go to Definition”, and finding all references across 50,000+ files without vector-embedding the repository.
Database IntrospectionInspects live schema constraints, column types, and foreign keys directly from local development databases.
Git & Issue TrackersReads commit logs, pull request review comments, and issue descriptions (GitHub/GitLab/Linear) on demand.
Observability / TracingFetches live stack traces from Sentry or Datadog to reproduce and fix production bugs based on actual runtime errors.

Architecture Summary

LayerResponsibilityBest For
Rules (.cursorrules, CLAUDE.md)Global project-wide constraintsTech stack versions, non-negotiable syntax conventions
SkillsSpecialized on-demand playbooksStandard Operating Procedures (SOPs), complex migrations
HooksLocal deterministic safety gatesLinting, formatting, pre-commit validation, blocking secrets
MCPLive interface to external state & toolsLSP navigation, live DB inspection, issue tracker syncing
Sub-AgentsSeparation of cognitive concernsDecomposing plans, writing scoped diffs, running audits
Spec-Driven DevPrecise contract definitionsTest generation, API contracts, verification criteria

Edit page
Share this post on:

Previous Post
Angular Agentic Engineering From Spec to Ship
Next Post
How to Provide the Right Context Through Rules, Skills, MCP, and Hooks, How to Evaluate Modularization with AI and Architecture Tools, and How to Use Deterministic Checks as Guardrails for Coding Agents

Comments