mech.app

The mech.app newsletter

Agentic AI, minus the noise.

Get practical field notes on AI agents, automation, developer tools and security delivered to your inbox.

No spam. Unsubscribe anytime.

AI Agents

Three-Phase Agentic Workflow: How Developers Actually Use Claude Code

A repeatable workflow for AI coding assistants that moves from exploratory prompts to structured implementation, showing the handoff boundaries engineer...

Source: apimatic.io
Three-Phase Agentic Workflow: How Developers Actually Use Claude Code

AI coding assistants promise to write entire features from a single prompt. In practice, you write a prompt, wait, and get back code that compiles but ignores half your requirements or invents abstractions you never asked for. You re-prompt. The agent drifts further. You burn through the context window before shipping anything.

The problem is not the model. It is the missing structure around the prompt. Without clear requirements, scope boundaries, and verification criteria, the agent fills gaps with guesses. You inherit those guesses.

The fix is a repeatable three-phase workflow that treats the coding agent as a capable but literal collaborator. This approach moves you from “vibe coding” (prompting and hoping) to agentic engineering (prompting with guardrails).

The Three Phases

Phase 1: Exploration (Vibe Coding)

This phase is human-led. You use the agent to explore the problem space, prototype solutions, and clarify requirements. The agent acts as a sounding board, not an autonomous executor.

What happens:

  • You describe the problem in natural language
  • The agent proposes approaches, surfaces edge cases, and generates throwaway code
  • You iterate quickly without worrying about production quality
  • The goal is to define scope, not ship code

State management:

  • Conversation history is ephemeral
  • Code artifacts are temporary
  • No formal acceptance criteria yet

When to gate out:

  • You have a clear problem statement
  • You know what success looks like
  • You can write acceptance criteria

Phase 2: Structured Implementation

This phase is agent-led but human-gated. You hand the agent a structured prompt with requirements, constraints, and verification steps. The agent writes production-ready code. You review and approve before merging.

What happens:

  • You provide a detailed prompt with acceptance criteria
  • The agent generates code, runs tests, and verifies against criteria
  • You review the output for correctness and fit
  • The agent refactors based on feedback

State management:

  • Requirements and constraints are explicit
  • Test results are captured
  • Code changes are tracked in version control

When to gate out:

  • All acceptance criteria pass
  • Code passes review
  • Tests are green

Phase 3: Production Handoff

This phase is human-led again. You integrate the agent’s output into the codebase, handle deployment, and monitor for issues. The agent is no longer in the loop.

What happens:

  • You merge the code
  • You deploy to staging, then production
  • You monitor for regressions
  • You handle rollback if needed

State management:

  • Deployment logs are captured
  • Observability hooks are in place
  • Rollback procedures are ready

Orchestration Flow

The workflow is a state machine with three states and two gates:

[Exploration] --gate--> [Implementation] --gate--> [Production]
      ^                                                  |
      |__________________________________________________|
                     (rollback or new feature)

Gate 1: Exploration to Implementation

  • Human writes acceptance criteria
  • Human confirms scope is clear
  • Human provides structured prompt

Gate 2: Implementation to Production

  • Agent output passes all tests
  • Human reviews and approves code
  • Human triggers deployment

Handoff Boundaries

The key to this workflow is knowing when to hand control to the agent and when to take it back.

PhaseControlAgent RoleHuman RoleFailure Mode
ExplorationHumanPropose, clarifyDefine scopeUnclear requirements
ImplementationAgentExecute, verifyReview, approveContext drift
ProductionHumanNoneDeploy, monitorSilent breakage

Context Preservation

The biggest risk in multi-phase workflows is losing context between phases. Here is what needs to persist:

From Exploration to Implementation:

  • Problem statement
  • Acceptance criteria
  • Constraints (performance, security, compatibility)
  • Edge cases discovered during exploration

From Implementation to Production:

  • Test results
  • Code changes (via version control)
  • Known limitations
  • Deployment checklist

Practical approach:

  • Use a structured prompt template for Phase 2
  • Capture exploration notes in a markdown file
  • Link the prompt to the ticket or issue
  • Store test results in CI artifacts

Example Prompt Structure for Phase 2

# Task: Add rate limiting to API endpoint

## Context
- Endpoint: POST /api/v1/orders
- Current behavior: No rate limiting
- Codebase: Python/Flask, Redis available

## Requirements
1. Limit to 10 requests per minute per API key
2. Return 429 status code when limit exceeded
3. Include Retry-After header in response
4. Log rate limit violations

## Constraints
- Use existing Redis connection pool
- Do not break existing tests
- Follow project's error handling pattern

## Acceptance Criteria
- [ ] Rate limiter middleware is implemented
- [ ] Existing tests pass
- [ ] New tests cover happy path and rate limit exceeded
- [ ] Rate limit violations are logged
- [ ] Retry-After header is present in 429 responses

## Verification Steps
1. Run pytest suite
2. Manual test: send 11 requests in 60 seconds
3. Check logs for rate limit violation entry

This prompt gives the agent everything it needs to execute without guessing.

Observability and Rollback

When the agent produces unexpected changes, you need visibility and a way back.

Observability:

  • Diff the agent’s output before accepting
  • Run tests in CI before merging
  • Deploy to staging first
  • Monitor error rates and latency after production deploy

Rollback:

  • Use feature flags to disable new code paths
  • Keep the previous deployment artifact ready
  • Have a rollback runbook
  • Set a rollback SLA (e.g., 5 minutes)

Failure Modes and Mitigations

Context window overflow:

  • Symptom: Agent forgets earlier instructions
  • Mitigation: Keep Phase 2 prompts under 4,000 tokens, split large tasks into subtasks

Scope creep:

  • Symptom: Agent adds features you did not ask for
  • Mitigation: Explicit acceptance criteria, reject changes outside scope

Silent breakage:

  • Symptom: Code compiles but breaks existing behavior
  • Mitigation: Comprehensive test suite, require all tests pass before merge

Ambiguous requirements:

  • Symptom: Agent guesses wrong
  • Mitigation: Spend more time in Phase 1, write detailed acceptance criteria

When to Skip Phases

You do not always need all three phases.

Skip Phase 1 if:

  • Requirements are already clear
  • You are fixing a well-defined bug
  • You are repeating a pattern you have used before

Skip Phase 2 if:

  • The change is trivial (typo fix, comment update)
  • You are faster writing it yourself
  • The agent does not have enough context

Skip Phase 3 if:

  • You are prototyping
  • The code is not going to production
  • You are exploring a dead-end approach

Technical Verdict

Use this three-phase workflow when you want AI coding assistants to produce production-ready code without constant babysitting. It works best for:

  • Feature development with clear requirements
  • Refactoring tasks with defined scope
  • Bug fixes that need test coverage

Avoid it when:

  • Requirements are too vague to write acceptance criteria
  • The task is faster to do manually
  • You are exploring multiple approaches in parallel

The workflow adds overhead, but it pays off by reducing wasted sessions, context drift, and broken production deploys. The key is treating the agent as a collaborator that needs structure, not a magic box that reads your mind.