I Stopped Letting My AI Agent Draw AWS Diagrams. Now It Writes a Few Lines and a Compiler Draws the Rest
An AI agent drew a slightly different AWS diagram every time I asked. I moved the layout into a rule-based command, archwire, so the agent only writes which services connect. Over four runs each, the cost per diagram went from $1.15 to $0.27.
When I ask an AI agent for an AWS architecture diagram, I get a slightly different diagram every time, even with the same prompt. A line takes another route, a label changes, and I can't diff two versions of the same architecture.
So I changed who does what. The agent now writes only which services connect to which. A rule-based command called archwire lays the diagram out and adds the parts the lines imply. It's open source, and you can try it with
uvx archwire .The commands and outputs below were checked in December 2026 with archwire 0.1.0 from PyPI, on macOS. To get the same results after a newer version is out, pin it with
uvx archwire@0.1.0 . The cost and time measurements are from September and November 2026. It also runs on Linux. This is a personal project, not an official AWS tool.Why I built it
Until recently, I used my own Claude Code skill to draw diagrams. It is aws-drawio-diagram-skill , and I wrote about how I got to it in an earlier post . The skill made the diagrams look much better, but the agent still wrote every coordinate and every line of draw.io XML.
I gave Claude Opus 5.5 the same detailed request four times: a two-AZ web architecture with CloudFront, an ALB, ECS, Aurora, S3 and CloudWatch, with the subnets and NAT gateways spelled out. In this measurement, one diagram cost an average of $1.15 and took 5.6 minutes, because the agent wrote about 30,000 tokens of coordinates and XML each time. All four diagrams were a little different. The route of the line from the NAT gateway to the internet gateway changed, and so did the label on the line from the ALB to ECS.
The agent is good at understanding what I want to build. It is not a good layout engine. So I split the work:
- The agent writes the connections, a few lines of text
- archwire places the parts, routes the lines, and adds what the connections imply, by rules
Five lines in, a diagram out
This is the whole input.
-> is a main flow, the path traffic takes. ~> is an auxiliary flow such as logs and metrics.flows: - user -> cloudfront -> alb -> ecs(fargate) -> aurora - cloudfront -> s3 - ecs -> internet - ecs ~> cloudwatchSave it as
web.yaml and compile it:uvx archwire compile web.yaml -o web.drawioOpen
web.drawio in draw.io:
I did not write the VPC, the subnets, the second Availability Zone, the NAT gateways, the internet gateway or the Aurora reader. archwire added them.
The output is a normal
.drawio file, so you can still edit it by hand. And the same definition, compiled by the same version, always gives the same file. I compiled web.yaml twice and compared the two files with cmp : they were identical, byte for byte.Is it really cheaper and faster?
The repository has a Claude Code skill that calls archwire. I gave the same web architecture request to the same Claude Opus 5.5 four times through it.
| Cost per diagram | Time per diagram |
|---|---|---|
My earlier skill (the agent writes the XML) | $1.15 | 5.6 min |
The archwire skill (the agent writes the definition) | $0.27 | 34 s |
Both rows are averages over four runs. The prompts were in Japanese. The cost went down to about a quarter and the time to about a tenth, because the agent's output shrank from about 30,000 tokens to about 2,000.
This did not make the agent deterministic. In the four runs, the agent wrote the definition itself each time. Runs 1 and 4 produced the same definition, so the two diagrams were byte-identical. Run 2 had the same lines in a different order, which in 0.1.0 still changes the routing of a few lines. Run 3 left out one line,
cloudfront ~> cloudwatch , so that line was missing from the diagram.What changed is where the variation lives. Before, it was spread over more than a hundred coordinates and the XML around them. Now it is in a file of about a dozen lines that I can read in a few seconds and keep in Git.
Three things I cared about
1. Every part archwire adds comes with a reason
When archwire adds a part you did not write, it records why. Take the internet gateway in the diagram above. It is nowhere in the five lines.
compile prints a JSON report on standard output. Redirect it to a file:uvx archwire compile web.yaml -o web.drawio > web.jsonThe report's
derived list has an entry for each part or setting archwire added or chose. This is the one for the internet gateway:{ "target": "igw", "added": true, "kind": "constraint", "rule": "internet-facing-alb-in-vpc-with-igw", "reason": "With an internet-facing Application Load Balancer, only VPCs that have an Internet Gateway can be selected, so the VPC gets an Internet Gateway.", "source": "https://docs.aws.amazon.com/elasticloadbalancing/latest/application/create-application-load-balancer.html"}constraint means AWS requires it, and it always comes with a link to the AWS documentation. Things archwire merely chose, such as one NAT gateway per Availability Zone, are marked default . For web.yaml , derived has 19 entries.The same reasons are stored in the
.drawio file. Hover over a part in draw.io and you see why it is there. I often ask an agent for a diagram to understand an architecture or the code it wrote, and this helps: I can follow why each part exists without leaving the diagram.2. It does not guess where the connections can't decide
Add one line, from ECS to S3:
- ecs -> s3Compile again, and the exit code is 2 instead of 0. The report has this:
{ "hole": "route.ecs.s3", "at": "flows[4]", "need": "Route from ecs to s3", "choices": ["endpoint", "nat"]}Traffic from a private subnet to S3 can go through a VPC endpoint or a NAT gateway. Both are valid, and they differ in cost and in what you have to manage. archwire does not pick one. It returns the question as a hole. The diagram is still written, with that line grey, dashed and labelled "Route undecided".

Answer the hole and compile again. The exit code is back to 0, and the line is labelled "Read/Write (via VPC endpoint) (all AZs)".
uvx archwire set web.yaml choose.route.ecs.s3 endpointuvx archwire compile web.yaml -o web.drawioThis matters most when an agent is driving. An agent that hits an ambiguous choice usually picks something plausible and moves on, and you find out later, or never. The skill tells the agent not to answer holes itself. When I ran it, Claude Code stopped and asked me which route I wanted.
3. It stops instead of drawing something wrong
archwire accepts a fixed list of connections. Anything else stops with
UNSUPPORTED , exit code 1, and no diagram. In 0.1.0, for example:flows: - user -> alb -> lambda{ "code": "UNSUPPORTED", "at": "flows[0]", "got": "alb -> lambda", "allowed": [], "rule": null, "message": "`alb -> lambda` is not a supported connection"}That is a real AWS pattern that 0.1.0 simply doesn't know yet. I would rather have the tool say so than draw a diagram I can't trust.
How an agent uses it
Two pieces make this work with an agent.
archwire list prints, as JSON, every service, every accepted connection and every setting, taken from the same rules data the compiler uses. The agent reads it before writing, so it does not have to guess names from memory, and the list is never out of date with the tool.- Never change what the user asked for to make the definition compile. If archwire stops, tell the user what could not be drawn
- Never answer a hole yourself. Show the user the choices
- Exit code 0 is not the end. If the report names a line that could not be drawn clear of everything else, say which one
To install it for Claude Code:
git clone https://github.com/sagochiko/archwire.gitcp -r archwire/skills/archwire ~/.claude/skills/The pattern is not specific to diagrams. Let the model do the part that needs understanding, give it a small format to write, and hand the rest to something deterministic that can explain itself and can say no.
What 0.1.0 can and can't draw
Version 0.1.0 covers these shapes:
- A web architecture with an ALB, ECS or EC2, and Aurora, in one VPC with two or three Availability Zones
- An API without a VPC: CloudFront, S3, API Gateway, Lambda, DynamoDB, Cognito
- Both in one definition, with a Lambda function that reaches Aurora drawn inside the VPC
- Detection to notification, from GuardDuty, Inspector, Security Hub, Config or CloudTrail to EventBridge, SNS, Step Functions or Systems Manager
- Log analysis with Security Lake, Athena and the Glue Data Catalog
- Event-driven flows between EventBridge, SNS, SQS, Lambda and S3
The Region is Tokyo only, and a diagram has at most one VPC. RDS, CI/CD pipelines, multiple VPCs or accounts, and Bedrock or AgentCore architectures are not in 0.1.0. Some of these are already on the main branch for the next release. The full list is in Limits .
One more thing to be clear about: a diagram that compiles is consistent under archwire's rules. It is not a guarantee that the architecture works in AWS.
Try it
uvx archwire compile web.yaml -o web.drawioIf archwire can't draw an architecture you need, I'd like to see the definition. Open an issue with the lines you wrote. That is how I decide what to add next.
I wrote this post with help from AI (Claude).
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article