Go: Because Someone Has to Read the Agents’ Code
Post{Author: "Matt", Published: "", ReadingTime: 5 * time.Minute}Post{
Author: "Matt",
Published: "",
ReadingTime: 5 * time.Minute,
}It is uncontroversial to say that writing code has never been cheaper. An LLM can produce a working implementation in the time it takes to describe one. The cost of understanding that implementation hasn’t decreased quite as much: someone has to review it, check its assumptions, and decide whether to maintain it.
That is one of the reasons Partite is written in Go. The preference is older than the LLMs, though. We formed it at our previous company, where Python began as our language of choice.
What Python was costing us
Our web services, data pipelines, and infrastructure were all Python. We used Django and Django REST Framework, Flask, and later aiohttp. As the codebases and traffic grew, we found ourselves continually solving similar problems.
Concurrency was one. Our services held lots of concurrent connections while doing substantial data transformation and mapping on the CPU, and we needed to do that without inflating our AWS bill.
Reading the code was another. We could produce a lot of Python quickly, but understanding the code we already had was taking longer. Following a request through layers of application and framework behavior was a constant tax. “Why is my decorator interacting with my metaclass in such strange ways?” can really put a damper on an afternoon.
Our data models were also getting stricter. We ingested data from hundreds of sources, and our assumptions about that data had to stay consistent as it passed through services and transformations. We wanted those assumptions explicit and easy to check.
Our stack was optimized for writing code quickly, while reading it was becoming the larger part of the job.
What changed with Go
Mike, our CTO at the time and now the CEO and co-founder of Partite, suggested Go. The first few days got mixed reviews. By the end of the first week, we were all on board.
- Concurrency. Goroutines gave us a straightforward way to keep independent operations in flight. We still had to decide how to batch requests, limit concurrent work, and handle failures, but those decisions were easier to see in the code.
- Types. Function signatures showed what each step expected and returned, and the compiler checked that we used them consistently. Validating incoming data remained our job, but the assumptions inside a service were easier to inspect.
- Serving. Where we had assembled nginx, uWSGI, and a web framework, we could use Go’s stdlib and a router library.
- SQL. We started writing it again, so we could read the joins and filters directly instead of working out what an ORM would generate. sqlc generated the typed database access code from our queries.
Our main GraphQL service became a useful test of our choices. It loaded data from internal and external APIs, S3, PostgreSQL, and other sources. It applied strict regulatory rules to that data, and it served both enterprise customers and a growing volume of consumer traffic. The Python implementation had become a repository engineers dreaded contributing to.
After we rewrote it in Go, CPU utilization dropped by more than half, and memory utilization dropped by more than that. Request latency improved, with far fewer spikes. We saw fewer bugs related to data discrepancies and mapping. Over the next six to twelve months, nearly every engineer contributed to that repository.
The rewrite did benefit from what we had learned operating the original, and Go was not free. Our first prototypes probably took a little longer, at least at first. We also kept managing our infrastructure in Python, because it was a reasonable tool for that job.
The same choice at Partite
When we started Partite, we brought that experience with us. A conversation in Partite is concurrent work: agents hand off to each other, tool calls go out to other systems, and results stream back to the application. Agents exchange structured messages, and the assumptions about those messages need to hold from one agent to the next.
The same concerns show up away from conversations too. Partite has a GraphQL API, which teams use to configure it. Each root field of a query runs in its own transaction, which holds a database connection, and the root fields of a query run concurrently. This extension from the Partite engine keeps one query from taking a connection for every field:
type ConcurrentRootFieldLimit struct {
Limit int
}
type rootFieldSlotsKey struct{}
func (l ConcurrentRootFieldLimit) InterceptOperation(ctx context.Context, next graphql.OperationHandler) graphql.ResponseHandler {
return next(context.WithValue(ctx, rootFieldSlotsKey{}, make(chan struct{}, l.Limit)))
}
func (ConcurrentRootFieldLimit) InterceptRootField(ctx context.Context, next graphql.RootResolver) graphql.Marshaler {
slots, ok := ctx.Value(rootFieldSlotsKey{}).(chan struct{})
if !ok {
return next(ctx)
}
select {
case slots <- struct{}{}:
case <-ctx.Done():
graphql.AddError(ctx, gqlerror.Errorf("the request ended before this field ran"))
return graphql.Null
}
defer func() { <-slots }()
return next(ctx)
}
A buffered channel holds the slots. A field takes a slot before it runs and gives it back when it returns. If the request ends first, the field stops waiting and says why.
We still write SQL directly as well. Our own library, modelg, generates the typed Go code around those queries. It will get a post of its own.
Why it matters more now
At Partite, agents write a lot of our code, which makes reading it the larger share of the work. The extra explicit work that Go asks for is exactly the part an LLM makes cheap. What it does not make as cheap is review, and there Go’s plainness helps. Generated Go looks like the Go we would have written. The formatter leaves one style. Errors are returned and handled where they occur. There are no decorators or metaclasses for behavior to hide in, and the compiler rejects a mismatched type before one of us spends time on it.
At Partite, we’re optimizing for the engineer who has to understand the result, including when the author is an LLM.
Of course, our choice of language doesn’t have to affect yours. You call Partite through a typed API, so the only language that has to matter to you is the one your team already uses.