agent in 9 lines python An engineer created a minimal AI agent in just 9 lines of Python code, using a custom tool to execute shell commands and a loop that processes user input through a language model. The agent, which calls a remote model endpoint, demonstrates a compact implementation of tool-use and conversation management. | 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 |