Skip to main content

Principle 2: Code as the Universal Interface

Sarah had 3,000 photos from her trip across Southeast Asia. They were scattered across her phone, her camera, and a backup drive. The filenames were meaningless: IMG_4521.jpg, DSC_0089.jpg, Photo_2024_03_15.png. She wanted them organized by country and city, with dates in the filenames, duplicates removed.

She tried three different photo organization apps. Each did part of what she wanted, but none could handle her specific combination of requirements. The apps had pre-built features, and her needs did not fit those features exactly.

Then she asked a general agent for help. Here's what she wrote:

"I have 3,000 photos scattered across three folders. They have meaningless names like IMG_4521.jpg. I want them organized by country and city based on their location data, with dates in the filenames (YYYY-MM-DD format), duplicates removed, and everything in a clean folder structure."

That's it. Plain English. No code, no technical knowledge required.

The agent translated her request into a program that:

  1. Read the location data embedded in each photo
  2. Figured out which country and city it was taken in
  3. Renamed the files with proper dates
  4. Detected duplicates by comparing actual image content
  5. Organized everything into a clean folder structure

Fifteen minutes later, her photos were perfectly organized in exactly the way she wanted. Sarah didn't write a single line of code. She described what she wanted in her own words, and the agent handled the translation.

This is Principle 2 in action. The general agent succeeded where specialized apps failed because it could write code. Code became the interface through which the agent could do anything Sarah needed, not just what some app designer anticipated.

Wait—Isn't Bash Already Code?

If you just read about Principle 1 (Bash is the Key), you might wonder: "Isn't Bash code? Why are these separate principles?"

Good question. Here's the distinction:

PrincipleRoleWhat It DoesAnalogy
Bash (Principle 1)The HandsNavigate, explore, move files, search, observeWalking through rooms, opening drawers, looking around
Code (Principle 2)The BrainCalculate, process data, build logic, create solutionsThinking, planning, solving puzzles, building tools

Bash commands like ls, grep, mv, and find let the agent navigate and manipulate the file system. They're quick, direct operations—look here, move that, search for this.

Code (Python scripts, data processing, custom programs) lets the agent think and build. When Sarah needed her photos analyzed for location data, compared for duplicates, and reorganized with custom naming—that required computation, not just file manipulation.

Bash opens the door. Code does the work inside.

Both are essential. An agent with only Bash can explore but not compute. An agent with only code generation but no file access can think but not act. Together, they make general agents truly capable.

Why General Agents That Write Code Win

Here is what Anthropic discovered when they released Claude Code. People were not just using it to write software. They were using it to:

  • Manage todo lists
  • Organize files
  • Analyze spreadsheets
  • Sort through emails
  • Automate repetitive tasks

This led to a fundamental insight: general agents that write code can solve any computational problem. Code is not just for programmers. Code is the universal interface through which agents interact with computers.

Think about what this means. A specialized "photo organizer" tool can only do what its creators built into it. Ten features, maybe twenty. If your needs do not match those features, you are stuck.

But a general agent that writes code has no such limits. Whatever you can describe, it can build. Your specific situation, your exact requirements, your unique combination of needs. The agent writes code that fits your problem precisely.

The Specialist Trap

Imagine you need work done on your house. The traditional approach is to call specialists:

  • Leaky faucet? Call a plumber
  • Broken light? Call an electrician
  • Squeaky door? Call a carpenter

Each specialist is good at their one thing. But this approach has problems:

  1. You need to know which specialist to call
  2. If your problem spans two areas, you are coordinating between experts
  3. If you have a truly novel problem, you might not find anyone who can help

Early approaches to building helpful software worked the same way. A "research agent" for gathering information. A "finance agent" for calculations. A "writing agent" for content. Each one limited to its pre-built capabilities.

The General Agent Advantage

Now imagine a different approach. Instead of specialists, you have one skilled problem-solver who can build tools for any job:

  • Need to fix the faucet? They craft the right solution
  • Need to repair the light? They figure it out
  • Need something that combines plumbing and electrical work? No problem

This is what a general agent does when it writes code. Instead of selecting from pre-built features, it writes solutions. Instead of being limited to what designers anticipated, it creates what you actually need.

Sarah's photo organization worked because the agent was not constrained by pre-built features. It wrote code that handled her exact situation:

  • Photos from multiple devices
  • Needing country-level organization
  • With duplicate detection based on actual image content, not just filenames
  SPECIALIST AGENTS                    GENERAL AGENT (writes code)

┌──────────┐ ┌──────────┐ ┌──────────────────────────┐
│ Research │ │ Finance │ │ │
│ Agent │ │ Agent │ │ One agent + code = │
│ (search) │ │ (calc) │ │ unlimited capabilities │
└────┬─────┘ └────┬─────┘ │ │
│ │ │ "Describe your problem, │
┌────┴─────┐ ┌────┴─────┐ │ I'll build the tool" │
│ Writing │ │ Data │ │ │
│ Agent │ │ Agent │ └──────────────────────────┘
│ (draft) │ │ (clean) │
└──────────┘ └──────────┘ Novel problem? No problem.
Cross-domain? No problem.
Novel problem? Unique combo? No problem.
Which agent do you call?

The Five Powers of Code

Why is code such an effective interface for agents? Because code gives agents five distinct powers that nothing else provides.

Power 1: Precise Thinking

Watch what happens when you ask a general agent to calculate something complex. If it tries to reason through the calculation in words, it might make mistakes. Language is fuzzy:

  • "About 30%" could mean 28% or 32%
  • "A few hundred" could mean 200 or 500

But when the agent writes code to do the calculation, something changes. The code executes with perfect precision. 127 times 89 always equals 11,303. No approximation, no drift, no fuzzy thinking.

Story: The Budget Analysis

Marcus needed to analyze his small business expenses. He had a year of transactions and wanted to know:

  • Average monthly spending by category
  • Which months had unusual spikes
  • How spending compared quarter over quarter

If he just asked for "a summary," the results would be vague. But the general agent wrote code that processed every transaction precisely. It:

  1. Calculated exact averages down to the cent
  2. Identified months that were more than two standard deviations from the mean
  3. Produced quarter-by-quarter comparisons with specific percentages

The code did not approximate. It computed. That precision came from code being the interface between the agent's understanding and the computer's execution.

What the agent actually wrote (simplified):

import csv
from statistics import mean, stdev

with open("expenses.csv") as f:
rows = list(csv.DictReader(f))

# Exact averages by category
by_category = {}
for row in rows:
cat = row["category"]
by_category.setdefault(cat, []).append(float(row["amount"]))

for cat, amounts in by_category.items():
print(f"{cat}: ${mean(amounts):.2f}/month")

# Spike detection: months > 2 standard deviations above mean
monthly_totals = {} # group by month, sum amounts
for row in rows:
month = row["date"][:7]
monthly_totals[month] = monthly_totals.get(month, 0) + float(row["amount"])

avg = mean(monthly_totals.values())
sd = stdev(monthly_totals.values())
spikes = {m: t for m, t in monthly_totals.items() if t > avg + 2 * sd}
print(f"Unusual months: {spikes}")

Notice: Marcus did not write this code. He said "analyze my expenses." The agent translated his intent into precise computation. That is the principle in action.

Power 2: Workflow Orchestration

Many tasks involve multiple steps. First do this, then check that, then based on the result, do something else. Traditional approaches handle these steps one at a time, with back-and-forth at each stage.

Code lets the agent write an entire workflow at once. All the steps, all the conditions, all the logic, captured together. Then the whole thing runs smoothly from start to finish.

Think of it like building a train track versus pushing a cart by hand. Without code, the agent asks you at every junction: "Should I go left or right? What if it's a PDF? What if it's empty?" With code, the agent builds the entire track in advance—all the switches, all the decision points—and the train runs itself.

File arrives → Is it a PDF?
├─ Yes → Extract text → Contains "Invoice"?
│ ├─ Yes → Move to Finances/
│ └─ No → Move to Documents/
└─ No → Is it an image?
├─ Yes → Move to Images/
└─ No → Move to Other/

This decision tree runs automatically. No back-and-forth. No interruptions. The code handles every branch.

Consider a job applicant tracking applications across emails, spreadsheets, and job sites. An agent could write code that scans emails for confirmations, cross-references a spreadsheet, calculates days since each application, and generates a prioritized follow-up list. This is not one simple task—it is a workflow with multiple data sources, conditional logic, and calculated outputs. Code lets the agent orchestrate all of it as a coherent whole.

Power 3: Organized Memory

Agents often need to work with lots of information:

  • Documents and data
  • Intermediate results
  • Context from earlier steps

How do they keep track of it all?

File systems provide the answer. The agent can create files to store information, read files to retrieve it, search through files to find what it needs, and organize files into meaningful structures.

Imagine researching a dozen electric vehicles across range, price, reliability, and satisfaction. An agent can gather data from multiple sources, save each piece to organized files, cross-reference results into comparison tables, and generate a final report. The agent creates folders for each model, files for different data types, and summary documents. Without file system access, the agent would struggle to manage all that information. With it, the agent has organized memory that persists across the entire research process.

Power 4: Universal Compatibility

Different systems store data in different formats:

  • Spreadsheets
  • Databases
  • PDFs
  • Web pages
  • Specialized file types

Different services have different ways of being accessed. This fragmentation could make integration impossible.

But code can read any format, transform any data, and connect to any service. Code serves as a universal translator between systems that were never designed to work together.

Story: The Event Planning Merge

Aisha was planning a large family reunion. She had:

  • Guest information in a spreadsheet
  • Dietary restrictions in email threads
  • RSVP responses from a web form
  • Flight itineraries in PDF attachments

A general agent needed to bring all of this together. The agent wrote code that:

  1. Read the spreadsheet for guest names and contact info
  2. Parsed the emails for dietary notes
  3. Pulled data from the web form for RSVPs
  4. Extracted arrival times from the PDFs
  5. Merged everything into a unified guest list with all relevant details

No single tool was designed to handle this combination of sources. But code could interface with all of them, making the agent universally compatible.

Power 5: Instant Tool Creation

Sometimes you need a custom tool that does not exist:

  • A specific calculation for your situation
  • A particular way of processing your data
  • A unique automation for your workflow

Code lets agents create these tools on demand. You describe what you need, the agent writes code, and suddenly you have a tool that does exactly that thing.

Imagine managing a community garden and needing to track plot assignments, water usage, harvest yields, and volunteer hours. No garden management app does quite what you need. A general agent can build exactly the right tool: code that tracks your specific data points, calculates the metrics you care about, and generates weekly reports in the format that works for your community newsletter. The agent does not find an existing tool—it creates one. Anything you can describe, the agent can build.

What This Means for You

Understanding this principle changes how you work with general agents.

Describe What You Want, Not How to Do It

Your job is to be clear about what you need. The agent's job is to figure out how to accomplish it through code.

Less EffectiveMore Effective
"Can you write a Python script that uses the os module to walk through directories and rename files?""I have 500 files with random names. I want them renamed to include the date they were created, in the format YYYY-MM-DD, followed by the original name."

The second version focuses on the outcome you want. It gives the agent freedom to write whatever code accomplishes that goal.

Be Specific About Your Situation

The more precisely you describe your situation, the better the agent can tailor the solution.

Vague:

"Organize my files."

Specific:

"I have files in three folders: Downloads, Desktop, and Documents. I want all PDFs moved to a folder called 'PDFs', all images to 'Images', and all spreadsheets to 'Spreadsheets'. Files older than one year should go into an 'Archive' subfolder within each category."

Specific descriptions help agents write code that fits your exact needs.

Trust the Process

When a general agent writes code to solve your problem, you do not need to understand every line. What matters is whether the result matches what you wanted.

The collaboration loop works like this:

  1. You describe what you want
  2. The agent writes code to accomplish it
  3. You verify the results
  4. You refine if something is not quite right

If something is wrong, describe what you expected versus what you got. The agent will adjust the code.

The Bigger Picture

This principle connects to the core thesis of this book. General agents are powerful because they are not limited to pre-built capabilities. They can write code to solve any computational problem.

Code is the universal interface between agents and computers. Through code, agents can:

PowerWhat It Enables
Precise ThinkingExact calculations without fuzzy approximations
Workflow OrchestrationMulti-step processes that run smoothly
Organized MemoryPersistent storage across complex tasks
Universal CompatibilityWorking with any format or system
Instant Tool CreationCustom solutions built on demand

This is why "all agents will become coding agents," as Davis Treybig (Partner, Innovation Endeavors) observed. Specialized agents with fixed features will always be limited. General agents that write code can do anything.

The Catch: Code Must Actually Work

There's an important caveat to everything we've discussed. LLMs sometimes generate code that looks correct but isn't.

The agent might:

  • Misunderstand your intent and solve the wrong problem
  • Use a function that doesn't exist or works differently than expected
  • Write logic that fails on edge cases you didn't mention
  • Make assumptions that don't match your actual data

This isn't a flaw—it's the nature of probabilistic language models. They're remarkably capable, but they're not compilers. They don't execute code in their heads; they predict what correct code looks like.

Code is powerful, but only when it actually works. A beautiful program that crashes on your data is worthless. An elegant solution that misunderstands your requirements wastes your time.

This is why the next principle is essential.

In the next lesson, we will explore Principle 3: Verification as a Core Step. The power of code demands the discipline of verification. You'll learn how to confirm that what the agent built actually does what you intended—before you trust it with your real work.

Try With AI

Prompt 1: See the General Agent Advantage

I want to understand why general agents that write code are more powerful than specialized tools.

Here is my situation: I have a folder with hundreds of receipts. Some are photos from my phone, some are PDFs from email, and some are screenshots. I need to:
1. Extract the date and amount from each receipt
2. Categorize them (groceries, dining, transportation, etc.)
3. Create a monthly summary showing totals by category
4. Flag any unusually large purchases

Walk me through how you would approach this. Do not write actual code, since I am still learning. Instead, explain:
- What different steps would you take?
- How does this approach give you flexibility that a pre-built receipt app would not have?
- Which of the Five Powers are you using?

What you are learning: You are seeing how a general agent thinks about solving a problem. Notice how the agent can handle your specific combination of requirements rather than forcing you to fit pre-built features.

Prompt 2: Experience the Five Powers

I want to understand the Five Powers that code gives to general agents.

Pick an everyday task: planning a dinner party for 12 people with various dietary restrictions.

Show me how each power would help you handle this task:

1. **Precise Thinking:** How would code help calculate quantities and portions exactly?
2. **Workflow Orchestration:** What multi-step process would you create?
3. **Organized Memory:** How would files help track all the details?
4. **Universal Compatibility:** What different formats or sources might you need to work with?
5. **Instant Tool Creation:** What custom mini-tools might you build?

Help me see that these powers are not about programming. They are about what becomes possible when an agent can write code to solve problems.

What you are learning: You are experiencing how each power contributes to solving real problems. The dinner party is not a "coding task," but a general agent can handle it beautifully through these five powers.

Prompt 3: Practice Describing Problems

Help me practice describing problems in ways that help you write effective solutions.

I will give you three vague requests. For each one, help me make it specific enough that you could write code to solve it.

Request 1: "Help me manage my passwords better."
Request 2: "I want to read more books this year."
Request 3: "Keep track of my exercise."

For each request:
- Point out what is vague or ambiguous
- Ask me questions that would make it specific
- Show me what a clear, specific version would look like

Then explain how the specific version helps you write better code.

What you are learning: You are developing the skill of clear problem description. This is your main contribution to the human-agent collaboration. The clearer you describe what you want, the better code the agent can write to achieve it.

Summary

General agents are powerful because they write code. Code is the universal interface through which agents interact with computers to accomplish any task.

This principle explains why specialized tools with pre-built features will always be limited. A photo organizer app can only do what its designers built in. But a general agent can write whatever solution your specific situation requires.

Code gives agents five powers:

  1. Precise Thinking through exact calculations
  2. Workflow Orchestration through multi-step programs
  3. Organized Memory through file systems
  4. Universal Compatibility through the ability to work with any format
  5. Instant Tool Creation through writing custom solutions on demand

Your role in working with general agents is to describe what you want clearly and specifically. Focus on outcomes, not methods. Be precise about your situation. Then verify that the results match your intentions.

"All agents will become coding agents." This is not a prediction. It is already happening. Understanding why prepares you for a world where the most capable help comes from agents that can write code to solve any problem you bring them.

Safety Note

Code is powerful—but code that runs on your real data can cause real damage. Before letting an agent run generated code on important files, always: (1) work on copies, not originals, (2) review the code's intent even if you don't understand every line, and (3) verify the results before deleting your backups. The next lesson (Verification) covers this in depth.