

Building Code Mode Agents
Most agents use tools by emitting one structured tool call at a time. The model picks a tool, waits for the result, picks the next, and every intermediate result flows back through its context. As the number of tools and steps grows, that gets expensive, slow, and brittle.
Code mode flips this. Instead of calling tools one at a time, the agent writes code that calls them as functions, runs that code in a sandbox, and returns only what matters back to the model. Why this works well in practice: models are trained on far more code than tool-call traces, so they compose operations more reliably in a language they already know. Loops, branching, filtering, and data transforms happen in the sandbox instead of as separate round-trips. Large intermediate results stay out of the context window, and tool definitions load on demand instead of all up front. The result is an agent that does more per step and spends fewer tokens doing it.
The obvious worry is letting a model write and run code. We'll handle that with Flyte's sandboxed orchestrator: the generated code can do pure control flow like loops, branching, and wiring tool calls together, but has no access to the filesystem, network, or OS. The actual tool or MCP calls get dispatched to isolated container tasks. You get the flexibility of letting a model write code without handing it the keys to the machine.
In this hands-on workshop, we'll build a code mode agent that writes and executes code to call tools, then deploy it behind a simple UI. The whole pipeline runs on Flyte 2/Union, so runs are durable and reproducible, steps are cached, and the same code scales from a laptop to a multi-node cluster without rewrites.
By the end, you'll have a working code mode agent and a reusable pattern you can point at your own tools.
What we'll cover
Why direct tool-calling breaks down at scale, and what code mode changes
Running model-generated code safely in Flyte's sandboxed orchestrator, with heavy work dispatched to isolated tasks
Orchestrating with Flyte 2: cached steps, durable runs, and execution that scales
Deploying the agent with a UI, with a path to production
What you'll leave with
A working code mode agent that writes and runs code to use tools
A reusable pattern you can adapt to your own tools and MCP servers
A clear sense of when code mode beats direct tool-calling, and when it does not
Who it's for
ML and software engineers building agents who want a more efficient, more capable alternative to chaining tool calls. Whether you're prototyping at work, evaluating agent infrastructure, or building a portfolio project, you'll leave with code you can keep extending.
Hosted by Sage Elliott, AI Engineer at Union.ai