frontpage.
newsnewestaskshowjobs

Open Source @Github

fp.

Open in hackernews

Show HN: Agent in 9 Lines Python

https://gist.github.com/tosh/6e91a9dbf08dd630c535e7345ac7f0b5
3•tosh•1h ago
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!

Comments

JSR_FDED•33m ago
Super cool for how compact yet still readable it is. Shouldn’t there be a tool description passed to the LLM though?

The Light Flip Is the Stylish Dumb Flip Phone of Your Dreams

https://www.wired.com/story/light-flip-is-the-modern-stylish-dumb-flip-phone-of-your-luddite-dreams/
1•notpachet•2m ago•0 comments

Politician Count Binface Demands Sega Releases Shenmue 4

https://kotaku.com/count-binface-shenmue-4-sega-arcades-adele-nigel-farage-2000718341
1•robin_reala•2m ago•0 comments

AI Companies Are Buying Tons of Old Books Because They're Free of AI Slop

https://www.404media.co/ai-companies-are-buying-tons-of-old-books-because-theyre-free-of-ai-slop/
1•Brajeshwar•2m ago•0 comments

Show HN: Langy, an automated AI engineer (we gave it a robot body) [video]

https://langwatch.ai/blog/introducing-langy-your-automated-ai-engineer
1•jangletown•3m ago•0 comments

Show HN: A Sonos home-screen widget that talks directly to speakers over UPnP

https://play.google.com/store/apps/details?id=com.sonoswidget&hl=en_US
1•eyal4473•3m ago•0 comments

Show HN: I walk-forward tested classic trading setups. Several have no real edge

https://edgestacker.com/tools/library/
1•thepromptgenius•5m ago•0 comments

Show HN: Fund an agent once – prepaid USDC key for HTTP 402 tools (Solana)

https://vibes-coded.com/start
1•b_radford•5m ago•0 comments

Fujifilm X100 vs. Leica Q vs. Ricoh GR

https://map.simonsarris.com/p/fujifilm-x100-vs-leica-q-vs-ricoh
1•speckx•5m ago•0 comments

Show HN: Kernel optimization is obsolete. Just NPM install it

https://github.com/tensormux/kernel-skills
1•KRISH2832•6m ago•0 comments

Waymos cause "way mo" injuries per mile driven than for-hire vehicles in NYC

https://gothamist.com/news/are-waymo-robotaxis-actually-safer-than-nyc-uber-and-taxi-drivers
3•laserson•7m ago•0 comments

Which streaming service was that on again

https://www.timwehrle.de/blog/which-streaming-service-was-that-on-again/
3•weetii•9m ago•0 comments

Airtight – privacy-first crypto portfolio tracker,single HTML file, zero servers

https://airtight.sell.app/product/airtight-private-portfolio-tracker
1•AirTight•9m ago•0 comments

Backpropagation as Physical Relaxation: Exact Gradients in Finite Time

https://arxiv.org/abs/2602.02281
2•binyu•10m ago•0 comments

Trovio for Brands

https://brands.gotrovio.com/auth/signup
1•derrickshowers•10m ago•1 comments

Navigating abstraction in the age of machine-generated code

https://www.khola.blog/p/the-top-down-bet-needs-a-bottom-up
1•nkhola•11m ago•0 comments

Granola Discloses a 1 Click Session Takeover of Its Notes App

https://docs.granola.ai/help-center/policies/security-contributions/desktop-app-navigation-vulner...
2•bearsyankees•11m ago•1 comments

Sleight – Playwright for native Mac apps

https://sleight.sh/
1•imazio•11m ago•0 comments

Ghost Cut – or why Cut and Paste is broken everywhere

https://ishmael.textualize.io/blog/ghost-cut/
2•willm•12m ago•0 comments

Hologram works. Elixir runs in the browser

https://hologram.page/blog/backing-hologram
5•lawik•12m ago•1 comments

Libx11-Compat Is Working to Implement Xlib Atop SDL for Wayland, macOS, Android

https://www.phoronix.com/news/libx11-compat
2•arto•13m ago•0 comments

"We have information that Moonshot distilled Fable for the development of K3"

https://twitter.com/mkratsios47/status/2079933645888880708
2•softwaredoug•13m ago•1 comments

Rewriting the Futhark Type Checker

https://futhark-lang.org/blog/2026-07-21-rewriting-the-type-checker.html
2•fanf2•13m ago•0 comments

Physical Media vs. Digital Media

https://itsjustchronicallyoffline.bearblog.dev/physical-media-vs-digital-media/
3•speckx•13m ago•2 comments

Ernst's Paradox

https://www.futilitycloset.com/2026/07/20/ernsts-paradox/
1•surprisetalk•15m ago•0 comments

Ethics Is the Skill That Matters Most Now

https://agonora.com/blog/ethics-most-important-skill
2•mw67•16m ago•0 comments

Show HN: Trifle – Open-source analytics that stores answers, not events

https://trifle.io/
2•iluzone•16m ago•0 comments

Towards a Theory of Bugs: The Ruliology of the Unexpected

https://writings.stephenwolfram.com/2026/07/towards-a-theory-of-bugs-the-ruliology-of-the-unexpec...
1•Brajeshwar•16m ago•0 comments

I Built a Private Genomics Study with Stoffel MPC

https://vishakh.blog/2026/07/21/i-built-a-private-genomics-study-with-stoffel-mpc/
9•vishakh82•19m ago•0 comments

OpenAI Models Escaped and Hacked a Company in Cybersecurity Test Gone Wrong

https://www.wsj.com/tech/ai/openai-models-escaped-and-hacked-a-company-in-cybersecurity-test-gone...
2•flippyhead•20m ago•0 comments

Show HN: DataParade – generate dataflow diagrams from code for risk assessments

https://github.com/DataParade-io/dataparade-cli
4•dpdave•20m ago•0 comments