Two Ways an Agent Can Act
There are two main ways to let an AI agent do things: have it fill out a structured tool call, or have it write code. Most agents so far use the first. The second is catching on fast, and knowing when to use which will save you a lot of pain.
ReAct (JSON): The Classic Approach
“Reason + Act” (ReAct) has been the workhorse of agentic AI. The model outputs a structured JSON block, the system runs it, and the result gets fed back:
{"tool": "weather", "args": {"city": "NYC"}}
It’s predictable, safe and easy to debug. The model basically asks permission to use a tool, waits for the result, then decides what to do next.
Code Agents: The Newer Approach
Instead of filling in a fixed schema, the model writes a snippet of code that gets the job done. Rather than asking to use a weather tool, it might write:
import requests
weather_data = requests.get(f"https://api.weather.com/v1/weather?city=NYC").json()
temperature = weather_data['current']['temp']
print(f"The temperature in NYC is {temperature}°F")
The Core Shift: From Asking to Doing
We’re moving from models that ask to use a tool to models that write the logic to use those tools. It’s the difference between asking someone to pass you a screwdriver and just building the damn thing yourself.
How the Frontier Models Do It
Claude (Anthropic): Hybrid
For broad interactions like web search, Claude sticks with Tool Calling (structured JSON). On top of that, harnesses like Claude Code and the Claude Agent SDK can spin up sub-agents for multi-step work. That’s a feature of the harness, not something hidden inside the model, but it works like a manager handing specific tasks to specialists.
Gemini (Google): The Thinking Agent
Gemini leans on “Thinking” as Chain-of-Thought (CoT): a hidden reasoning layer where it runs a Think -> Act -> Observe loop before giving you the final answer. Google emphasizes “native” tool use, where reasoning and execution are tightly coupled inside the model.
The Thinking block is an internal monologue that keeps the messy trial-and-error out of view. You see the chef’s plated dish, not the burnt attempts and spilled ingredients.
Rule of Thumb: Don’t Overengineer
If you just need the current temperature, a JSON tool call is perfect. It’s fast, predictable and cheap.
Using a full code agent (VM spin-up, extra logic) for a basic API fetch is like using a chainsaw to cut a grape. You add complexity, security risk and latency for nothing.
When Code Agents Win
Ambiguity. When the workflow isn’t a straight line. “Clean this messy CSV and find the outliers” needs judgment, conditionals and iteration that are painful to express in JSON.
Complex data types. JSON can’t carry non-serializable objects. Try passing a live database connection, a PyTorch model object or a big binary blob through it. You end up with 20 tool definitions for something code does in one line.
Logic density. Code lets the agent run if/else, loops and data transformations locally, without a round trip to the LLM for every tiny step. That matters a lot for speed and cost.
Frameworks at a Glance
| Framework | Primary Logic | Philosophy |
|---|---|---|
| Hugging Face smolagents | Code-First | Minimalist; the agent writes Python. Extremely high efficiency for complex tasks. |
| LangGraph | State-First | Focuses on “cycles” and controlled graphs. Great for complex, repeatable business logic. |
| LlamaIndex ReAct | JSON-First | Optimized for RAG; uses tool-calling to fetch data and reason over documents. |
The Security Elephant in the Room
The Risk
A code agent is, by definition, an arbitrary code execution engine. Sooner or later it will try something you didn’t want, by mistake or through prompt injection. Plan for it.
The Fix: Sandbox Everything
Never run agent code on your host machine. Ever.
Use micro-VMs (Firecracker) or hardened containers with strict import controls. Allow only the libraries the agent actually needs (e.g., pandas, requests) and block os, sys and subprocess entirely.
Think of a chemistry lab: you don’t let interns mix whatever they want in the main building. You give them a fume hood and a shelf of approved reagents.
Choosing Your Architecture
Neither approach is “better.” It depends on the job.
Use ReAct/JSON for rigid, predictable tool use and simple API calls, in high-security environments, or anywhere you need maximum control and observability.
Use code agents for open-ended data science work, complex tasks with real ambiguity, cases where using the tools takes actual logic, and heavy data processing.
A practical default: start with JSON tool calls, and switch to a code agent only when you catch yourself writing a pile of tools to work around what a few lines of code would do.