Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

Hugging Face 11 min read How-to mediumAdept

Tool Use, Unified

Hugging 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.

Assumes: LLM chat modelsPythonJSON Schema

Related posts

  • Tiny Agents in Python: a MCP-powered agent in ~70 lines of code

    Hugging Face mediumAdept

    Hugging 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.

  • From OpenAI to Open LLMs with Messages API on Hugging Face

    Hugging Face mediumAdept

    Text Generation Inference 1.4.0 adds a Messages API compatible with OpenAI's Chat Completion API, so open LLMs on Inference Endpoints can be called from existing OpenAI client code by changing the base URL and token. The guide deploys Nous-Hermes-2-Mixtral-8x7B-DPO via huggingface_hub with TGI token-limit settings and then calls it from the OpenAI Python and JavaScript clients. It also plugs the endpoint into LangChain (ChatOpenAI) and LlamaIndex (OpenAILike) RAG pipelines. Limitations: no function calling, only models with a chat_template, and a subset of parameters (stream, max_tokens, temperature, top_p, seed, logprobs, frequency_penalty).

  • Hugging Face x LangChain : A new partner package

    Hugging Face mediumAdept

    langchain-huggingface is a new Python partner package jointly maintained by Hugging Face and LangChain, replacing community-written integrations that had drifted out of date. It provides HuggingFacePipeline for running transformers models locally, HuggingFaceEndpoint for the serverless Inference API or deployed TGI endpoints via InferenceClient, and ChatHuggingFace, which turns message lists into model-specific prompts with tokenizer.apply_chat_template. For embeddings it offers HuggingFaceEmbeddings (local sentence-transformers) and HuggingFaceEndpointEmbeddings (Hub or TEI instances), each shown with short code examples.

  • Chat Templates: An End to the Silent Performance Killer

    Hugging Face mediumAdept

    Chat models are trained with incompatible formats for flattening role/content message lists into a single string, and feeding a model a different format than it was trained on causes severe but silent performance degradation. Hugging Face tokenizers now carry a `chat_template` attribute holding a Jinja template that renders conversations into the model's exact training format, applied via `tokenizer.apply_chat_template()`. Jinja was chosen over a simpler per-role prefix/suffix scheme because it can express every known format. ChatML with `<|im_start|>`/`<|im_end|>` tokens is recommended for new models, and model owners should set explicit templates rather than relying on fragile class-level defaults kept only for backward compatibility.

  • ToolGrad: Efficient tool-use dataset generation with textual "gradients"

    Google Research hardMaster

    ToolGrad generates synthetic tool-use training data answer-first: it builds a verified API chain iteratively, then has an LLM write the matching user query, instead of inventing a query and searching for a solution with a DFS agent as ToolBench and ToolACE do. Borrowing TextGrad's idea of textual "gradients", each iteration runs four modules: an API Proposer, parallel API Executors, an API Selector that picks the best call as directional feedback, and an LLM Updater that revises the query and response. On ToolBench's 16k+ APIs this reaches a 99.8% pass rate with fewer steps than DFS. Gemma-3 12B fine-tuned on just 500 such samples scores 83.1 on the Berkeley Function Calling Leaderboard, close to gemini-2.5-pro (83.2) and ahead of its gemini-2.5-flash-lite teacher.

The quest for software engineering knowledge.

Look:
Layout: