Skip to content
nishantkumar1292Public

About

A demonstration about how tools can be constructed on the fly by agents, and they persist to be used by agents in other sessions

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

ToolForge 🔨

Chat with an agent that forges its own tools — and shares them with other agents.

You type a request. The agent checks a shared registry for a tool that fits; if none does, it forges a new tool on the spot, validates it in a sandbox, publishes it, and uses it. Tools persist to registry.json, so a tool forged in one conversation is available to the next session — or to any other agent that reads the registry. That's the whole idea: tools created on the fly, shared.

It's a tiny take on LLMs as Tool Makers (LATM): a powerful "maker" writes the tool once, a cheap "user" reuses it forever.

  you › sort these words: banana, apple, cherry
  🔨 forged sort_words()  (Sort a list of words alphabetically)  [validated 6/6]
  agent › apple, banana, cherry
         🔨 via sort_words()  ·  just forged this turn  ·  used 1/1×

  you › please alphabetize: orange, kiwi, banana      # ← even a later session
  agent › banana, kiwi, orange
         ♻️  via sort_words()  ·  reused from the registry  ·  used 2/2×

Run it

Managed with uv:

uv run chat.py            # offline, deterministic — sort / brackets / scheduling / dates
uv run chat.py --real     # live Claude — the maker can invent a tool for ANY request
uv run chat.py --fresh    # start from an empty registry

Offline mock mode needs nothing; --real needs anthropic (installed by uv) and a key. Set it once in a .env file (auto-loaded, gitignored):

cp .env.example .env       # then put your ANTHROPIC_API_KEY in it

In-chat commands: /tools /examples /fresh /help /quit.

How it works

   your query ─▶ select_tool ──hit──▶ extract_arg ─▶ run in sandbox ─▶ answer
                  │ miss                                    ▲
                  ▼                                         │
                  design_tool ─▶ validate ─▶ publish ───────┘
                  (maker)        (sandbox)   (registry)

   once published, a *different* agent can discover and reuse the tool later
File Role
chat.py the REPL + forge/reuse loop
llm.py the pluggable brain: MockLLM (offline) and AnthropicLLM (real)
registry.py the shared tool store: one JSON file every agent reads from and writes to
sandbox.py runs untrusted, agent-written tool code in an isolated subprocess
tasks.py the 4 built-in families + their reference tools (mock mode)

The registry is the only thing connecting the two agents. The maker never calls the user directly — it just saves the tool to registry.json: the tool's name, description, and its actual Python source (stored as a string), plus how many times it's been used. The user reads that file, picks a tool whose family matches the request, runs the stored source, and records whether it worked. Because it's a plain file on disk, forged tools outlive the session that made them — the next chat (or a separate process) loads exactly the same tools.

A forged tool is only published if it passes all of its own validation tests in the sandbox — a buggy tool never poisons the shared registry.

Notes & next steps

  • Mock vs real: offline mode only forges the 4 built-in families (it's deterministic, no reasoning). --real can design a genuinely new tool for an arbitrary request.
  • Sandbox is process-isolation + timeout — fine for a demo, not for arbitrary internet code. Harden with no-network, read-only FS, and CPU/memory limits before trusting it further.
  • Natural next steps: semantic tool retrieval (embeddings, to scale past a handful of tools), a self-debugging maker loop, tool composition, or exposing the registry over MCP so any MCP agent can use the tools you forge here.

About

A demonstration about how tools can be constructed on the fly by agents, and they persist to be used by agents in other sessions

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages