Hugging Face just dropped Agents.js, a library that turns plain-text commands into JavaScript code generated by an LLM. You ask for a picture of a rubber duck in a top hat with a caption, and the model writes the code to call a text-to-image tool, then an image-to-text tool, then stitches the results together. Installation is a single npm command, and the API surface is deliberately small: instantiate an HfAgent with a token, call generateCode, then evaluateCode.

The default LLM is OpenAssistant’s oasst-sft-4-pythia-12b-epoch-3.5 running on Hugging Face’s Inference API. But the library treats LLMs as swappable async functions, so you can plug in OpenAI’s text-davinci-003 with a few lines of code. Tools work the same way. Each tool is a named object with a description, examples for few-shot prompting, and a call function. The English-to-German translation example in the docs shows exactly how to wire a custom tool into the agent.

There’s a security warning worth reading twice. The run method executes generated code directly, which means arbitrary code evaluation in your browser or Node environment. Hugging Face recommends using generateCode and evaluateCode separately so you can inspect the code before it runs. That’s the right call for anything beyond a sandboxed demo.

What’s interesting here is the architectural bet: instead of prompting an LLM to call a rigid function-calling API, you’re letting it write actual JavaScript that composes tools freely. That flexibility is powerful, but it’s also what makes the security warning necessary. The rubber duck example works because the generated code is simple. Whether this approach scales to multi-step workflows where the model needs to handle errors, retries, or conditional logic remains an open question. The library gives you the building blocks; it doesn’t yet answer how robust the generated code will be in the wild.