DEV Community

Alexis MP for Google Cloud

Posted on Originally published at Medium on

From Python to Rust, Go, to… Java? Steering Your AI Coding Agent Through Architecture Trade-Offs

When you pair-program with an autonomous AI coding agent, something magical happens: you go from an idea to a deployed, production-grade cloud application in an afternoon. But something else happens, too. If you don’t actively steer your agent’s architectural compass, it will happily ride the defaults of its training data or jump onto the latest Hacker News hype train.

Here is the story of building Akkord , an AI-powered sheet music harmonizer and guitar arranger running on Google Cloud, and what happened when I challenged my coding agent to rethink the stack across Python , Rust , Go , and Modern Java (JDK 21/25).

Akkord: Computer Vision Meets Musical Counterpoint

Musicians, especially guitarists, frequently run into two problems with PDF sheet music:

  1. Bare scores with no chords: You have a classical or folk melody on a 5-line staff, and you want playable guitar chords and a tasteful bass line added directly above the staves.
  2. Scores with questionable chords: You download a lead sheet where every measure just pounds the root note in the bass (Am -> Dm -> E -> Am), doubling the melody note in parallel octaves and ignoring harmonic counterpoint.

Akkord automates both workflows end-to-end:

  1. Pixel-Level Staff & TAB Geometry Detection: It rasterizes each PDF page and scans horizontal ink-density slices (accounting for tilted scans and stripping outer eighth/sixteenth-note beams) to distinguish 5-line musical staves from 6-line guitar TABs , computing exact bounding boxes (S1..Sn) in PDF points.
  2. Visual Rulers for Multimodal AI Grounding: Instead of asking an LLM to guess (x, y) coordinates blindly, Akkord generates a Guide Image for every page with red vertical X-coordinate rulers (40pt..560pt) and color-coded translucent bands over each detected staff system, plus extracted vector text tokens (re-joining spaced chord tokens like G m into Gm).
  3. Multimodal Harmonic & Counterpoint Analysis: It sends the clean score, the coordinate guide image, and the extracted tokens to Gemini (gemini-4-argon / gemini-3.8-flash) with strict musical rules:
  • Avoid systematic root-position monotony and melody doubling: propose slash chords (Am/G, Dm/F, E7/G#) using contrary motion and walking-bass lines.
  • Never confuse a 3-sharp guitar score in A Major with F# Minor just because the guitar reads an octave higher and uses low ledger lines (E2, F#2, G#2)!
  1. Collision-Free Vector PDF Overlay: Using a 2pt ink-density grid and a spiral low-ink search , Akkord places vector chord pills, uniform-sized chord corrections with superscript footnote numbers (G → G7/B ¹), 6-string fretboard diagrams, and an appended harmonic report page, without drawing over a notehead, lyric, or tie.
  2. Cloud-Native Batch Pipeline: Users sign in with Google OAuth 2.0, pick a Google Drive folder (or drop PDFs), and process batches asynchronously via Cloud Run , Cloud Tasks , Cloud Firestore , and Cloud Storage , complete with a 25-PDF/day quota, automatic next-day deferral, and an 18:00 daily usage & token-cost digest email.

How the Agent Harness Led Me to 100% Python

When I started building Akkord inside my AI agent harness with no particular language or framework SKILLS installed, I didn’t specify a programming language. I focused entirely on the domain:

Read music sheets from Google Drive, analyze the harmony with Gemini, and write chords onto the PDF.

The agent reached for Python 3.12 :

  • Web & APIs: FastAPI + Uvicorn
  • PDF & Image Processing: PyMuPDF (fitz) + Pillow + ReportLab
  • AI & Cloud: google-genai SDK + direct REST calls to Firestore, Cloud Storage, Cloud Tasks, and Drive API v3

Why the Agent Chose Python (And Why It Works Just Fine!)

AI coding agents love Python for rapid iterative prototyping. When I asked the agent to tweak the staff-line clustering algorithm so outer beams wouldn’t look like a 6th staff line, or to adjust the spiral ink-avoidance penalty inside pdf_annotator.py, the edit-test loop just took two seconds.

And honestly? The Python version on Cloud Run works great and I was able to deliver the entire app in less than than 24h. Because the main latency in Akkord is the multimodal Gemini call (typically 4 to 12 seconds per score), Python’s ~350 ms of local PDF pixel scanning and vector drawing barely matters on a single file.

Still, as a developer, you look at nested Python for loops iterating over millions of grayscale pixels in pdf\_layout.py and pdf\_annotator.py, plus a ~320 MB container memory footprint, and you start thinking: Surely, I can do better!

“Rewrite It for Speed!” — The Trendy 100% Rust Reflex

Curious, I gave the agent a classic developer prompt:

If I were to rewrite everything in another more efficient language with faster execution, what should it be?

If you ask an LLM in 2026 for “maximum efficiency and faster execution,” its first instinct is almost always Rust (Axum + Tokio + image + pdf-writer).

To be fair, Rust makes the pixel-scanning loops in pdf\_layout.py and the spiral ink-collision search in pdf\_annotator.py 15x to 25x faster , compiling them down to SIMD-vectorized machine code with zero garbage collection pauses and a tiny ~25 MB RAM footprint.

The catch? Writing OAuth 2.0 session management, multipart Google Drive uploads, dynamically nested Cloud Firestore REST JSON envelopes, and HTML email builders in pure Rust means fighting borrow-checker lifetimes on deeply nested JSON trees, all for code that spends 99.9% of its life waiting on network I/O.

Splitting the Brain — The Go + Rust Polyglot Architecture

So I refined my prompt:

Consider writing different parts in different languages if it makes sense.

Immediately, the agent pivoted from a monolithic rewrite to a Polyglot Architecture that splits the system along its true hardware boundary:

I/O-bound Cloud Orchestration vs. CPU-bound Pixel & Vector Geometry.

Part 1: Go (cmd/akkord, internal/…) for the Cloud Server & Orchestrator

  • Using 100% Go standard library (net/http, compress/zlib, crypto/hmac, archive/zip), Go handles Cloud Run cold starts in <80 ms , manages goroutine worker pools and SSE streaming effortlessly, and speaks REST JSON to Gemini API, Firestore, GCS, and Google Drive with clean, readable structs.

Part 2: Rust (akkord-pdf-engine) for the Native PDF Vision & Vector Engine

  • Invoked by Go via a zero-overhead JSON stdin/stdout bridge, the native Rust binary uses rayon data parallelism, image, imageproc, ab_glyph, and lopdf to rasterize pages, detect 5-line staves vs. 6-line TABs, compute the 2pt ink grid, and inject raw PDF content streams (BT/ET, Bézier curves c, vector rectangles re) in an estimated ~25–40 ms per page!

Nudging the Agent Toward Modern Java (JDK 21/25 LTS)

The Go + Rust polyglot architecture is awesome, if your team is happy maintaining both a Cargo.toml and a go.mod in the same Dockerfile.

But what if you work in an organization where the platform, security, observability, and engineering teams are standardized on the JVM?

Many LLMs still carry an outdated mental model of Java from the Java 8 era (remember heavyweight application servers, thread-per-request exhaustion, slow startup?).

When you nudge the agent to evaluate Modern Java (Java 21 / Java 25 LTS) for the exact same workload, the technical picture changes dramatically:

  1. Project Loom (Virtual Threads — JEP 444): Just like Go’s goroutines, Java’s Virtual Threads (Executors.newVirtualThreadPerTaskExecutor()) allow Akkord to fan out dozens of concurrent Google Drive downloads, Gemini API requests, and Firestore writes with simple, readable blocking code and near-zero OS thread overhead.
  2. JIT Vectorization & the Vector API (jdk.incubator.vector) for PDF Pixel Math: Python was slow on pdf\_layout.py and pdf\_annotator.py because Python boxes every integer and interprets loops bytecode-by-bytecode. In modern Java, primitive byte[] and int[] arrays on the HotSpot C2 compiler (or GraalVM JIT) are automatically unrolled and compiled into*AVX-512 / ARM Neon SIMD instructions *. Scanning a 1240×1754 page for 5-line staves or running the 2pt spiral ink-collision search in pure Java takes** ~25–45 ms**, within striking distance of Rust, without needing a second language or FFI boundary!
  3. Mature, Pure-Java PDF & Graphics Ecosystem: Instead of shelling out to C binaries or stitching together separate crates for font metrics and PDF dictionaries, Java has PDFBox 3.x and hardware-accelerated Java2D (BufferedImage, Graphics2D, TrueType glyph layout) built right in.
  4. First-Class Google Cloud & Enterprise Ecosystem: Google’s official Java SDKs for Gemini , Firestore , Cloud Storage , Cloud Tasks , and Google Drive are tier-1 citizens with built-in gRPC connection pooling, automatic retries, and OpenTelemetry tracing. Additionally, framework libraries like LangChain4j provide clean, idiomatic wrappers around Gemini API calls, streamlining prompt orchestration and structured AI outputs in Java.
  5. Fixing Cold Starts with GraalVM Native Image: Compile the Java service with GraalVM Native Image (via Quarkus, Micronaut, or Spring Boot 3.4+) and you get a ~50–90 ms Cloud Run cold start and a ~60 MB RAM footprint , matching Go while keeping 100% of your codebase in a single, type-safe language.


The Complete Architecture Showdown

Conclusion: Steer Your Agent, Don’t Let Defaults Steer You

Here are three lessons about working with modern AI coding assistants:

  1. Agents default to frictionless velocity first. Left unprompted, an agent will pick Python + FastAPI because it minimizes token count and maximizes first-draft success. And for 80% of cloud apps, including our working Python release of Akkord, that’s a fantastic starting point!
  2. Vague optimization prompts trigger trendy answers. Ask an agent “what is the fastest language?” in the abstract, and it will hand you a 100% Rust rewrite, even if 90% of your time in the app is waiting on an LLM API and Google Drive.
  3. Specific architectural nudges unlock the best engineering insights. When you ask your agent to consider polyglot boundaries (leading to Go + Rust ) or to evaluate modern capabilities of an established enterprise platform (leading to Modern Java with Virtual Threads, SIMD vectorization, and GraalVM ), the agent stops repeating clichés and starts doing real systems engineering.

Even if you standardize your backend services on Modern Java, keeping a standalone developer or admin CLI in Go remains a highly practical choice. Go’s instant startup time, cross-compilation to single, self-contained static binaries with zero JVM dependency, and lightweight memory footprint make it exceptionally well-suited for fast command-line tooling.

Your AI agent knows how to write Python, Rust, Go, and modern Java fluently. The secret is remembering that you are still the Architect. Don’t hesitate to challenge your tools, ask “what about language X?”, and steer them toward the stack that fits your team, your runtime, and your company best!


Top comments (0)