How much of an AI agent is the framework, and how much is just a loop?

Reddit r/AI_Agents Tools

Summary

作者对比了手写 agent loop 和使用 LangGraph create_agent 构建购物助手,说明框架本质上是帮你运行同样的循环,并额外提供 checkpointer 记忆、流式输出、重试和追踪。建议先手写循环理解原理,再用框架落地。

When I started using LangGraph I couldn't tell which part was the framework and which part was the model. To get an understanding, i built a shopping assistant without any framework first. It has two tools, one searches a product catalogue and one fetches the details of a single product. The whole agent is this function: ```python def run_agent(user_message, max_steps=6): messages = [ {"role": "system", "content": SYSTEM_PROMPT}, {"role": "user", "content": user_message}, ] for step in range(1, max_steps + 1): response = client.chat.completions.create( model=MODEL, messages=messages, tools=TOOL_SCHEMAS, temperature=0.1, extra_body=EXTRA_BODY, # provider-specific; empty for non-NVIDIA ) message = response.choices[0].message messages.append(message) # remember what the model said # No tool calls -> the model gave its final answer. if not message.tool_calls: return message.content # Otherwise: run each requested tool, feed the result back, loop. for call in message.tool_calls: name = call.function.name args = json.loads(call.function.arguments) result = TOOL_FUNCTIONS[name](**args) messages.append( {"role": "tool", "tool_call_id": call.id, "content": result} ) return "Stopped: reached the step limit without a final answer." ``` The model only asks for a tool and runs nothing. The loop runs the function, appends the result as a message, and calls the model again. When a response comes back without tool calls, that's the answer. I first read max_steps as a safety net. It's really a budget, because every pass through the loop is one API call. A question that needs five tool uses costs six calls. Then I built the same agent with LangGraph's create_agent. The function above becomes three lines. But print the message list after a run and it's the same sequence: user message, the model asks for tools, tool results, final answer. The framework runs the loop for you. It doesn't replace it. What it does add is memory. The raw loop starts with an empty message list on every call, so "Show me your hiking boots" followed by "Which of those is waterproof?" goes nowhere. With a checkpointer the second question works. Add streaming, retries and tracing, and that's real work you'd otherwise build yourself. My take: write the loop once to learn it, use the framework when you ship. If you start with the framework, the loop is magic, and you can't debug magic. I wrote this up as part of a tutorial that runs on a laptop without a GPU, against any OpenAI-compatible endpoint including Ollama. Link to the article in the comments. Did you start with a raw loop or with a framework? What do you wish you'd known earlier?
Original Article

Similar Articles

@Huahuazo: I want to understand how to build an Agent from scratch, not just call APIs—I've looked through many resources, and they're either too abstract or just hand you a finished product to tweak parameters, leaving the 'why design this way' part basically blank. LangChain's official Agents From Scratch...

X AI KOLs Timeline

LangChain's official Agents From Scratch tutorial provides a detailed guide on how to build an AI agent from scratch with human-in-the-loop and memory capabilities, covering four parts: basic setup, evaluation system, human-in-the-loop (HITL), and long-term memory.

@cellinlab: https://x.com/cellinlab/status/2064144608242679822

X AI KOLs Timeline

This article introduces the concept of Loop Engineering — instead of directly writing prompts for AI agents, it designs a system (loop) that recursively lets the agent iterate on tasks until completion. The article provides a detailed comparison of how Claude Code and Codex implement five building blocks: automations, worktrees, skills, sub-agents, etc. It suggests this could be the future trend of collaborating with coding agents, but also warns about token costs and AI slop issues.

@antiAIvo: How to Handwrite an Agent from Scratch? I Put Together an Agent Tutorial in 18 Parts Coding agents like Claude Code and Codex are really just a loop at their core: The model requests tools, code executes, the result goes back into the conversation, until the model stops requesting This tutorial starts from 100 lines of code and builds up layer by layer in Python:...

X AI KOLs Following

Shared a complete 18-part handwritten Agent tutorial, starting from 100 lines of Python and progressively building tool calling, permissions, context management, Skills, chat platform integrations, scheduled tasks, MCP, sub-Agents, planning, and memory. Each lesson also compares how mainstream Agents like Claude Code, Codex, Grok Bot, and DeepSeek Harness approach the same problems. The biggest takeaway: mainstream products mostly diverge on one question — should the security layer be handled by prompts or by code?

This article systematically reviews AI Agent architecture and engineering practices, covering control flow, context engineering, tool design, memory, multi-agent organization, evaluation, tracing, and security. It is based on the OpenClaw implementation and emphasizes the critical role of Harness (testing and validation infrastructure) for system stability.

X AI KOLs

This article systematically reviews AI Agent architecture and engineering practices, covering control flow, context engineering, tool design, memory, multi-agent organization, evaluation, tracing, and security. It is based on the OpenClaw implementation and emphasizes the critical role of Harness (testing and validation infrastructure) for system stability.

@yibie: Every programmer should hand-write an agent. It only takes about 50 lines of code, it's fun, and it will surprise you. But to get the most out of it, do these two things: First, write it from scratch. Open a blank text file and type every line yourself. Don't use any AI, not even autocomplete. Second, rely only on the standard library documentation…

X AI KOLs Timeline

This article encourages programmers to manually write a simple AI agent (around 50 lines of code) to deepen their understanding of how agents work, and suggests writing it from scratch while relying only on standard library and API documentation.