back

by tosh·1mo ago·view on hn ↗
9 lines of python:

  import json,sys,uuid;from subprocess import getoutput as sh;from urllib.request import Request as R,urlopen
  b={"model":"gpt-5.6","prompt_cache_key":uuid.uuid4().hex,"input":[],"tools":[{"type":"custom","name":"shell"}]}
  while prompt:=input("> "):
      b["input"]+=[{"role":"user","content":prompt}]
      while True:
          o=(r:=json.load(urlopen(R(sys.argv[1],json.dumps(b).encode(),{"Content-Type":"application/json"}))))["output"]
          b["input"]+=o;calls=[i for i in o if i["type"]=="custom_tool_call"];used=r["usage"]["total_tokens"]/10500
          if not calls: print(o[-1]["content"][0]["text"],f'\n[{used:06.3f}%]'); break
          b["input"]+=[{"type":"custom_tool_call_output","call_id":i["call_id"],"output":sh(i["input"])} for i in calls]
2 comments
nb:

- stdlib only, 0 external dependencies

- works with openai compatible api (including local models)

- shows context usage in % when turn goes back to user

- cache friendly (keeps stable prefix and provides uuid v4 as session cache key)

- uses 'shell' as open ended tool

'shell' as tool name is sufficient context for gpt 5.6 sol

Every Lisp program can be written in one line.