Introducing Agents.js: Give tools to your LLMs using JavaScript
Agents.js is a JavaScript library from huggingface.js that gives LLMs tool access in the browser or on Node. An HfAgent turns a plain-text command into JavaScript that chains multimodal tools such as textToImage, imageToText and textToSpeech, then evaluates that code and returns messages carrying strings or Blobs. Any async string-to-string function can stand in as the LLM, with OpenAI shown as an example, and custom tools are defined with a name, description, few-shot examples and a call function. Because the agent executes arbitrary generated code, generateCode followed by evaluateCode is recommended over run, so the code can be reviewed before it executes.
Related posts
- Introducing smolagents: simple agents that write actions in code.
Hugging Face mediumAdeptsmolagents is a minimal Python library from Hugging Face for building LLM agents, with first-class support for code agents that write their actions as Python code instead of JSON tool calls. Agency is framed as a spectrum from simple output processing to multi-step and multi-agent loops, and the post advises using deterministic workflows unless tasks genuinely need flexibility. Code actions are argued to beat JSON for composability, object handling, generality and training-data coverage. The library supports sandboxed execution via E2B, custom tools defined with a @tool decorator and shareable on the Hub, any LLM via transformers, the HF inference API or LiteLLM, and a benchmark shows open models competitive with closed ones on agentic tasks.
- Tiny Agents in Python: a MCP-powered agent in ~70 lines of code
Hugging Face mediumAdeptHugging Face's huggingface_hub Python SDK now includes an MCP client and a minimal Agent class, letting an LLM pull tools from MCP servers (stdio, SSE or streamable HTTP) and call them during inference. Install it with `pip install "huggingface_hub[mcp]"`, then run agents from the `tiny-agents` CLI, configured by an agent.json that sets model, inference provider and MCP servers, plus an optional PROMPT.md. The MCPClient connects to servers, converts their tool schemas into OpenAI-style function definitions, and streams chat completions while rebuilding tool calls. It then routes each call to the right MCP session. The Agent is essentially a while loop on top of the client, with special exit-loop tools to end a turn.
- Tiny Agents: an MCP-powered agent in 50 lines of code
Hugging Face mediumAdeptAn LLM agent built on the Model Context Protocol reduces to a simple while loop around an MCP-aware inference client: connect to MCP servers, convert their tools into OpenAI-style function definitions, pass them to the chat-completion call, execute returned tool calls via the MCP SDK, and feed results back. The TypeScript implementation in huggingface.js extends InferenceClient into an McpClient that holds one session per server and maps tool names to sessions. An Agent class adds a system prompt plus two control-flow tools (task_complete, ask_question). The loop alternates tool calls and results until an exit tool is called, the model answers twice without tools, or a turn limit is reached. The default setup uses Qwen2.5-72B on Nebius, and the model, provider and MCP servers can be swapped.
- Tool Use, Unified
Hugging Face mediumAdeptHugging Face Transformers extends Jinja chat templates to cover tool use, giving a single portable API for passing tools to Mistral, Cohere, NousResearch and Llama models. Tools are defined as JSON schema, or as Python functions whose type hints and docstrings are converted automatically via get_json_schema. Tool calls go into the chat as a tool_calls field on assistant messages, and results are added as separate tool-role messages. A full walkthrough with Hermes-2-Pro-Llama-3-8B shows the loop end to end. Parsing the model's emitted tool-call text is still model-specific and needs a little json.loads or regex work.
- Designing the hf CLI as an agent-optimized way to work with the Hub
Hugging Face mediumAdeptHugging Face rebuilt its hf CLI to serve both humans and coding agents. It detects agents via environment variables like CLAUDECODE and CODEX_SANDBOX and switches to untruncated, ANSI-free TSV output, sends hints and errors to stderr, fails fast instead of prompting, and supports idempotent retries, --dry-run and consistent resource+verb commands. In a benchmark of ~1,000 graded runs across 18 Hub tasks on Claude Code (Sonnet 4.6) and Codex (GPT-5.5), agents hand-rolling curl or the Python SDK used 1.3-1.8× more tokens overall, and up to 6× on multi-step tasks. On Sonnet they also succeeded less often (84% vs 94%) and falsely reported success more often. A generated skill file covering the full command surface adds a further small reduction in tool calls.