Created
July 22, 2026 13:19
-
-
Save tosh/6e91a9dbf08dd630c535e7345ac7f0b5 to your computer and use it in GitHub Desktop.
agent in 9 lines python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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] |
Claude and I wrote this version but we didn't test it. It uses http.client (std lib) which keeps the connection open, so less overhead.
import json,sys,http.client,urllib.parse;from subprocess import getoutput as sh
url=urllib.parse.urlsplit(sys.argv[1]);c=http.client.HTTPSConnection(url.hostname);h=[];b={'model':'gpt-5.6','input':h,'tools':[{'type':'custom','name':'sh'}]}
while p:=input('> '):
h.append({'role':'user','content':p})
while True:
c.request('POST',url.path,json.dumps(b).encode(),{'Content-Type':'application/json'})
o=(r:=json.load(c.getresponse()))['output'];h.extend(o);t=[i for i in o if i['type']=='custom_tool_call']
if not t:print(o[-1]['content'][0]['text'],f'\n[{r['usage']['total_tokens']/10500:06.3f}%]');break
h.extend({'type':'custom_tool_call_output','call_id':i['call_id'],'output':sh(i['input'])} for i in t)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
see https://news.ycombinator.com/item?id=49006862 and https://gist.github.com/tosh/61aca9ffa9ea115fa4df332407d7a9a9