From Job Description to Colleague: Building Your First AI Agent in 100 Lines
Agents turn AI from a prompt-driven chatbot into an autonomous worker that can run multi-step jobs unattended, audit its own decisions, and collaborate with other specialized Agents. The difference in output quality between a single overloaded Agent and a team of narrowly-scoped Agents is the difference between "barely usable" and "needs no edits."
The core distinction between a Skill and an Agent is autonomy. A Skill is a passive Markdown document that executes a fixed process only when triggered. An Agent runs a ReAct loop—observe, think, act, evaluate—deciding its own next steps, retaining short- and long-term memory, and handing off tasks to other specialized Agents. The OpenAI Agents SDK makes this practical in roughly 100 lines of Python.
Two working examples are built from scratch. First, a single Research Agent that breaks a question into sub-questions, searches the web via Tavily, evaluates whether information is sufficient, and writes a structured report to disk—with hard limits on search rounds to prevent infinite loops. Second, a three-Agent dev team: a PM Agent produces a technical spec, a Coder Agent implements it, and a Reviewer Agent checks the code against acceptance criteria. If the review fails, the Reviewer hands back to the Coder automatically, with a retry cap enforced by an outer loop.
Five hard-won pitfalls are detailed: mistaking a long prompt for an Agent, overloading a single Agent with too many tools (accuracy drops from ~90% to ~50%), building an omnipotent Agent that does everything poorly, forgetting to set `max_turns` (one Agent burned $3.20 in tokens running 47 searches unattended), and skipping human-in-the-loop for destructive operations like `rm -rf`. Model switching—to local Ollama for privacy, to Claude via LiteLLM, or to enterprise vLLM—is covered with concrete code changes.
The ReAct loop is the irreducible core of agency—without it, even a 3,000-character System Prompt is just a chatbot with a long instruction manual.
Tool count is a sharp accuracy lever: the jump from 5 to 30 tools cuts reliability roughly in half, making narrow-scope Agents a practical necessity rather than an architectural preference.
Token economics invert intuition—tool return values, not model reasoning, consume half the budget, so return-value truncation is the single highest-leverage cost control.
The PM-Coder-Reviewer Handoff pattern with automatic rejection-and-retry mirrors a real team's quality loop, and the quality jump from self-review to independent review is immediate and measurable.
The individual-vs-enterprise split is not about capability but about infrastructure overhead; a single `.py` file and `.env` suffice for personal use, while enterprise demands K8s, Vault, and audit logging.
Local 7B models can run Agents but at ~60% success rate versus 95%+ for GPT-4o on the same task, making them viable only for simple, high-frequency, or privacy-sensitive workloads.