Using Command A on Hugging Face
This page contains detailed instructions about:
- How to set safety preambles for Command A in Hugging Face
- How to run Command A in Hugging Face for Chat, RAG, Tool Use and Agents use cases.
Chat Capabilities
Conversational Mode
Command A is configured as a conversational model, meaning it is optimized for interactive experiences, such as chatbots, where the model engages in dialogue. This kind of behavior is conditioned with a system message; system messages vary for different models, and in the case of Command A, it is written such that the model will reply in a conversational fashion, provide introductory statements and follow-up questions, and use Markdown as well as LaTeX where appropriate.
The (conversational) system message for Command A looks like this:
In the above, {Safety Preamble}
can represent either the contextual or the strict safety mode preamble, about which more below.
Obtaining non-interactive behavior
Observe that the system message contains the following instructions explicitly asking for interactivity:
- You reply conversationally with a friendly and informative tone and often include introductory statements and follow-up questions.
- If the input is ambiguous, ask clarifying follow-up questions.
- Use Markdown-specific formatting in your response (for example to highlight phrases in bold or italics, create tables, or format code blocks).
- Use LaTeX to generate mathematical notation for complex equations.
- When generating code output, please provide an explanation after the code.
These instructions are useful in conversational settings. However, in other circumstances a non-interactive model might be preferred, such as when asking the model to generate structured data formats that are parsed directly and automatically.
System messages can be used to achieve such non-interactive behavior. For example, when asking the model to “Please generate a JSON summarizing the first five Wes Anderson movies”, the model might output something along these lines
Here’s a JSON summarization of the first five Wes Anderson movies, including their titles, release years, and brief descriptions:
For this prompt, the preamble can be used to change the model behavior such that the completion only contains the JSON object, without any Markdown code block markers:
And here’s a sample output:
Safety modes
Safety Modes define what model behaviors will look like under specific scenarios. Command A can be configured with two safety modes: contextual mode or strict mode (learn more here).
By default, Command A is configured in contextual mode. Under the hood, the following {Safety Preamble}
paragraph is added to Command A’s standard system message:
Here’s a code snippet to configure Command A in contextual safety mode.
If instead you would like to set the Safety Mode to strict, you would do that like so:
The fololwing strict mode preamble is added under the hood:
Grounded Generation and RAG Capabilities:
Command A has been trained specifically for tasks like summarization and the final step of Retrieval Augmented Generation (RAG). The model takes a conversation as input (with an optional user-supplied system preamble, indicating task, context and desired output style), along with a list of document snippets. This behavior has been trained into the model via a mixture of supervised fine-tuning and preference fine-tuning.
For these tasks, you can use Command A in two ways.
Option 1: Grounded Generation
Grounded generation in Command A is supported through chat templates in Transformers. Simply provide document snippets using the documents
parameter of Hugging Face’s apply_chat_template()
. Document snippets should be short chunks, rather than long documents, typically around 100-400 words per chunk, formatted as key-value pairs. The keys should be short descriptive strings, the values can be text or semi-structured. Under the hood, this builds a specific prompt template that the model has been trained on. The code snippet below shows a minimal working example.
Usage: Generate a Grounded Generation Prompt
Example of a Grounded Generation prompt
Example of a Grounded Generation completion
Option 2: Regular Generation
You may find that simply including relevant documents directly in a user message works just as well, or better than using the documents parameter to render the special grounded generation template. Grounded Generation is generally a strong default, but Regular Generation can offer more control and customization over the prompt, at the cost of some effort to find an optimal prompt. We encourage users to play with both Grounded Generation and Regular Generation, and to evaluate which mode works best for their specific use case.
Tool use, Function Calling & Agent capabilities
Command A has been specifically trained with conversational tool use capabilities. This allows the model to interact with external tools like APIs, databases, or search engines. These capabilities have been trained into the model via a mixture of supervised fine-tuning and preference fine-tuning, using a specific prompt template. Deviating from this prompt template will likely reduce performance, but we encourage experimentation.
These tool use capabilities unlock two use cases:
- Function Calling: A single inference where Command A selects relevant tools to fulfill a user request.
- Agents: Several inference cycles where Command A iterates through Plan → Action → Observation loops until it arrives at a final response.
Both function calling and agents work in the same way. Given a conversation as input (with an optional preamble), along with a list of available tools, the model will generate one of the following:
- Tool Selection: A high-level plan followed by a json-formatted list of actions to execute on a subset of the supplied tools. Command A may select multiple tools in parallel, and it may select a tool more than once. It is then up to the developer to execute these tool calls and obtain tool results.
- Or, a Response: A final response to the user. This can occur if the model chooses not to use any tools, such as when greeting the user or asking clarifying questions, or after processing tool results to formulate a final answer.
Tool use in Command A is supported through chat templates in Transformers. We recommend providing tool descriptions using JSON schema. Here is a quick example showing tool use.
Usage: Generate the Tool Use prompt
Example of a Tool Use prompt
Example of a Tool Use completion
In this case, the model decides to select tools.
Below is what the answer would have looked like, if the model had decided to respond directly (by, for example, asking the user a follow up question.)
If the model generates tool calls, you should add them to the chat history like so:
And then call the tool and append the result, with the tool role, like below. It is crucial to format the tool results as a dictionary:
After that, you can generate() again to let the model use the tool result in the chat.
Usage: Generate the Tool Use prompt with tool results in the conversation
Example of a Tool Use prompt with tool results in the conversation
Example of a completion
In this case, the model decides to select tools.