You should write an agent
TL;DR Highlight
A 15-line loop plus a ping tool became an agent that checks multiple hosts on its own
Who Should Read
An LLM API developer who uses Claude Code or Cursor but has no feel for how an agent loop works inside
Core Mechanics
- The context window is just a list of strings
- The illusion of memory comes from resending all prior inputs and outputs on every call.
- The LLM itself is a stateless black box.
- Tool calling is one extra loop
- Each call includes the tool list, and the LLM emits a special response when it wants a tool run.
- Your Python loop runs it, appends the result to the context, and calls the model again.
- One ping tool replaced a hand-written loop
- The author never wrote a loop to ping google.com, www.google.com and 8.8.8.8.
- Given permission to ping, the LLM figured out the rest.
- MCP is not essential, the author argues
- MCP is just a plugin interface for getting your tools into code you don't control, like Claude Code or Cursor.
- Writing your own agent means dealing in APIs, not plugins.
- Context engineering is ordinary programming
- Inputs, outputs, tool descriptions and tool results all eat a fixed token budget.
- Past a threshold, the system gets nondeterministically stupider.
- Sub-agents are just another context array
- Make a new context array, call the model again, and give each call different tools.
- You can have them summarize each other or build trees, and the author says an idea takes about 30 minutes to code.
Community Reactions
- Agent in 25 lines of PHP
- One commenter wrote an agent in 25 lines of PHP two years ago and found it effective even before tool calling existed.
- They view LLMs as Unix tools like sed or awk that you can compose, loop and branch.
- Hacking on a self-built coding agent
- A commenter said swapping models, adding memory and adding voice transcription each took only minutes.
- They noted Cerebras is very fast for many-turn tool calls, though gpt-oss 120b is not as good as frontier models.
- Toy versus production pushback
- Commenters argued compaction, security, sandboxing, planning and custom tools are hard to get right.
- Another said the last 10% of polish is where the work is.
- Debugging pain and local agents
- One commenter said agents fail at random steps like 17 or 41, are hard to reproduce, and waiting 10-20 minutes per run is painful.
- Another recommended building a local agent on llama.cpp or vllm to see how much control cloud APIs take away.
How to Apply
- Today in 30 minutes: run the ping agent
- Paste the prompt below into Claude Code to generate one Python file, set OPENAI_API_KEY, and run it.
- Log every tool call to see what the LLM decides to call by itself.
- Wire one of your own APIs into the loop
- Wrap an internal API as a JSON tool definition plus a function and add it to the loop.
- Compare how much code that takes versus going through an MCP server.
- Log token usage per call
- Record how many tokens inputs, tool descriptions and tool outputs take on each call.
- If many tools crowd the window, split work into sub-agents with separate contexts and tool sets.
Try It
# Paste into Claude Code (prompt that builds the article's agent example)
Create a single Python file agent.py.
- Use the openai package's Responses API (model="gpt-5").
- Keep context as a list of messages and append each user input and response.
- Define one tool, ping(host). Run `ping -c 5 host` via subprocess and return stdout.
- If the response has a function_call, run it, append function_call_output to the context, and call again. Repeat until no more tool calls.
- Print `tool call: ping <host>` on every tool call.
- Build a chat loop that reads input() with a "> " prompt.
Install: pip install openai. When done, test it with "describe our connectivity to {{target domain}}".Terminology
Related Papers
Frostbite: A new CPU architecture discovered, designed and verified by AI
AI agents designed a CPU from scratch, claiming 4.59x perf/W over a traditional core
Restricting AI agents in mobile operating systems platforms from capturing data
Signal now blocks OS-level AI agents from reading its screen on iOS 27 and Android
Actions Speak Louder than Words: Stateful Privacy Sniffing of LLM Agents via Behavioral Covert Channels in Web Interactions
Agents' link choices alone let attackers rebuild user queries at F1 0.89; SOR cuts it to 0.39.
Tracking and Limiting Unsupported Claim Propagation in Multi-Agent LLM Systems: A Provenance-Aware Framework
Passing claims with source, evidence and history kept equivalence at 5 agent stages at 96% versus 31%.
LLM assisted reverse engineering
Pointing an agent at binaries with skills and MD notes made years-long hacks feasible
Metrics-in-the-Loop: Complexity Feedback Reshapes Agent-Written Code
Injecting per-turn complexity reports into coding agents cut code erosion without changing correctness
Why is Gemini 4 Carbon taking so long?
Carbon took nearly an hour on bug fixes that Astra and Opus finished in minutes, mostly from extra unrequested work.
Weight-Space Programming builds neural networks like a 1990s researcher
LLM hand-wrote MNIST weights to 91.3%, using 1990s-style techniques