# agent in 9 lines python

> Source: <https://gist.github.com/tosh/6e91a9dbf08dd630c535e7345ac7f0b5>
> Published: 2026-07-22 13:19:55+00:00

| 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] |
