Skip to main content

Patterns & Architecture for Coding Agents

Reference architecture and recommended multi-agent patterns for building production coding agents on AgentCore.


Reference Architecture​

A production coding agent on AgentCore follows a layered architecture with clear separation between triggers, reasoning, execution, and output delivery.

Architecture Components​

LayerComponentResponsibility
TriggerGitHub/GitLab webhook, Jira, Schedule, CI eventReceives the external event and invokes the agent
IngestionLambda / EventBridgeNormalizes the event payload and routes to AgentCore Runtime
ReasoningAgentCore Runtime + LLMAgent loop: reads context, plans approach, generates code
ExecutionCode Interpreter / microVMRuns generated code, tests, and linters in an isolated sandbox
ContextAgentCore Memory + Gateway (GitHub MCP)Project context, file history, repository access
OutputPR / Branch / ArtifactAgent-generated code delivered via git with human review gate
QualityAgentCore Evaluations + ObservabilityTrajectory checks, LLM-judged quality, traces

Execution Flow​

Trigger (Webhook / Ticket / Schedule)→Trigger Lambda→AgentCore Runtime→Coding Agent
Coding Agent↔Memory↔Gateway (GitHub MCP)↔Sandbox / Code Interpreter↔Observability
Coding Agent→PR / Artifact→Human Review Gate→Merge

Reference implementation​

The Multi-Agent Coding Workshop provides a complete, deployable reference architecture with a multi-agent setup (planner, coder, reviewer), durable orchestration, and CI integration.


PatternWhen to UseReference
Single Agent + SandboxSimple generation or test tasks scoped to one fileQuick Start
Plan-Act-ReflectMulti-step implementation from specs; iterate until passing—
Swarm (Multi-File)Parallel agents handling different modules in a refactorPatterns Overview
Coder + ReviewerQuality-critical: separate generation from evaluationAutonomous Coding Agent
Durable OrchestrationMulti-phase pipelines with zero-cost suspensionAutonomous Coding Agent
Agents-as-ToolsOrchestrator delegates to specialized sub-agents—
Human-in-the-LoopPR review gate before mergeCode Agents Competition
info

All AgentCore patterns work for coding agents. For the full 12-pattern catalog including Graph, A2A, and Router, see the Architectural Patterns Reference.

Compose, not compete

Production coding systems assign each agent one role (e.g., backend builder, validator, frontend builder) and combine their outputs into a single deliverable. The deterministic gate (pytest) is the sole acceptance authority and the LLM judge can withhold approval but never fabricate a pass.


Pattern Selection Guide​

Start with Single Agent + Sandbox when:

  • The task is scoped to one file or module
  • You need a working example fast

Move to Plan-Act-Reflect when:

  • The task involves multiple steps (read specs, write code, run tests, fix failures)
  • You need iterative self-correction

Use Swarm (Multi-File) when:

  • A large refactor spans many modules that can be modified in parallel
  • Each module has independent tests

Use Coder + Reviewer when:

  • Quality is critical (regulated code, production infrastructure)
  • You want a separate evaluation pass before delivery

Use Durable Orchestration when:

  • The pipeline has distinct phases with wait points (human approval, async builds)
  • You want zero-cost suspension between phases

Add Human-in-the-Loop when:

  • Code must be reviewed before merge (all production use cases)
  • Regulatory or compliance requirements mandate human sign-off

End-to-End Coding Workflow​

The canonical pattern: the LLM handles reasoning, deterministic commands handle execution.

import json
import boto3

client = boto3.client("bedrock-agentcore", region_name="us-east-1")

AGENT_ARN = "arn:aws:bedrock-agentcore:us-east-1:123456789012:runtime/CodingAgent"
SESSION_ID = "session-coding-task-abc123-def456-gh"


def run_command(command, timeout=60):
"""Run a deterministic command in the agent's microVM (zero token cost).

Response stream events:
contentStart — command execution began
contentDelta — stdout/stderr output (may appear multiple times)
contentStop — command finished, contains exitCode and status
"""
response = client.invoke_agent_runtime_command(
agentRuntimeArn=AGENT_ARN,
runtimeSessionId=SESSION_ID,
body={"command": command, "timeout": timeout},
)
for event in response["stream"]:
if "chunk" in event and "contentStop" in event["chunk"]:
return event["chunk"]["contentStop"].get("exitCode")
return None


def invoke_agent(prompt):
"""Send a prompt to the agent (LLM reasoning — uses tokens)."""
response = client.invoke_agent_runtime(
agentRuntimeArn=AGENT_ARN,
runtimeSessionId=SESSION_ID,
payload=json.dumps({"prompt": prompt}).encode(),
)
body = json.loads(response["response"].read())
return body["response"]["content"][0]["text"]


# Step 1: LLM reasons and writes code
invoke_agent("Read issue #42 and implement the fix in /mnt/workspace")

# Step 2: Deterministic test execution (no tokens)
exit_code = run_command("cd /mnt/workspace && python -m pytest tests/ -v", timeout=300)

# Step 3: If tests pass, commit and push
if exit_code == 0:
run_command("cd /mnt/workspace && git checkout -b fix/issue-42")
run_command('cd /mnt/workspace && git add -A && git commit -m "Fix issue #42"')
run_command("cd /mnt/workspace && git push origin fix/issue-42")

Your Journey to Production​

  1. Define your trigger: Identify the event that starts the coding task (PR, ticket, schedule, CI failure).
  2. Build your sandbox: Configure session storage, install your toolchain in a container, wire file and shell tools.
  3. Implement the agent: Write the system prompt, connect tools, define the Plan → Generate → Validate loop.
  4. Add evaluations: Set up trajectory checks (100%, zero cost) and LLM-judged quality (sampled).
  5. Deploy and monitor: Push to AgentCore Runtime. Monitor tool usage and goal success via CloudWatch.