Agent in 9 Lines Python
I asked myself: what would a minimal implementation of an agent look like? Something that works out of the box, is a real agent with tool calling, but without 1000s of lines of code, without dozens or hundreds of npm or pypi dependencies. Something with just a few 'essential' features (not a whole kitchen sink that most agent harnesses come with nowadays). An implementation close to pseudocode that you can look at in one page, everything there at a glance, no scrolling. This is the agent.py I ended up with so far: import json,sys;from subprocess import getoutput as sh;from urllib.request…
In plain words
Agent in 9 Lines Python is a minimal implementation of an AI agent with tool calling capabilities, designed to work out of the box with minimal dependencies. Written in just nine lines of Python code, it enables an agent to interact with users and execute shell commands through a simple, readable implementation. The project is intended for developers who want to understand how agents work or build lightweight agent functionality without the complexity and bloat of larger frameworks.
written from the facts on this page · September 2026
From the sources
In the maker’s words, at launch
I asked myself: what would a minimal implementation of an agent look like? Something that works out of the box, is a real agent with tool calling, but without 1000s of lines of code, without dozens or hundreds of npm or pypi dependencies. Something with just a few 'essential' features (not a whole kitchen sink that most agent harnesses come with nowadays). An implementation close to pseudocode that you can look at in one page, everything there at a glance, no scrolling. This is the agent.py I ended up with so far: import json,sys;from subprocess import getoutput as sh;from urllib.request import Request as R,urlopen url=sys.argv[1];h=[];b=dict(model="gpt-5.6",input=h,tools=[dict(type="custom",name="sh")]) while p:=input("> "): h+=[dict(role="user",content=p)];H={"Content-Type":"application/json"} while True: o=(r:=json.load(urlopen(R(url,json.dumps(b).encode(),H))))["output"] h+=o;c=[i for i in o if i["type"]=="custom_tool_call"];z=r["usage"]["total_tokens"]/10500 if not c:print(o[-1]["content"][0]["text"],f'\n[{z:06.3f}%]');break h+=[dict(type="custom_tool_call_output",call_id=i["call_id"],output=sh(i["input"])) for i in c] It is a bit code golfed but I think it is fairly readable - imports are all from stdlib (0 external dependencies!) - assumes there is an inference api endpoint running somewhere - assumes the inference api endpoint is openai-like - model hardcoded to "gpt 5.6" (=> Sol), can easily be changed to e.g. open weight (kimi k3, glm 5.2 etc) - api endpoint url is passed as arg to the python script - configures only 1 custom tool: 'sh' - 'sh' is sufficient for interacting with the environment in an open ended way - new api output gets added to history ("h") - if api output contains tool calls the tool calls get executed - agent gives control back to user when the last model response is without tool calls - agent message to user shows % of context window used Noteworthy: no dependencies other than python stdlib (!) - less startup time - less dependency churn - less supply chain attack vector surface - less code to verify and understand no mcp, no plugins, no security theater - if you want to add something specific: add it explicitly - adapt the environment to give the agent access or restrict access to tools, resources, network etc (the env is the security boundary, not the harness) no system prompt - every token in context window is precious - current strong models do fine without steering via system prompt (or are even harmed by long overly specific system prompts designed for models from months ago) - system prompt or agents.md context can easily be added if needed (agent can also discover it or get prompted to read from environment as is) how to run/deploy the agent - design the environment you want to give the agent (container, docker, sandbox of your choice) - start an inference api endpoint that is openai-like (support the request/response shape used in agent.py above) - inference api endpoint can be as simple as a proxy to openai api that adds credentials/api key - adapt as you want/need it, change the model, remove/alter context window behaviour, add tools, etc etc Looking for any feedback you have to make it more clear or even simpler!
More ai this month
the category →
I trained a 125M-parameter transformer to autocomplete piano performances in real time (~108 notes/sec on an iPhone 15). The idea is basically GitHub Copilot or Tabnine, except instead of prompting it with code, you prompt it by playing a few notes on a MIDI piano. The model then continues what you played, entirely on-device. The app is free if anyone wants to try it. Happy to answer questions about the model, training, Core ML, or the many things that didn't work.
AI · 16d ago · simedw.com
Astute▲585Automate your B2B brand going viral, with new media creators
AI · 18d ago · company-app.joinastute.com


Hey HN, Henry from Cactus here! We previously released Cactus Needle, a 14MB agentic LLM for tool call, device use, and structured extraction for phones, wearables, smart homes, small robots and microcontrollers. We got really great feedback here, and have now incorporated the suggestions to release Needle 2. The whole model is a single 14MB binary that runs a full session in 28MB of RAM; 45m parameters at 2bit compression. Needle hits 500 tokens/sec decode speed on a Raspberry Pi 5, sits between 400-1,500 tokens/sec on VR devices like Meta Quest 3S and Apple Vision Pro, and ranges…
AI · 26d ago · cactuscompute.com


Launched alongside, July 2026
the whole month →- IR
I might be the only SRE on Earth with his own bowling center. It's a more in-depth gig than you'd think. My family and I bought an abandoned 8-lane bowling center in the rural mid-west. In our small town there weren't many recreation options for families. You've heard of a food desert? This is an R&R desert. It had been abandoned for a good reason. The roof leaks, the electrical system was constantly surging, and my 70-year-old bowling equipment (still) doesn't work perfectly. The system that keeps your score is particularly interesting to me. It's the thing you watch during your game, but…
Life & fun · Jul 2026
- EElevators▲1,680
Life & fun · Jul 2026 · john.fun
- 1W18 Words▲1,160
Life & fun · Jul 2026 · 18words.com
- BA
Over the past few months, our team has been building more and more slidedecks using web frontend technologies with coding harnesses like Claude Code, but a common complaint is to make even small edits we need to edit the code either manually or via the harness. To avoid this loop, I ended up creating Bento, a single HTML file with everything you need in a slide tool including animations and shared editing. There's no install or cloud login, everything works offline. The default deck is around 560 KB and it doesn't need to fetch anything once you got it. Open it in a browser and then you can…
Dev tools · Jul 2026 · bento.page
- GG
A few days ago I found myself trying out GLM 5.2 and was really positively impressed. The capabilities and security I was getting from this LLM are similar to those I've gotten from models like Claude or GPT, and this really surprised me. But then I thought, "I wonder how it would work on a normal computer like mine," and above all, "I wonder if it would work without going into OOM on a computer like mine." So I started working with the help of agents to test this possibility. I started converting the model to int4, understanding MTP usage, and if possible implementing DSA for long context.…
AI · Jul 2026 · github.com
