We are releasing Transformers Agents 2.0!
β π On top of our existing agent type, we introduce two fresh agents that can iterate based on past observations to solve complex tasks. (Related: Samsung releases its next major patch, One UI 9.5, in b...)
β π‘ We aim for the code to be clear and modular, and for common attributes like the final prompt and tools to be transparent.
β π€ We add sharing options to boost community agents.
β πͺ Extremely performant new agent framework, allowing a Llama-3-70B-Instruct agent to outperform GPT-4 based agents in the GAIA Leaderboard!
πΒ Go try it out and climb ever higher on the GAIA leaderboard!
transformers.agents has now been upgraded to the stand-alone library smolagents! The two libraries have very similar APIs, so switching is easy. Go checkout the smolagents introduction blog here.
Large Language Models (LLMs) can tackle a wide range of tasks, but they often struggle with specific tasks like logic, calculation, and search. When prompted in these domains in which they do not perform well, they frequently fail to generate a correct answer. (Related: One UI 9.5 Beta is out now for these Galaxy devices β h...)
One approach to overcome this weakness is to create an agent, which is just a program driven by an LLM. The agent is empowered by tools to help it perform actions. When the agent needs a specific skill to solve a particular problem, it relies on an appropriate tool from its toolbox.
Thus when during problem-solving the agent needs a specific skill, it can just rely on an appropriate tool from its toolbox.
Experimentally, agent frameworks generally work very well, achieving state-of-the-art performance on several benchmarks. For instance, have a look at the top submissions for HumanEval: they are agent systems.
Industry observers note that building agent workflows is complex, and we feel these systems need a lot of clarity and modularity. We launched Transformers Agents one year ago, and weβre doubling down on our core design goals.
On top of that, we have sharing features that let you build on the shoulders of giants!
Check out the documentation to learn how to use each component!
How do agents work under the hood?
Industry observers note that in essence, what an agent does is βallowing an LLM to use toolsβ. Agents have a key agent.run() method that:.
For more general context about agents, you could read this excellent blog post by Lilian Weng or our earlier blog post about building agents with LangChain.
To take a deeper dive in our package, go take a look at the agents documentation.
In order to get access to the early access of this feature, please first install transformers from its main branch:.
Agents 2.0 will be released in the v4.41.0 version, landing mid-May.
Recent findings suggest that quick definition: Retrieval-Augmented-Generation (RAG) is βusing an LLM to answer a user query, but basing the answer on information retrieved from a knowledge baseβ. It has many advantages over using a vanilla or fine-tuned LLM: to name a few, it allows to ground the answer on true facts and reduce confabulations, it allows to provide the LLM with domain-specific knowledge, and it allows fine-grained control of access to information from the knowledge base.
Recent findings suggest that letβs say we want to perform RAG, and some parameters must be dynamically generated. For example, depending on the user query we could want to restrict the search to specific subsets of the knowledge base, or we could want to adjust the number of documents retrieved. The difficulty is: how to dynamically adjust these parameters based on the user query?
Well, we can do this by giving our agent an access to these parameters!
Run the line below to install the required dependencies:.
We first load a knowledge base on which we want to perform RAG: this dataset is a compilation of the documentation pages for many huggingface packages, stored as markdown.
Now we prepare the knowledge base by processing the dataset and storing it into a vector database to be used by the retriever. We are going to use LangChain, since it features excellent utilities for vector databases:.
Now that we have the database ready, letβs build a RAG system that answers user queries based on it!
We want our system to select only from the most relevant sources of information, depending on the query.
Our documentation pages come from the following sources:.
How can we select the relevant sources based on the user query?
π Let us build our RAG system as an agent that will be free to choose its sources!
We create a retriever tool that the agent can call with the parameters of its choice:.
Now itβs straightforward to create an agent that leverages this tool!
The agent will need these arguments upon initialization:.
Our llm_engine must be a callable that takes as input a list of messages and returns text. It also needs to accept a stop_sequences argument that indicates when to stop its generation. For convenience, we directly use the HfEngine class provided in the package to get a LLM engine that calls our Inference API.
Since we initialized the agent as a ReactJsonAgent, it has been automatically given a default system prompt that tells the LLM engine to process step-by-step and generate tool calls as JSON blobs (you could replace this prompt template with your own as needed).
Then when its .run() method is rolled out, the agent takes care of calling the LLM engine, parsing the tool call JSON blobs and executing these tool calls, all in a loop that ends only when the final answer is provided.
And we get the following output:.
We can see the self-correction in action: the agent first tried to restrict sources, but due to the lack of corresponding documents it ended up not restricting sources at all.
We can verify that by inspecting the llm output at the logs for step 2: print(agent.logs[2]['llm_output']).
In a recent development, in this example, we want to build an agent and test it on the GAIA benchmark (Mialon et al. 2023). GAIA is an extremely difficult benchmark, with most questions requiring several steps of reasoning using different tools. A specifically difficult requirement is to have a powerful web browser, able to navigate to pages with specific constraints: discovering pages using the websiteβs inner navigation, selecting specific articles in time...
In a recent development, web browsing requires diving deeper into subpages and scrolling through lots of text tokens that will not be necessary for the higher-level task-solving. We assign the web-browsing sub-tasks to a specialized web surfer agent. We provide it with some tools to browse the web and a specific prompt (check the repo to find specific implementations).
Defining these tools is outside the scope of this post: but you can check the repository to find specific implementations.
To allow this agent to be called by a higher-level task solving agent, we can simply encapsulate it in another tool:.
Then we initialize the task-solving agent with this search tool:.
Let's run the agent with the following task:.
Use density measures from the chemistry materials licensed by Marisa Alviar-Agnew & Henry Agnew under the CK-12 license in LibreText's Introductory Chemistry materials as compiled 08/21/2023. I have a gallon of honey and a gallon of mayonnaise at 25C. I remove one cup of honey at a time from the gallon of honey. How many times will I need to remove a cup to have the honey weigh less than the mayonaise? Assume the containers themselves weigh the same.
Letβs take our agent framework for a spin and benchmark different models with it!
All the code for the experiments below can be found here.
The agents_reasoning_benchmark is a small - but mighty- reasoning test for evaluating agent performance. This benchmark was already used and explained in more detail in our earlier blog post.
Industry observers note that the idea is that the choice of tools you use with your agents can radically alter performance for certain tasks. So this benchmark restricts the set of tools used to a calculator and a basic search tool. We picked questions from several datasets that could be solved using only these two tools:.
Here we try 3 different engines: Mixtral-8x7B, Llama-3-70B-Instruct, and GPT-4 Turbo.
The results are shown above - as the average of two complete runs for more precision. We also tested Command-R+ and Mixtral-8x22B, but do not show them for clarity.
β Llama-3-70B-Instruct leads the Open-Source models: it is on par with GPT-4, and itβs especially strong in a ReactCodeAgent thanks to Llama 3βs strong coding performance!
According to recent reports, π‘ It's interesting to compare JSON- and Code-based React agents: with less powerful LLM engines like Mixtral-8x7B, Code-based agents do not perform as well as JSON, since the LLM engine frequently fails to generate good code. But the Code version really shines with more powerful models as engines: in our experience, the Code version even outperforms the JSON with Llama-3-70B-Instruct. As a result, we use the Code version for our next challenge: testing on the complete GAIA benchmark.
GAIA (Mialon et al., 2023) is an extremely difficult benchmark: you can see in the agent_reasoning_benchmark above that models do not perform above 50% even though we cherry-picked tasks that could be solved with 2 basic tools.
Now we want to get a score on the complete set, we do not cherry-pick questions anymore. Thus we have to cover all modalities, which leads us to use these specific tools:.
We first initialize these toole (for more detail, inspect the code in the repository).
And after some time needed to complete the 165 questions, we submit our result to the GAIA Leaderboard, andβ¦ π₯π₯π₯.
β Our agent ranks 4th: it beats many GPT-4-based agents, and is now the reigning contender for the Open-Source category!
Industry observers note that we will keep improving this package in the coming months. We have already identified several exciting paths in our development roadmap:.
Industry observers note that πΒ Go try out transformers agents! Weβre looking forward to receiving your feedback and your ideas.
Letβs fill the top of the leaderboard with more open-source models! π.
transformers.agents has now been upgraded to the stand-alone library smolagents! The two libraries have very similar APIs, so switching is easy. Go checkout the smolagents introduction blog here.