We're thrilled to share a preview version of txtai agents. Inspired by the simplicity of frameworks like OpenAI Swarm, txtai agents are built on top of the Transformers Agent framework. This supports all LLMs txtai supports (Hugging Face, llama.cpp, OpenAI + Claude + AWS Bedrock via LiteLLM).
The following example shows how to create an agent with txtai. Agents will be available in the upcoming txtai 8.0 release (available now in the txtai GitHub repo now - follow #804 - feedback welcome).
pip install git+https://github.com/neuml/txtai
An agent consists of a prompt, a list of available tools and an LLM engine used for processing. txtai makes it easy to create tools. A tool definition can be a dictionary, a function, callable or a pre-defined tool.
The txtai agent framework is built with Transformers. More on this can be read here.
from datetime import datetime
from txtai import Agent
wikipedia = {
"name": "wikipedia",
"description": "Searches a Wikipedia database",
"provider": "huggingface-hub",
"container": "neuml/txtai-wikipedia"
}
arxiv = {
"name": "arxiv",
"description": "Searches a database of scientific papers",
"provider": "huggingface-hub",
"container": "neuml/txtai-arxiv"
}
def today() -> str:
"""
Gets the current date and time
Returns:
current date and time
"""
return datetime.today().isoformat()
agent = Agent(
tools=[today, wikipedia, arxiv, "websearch"],
llm="hugging-quants/Meta-Llama-3.1-8B-Instruct-AWQ-INT4",
max_iterations=10,
)
The first example needs to pull in multiple data points to answer a question.
answer = agent("Which city has the highest population, Boston or New York?", maxlength=16000)
======== New task ========
Which city has the highest population, Boston or New York?
=== Agent thoughts:
Thought: I will proceed step by step and use the following tools: `web_search` to find the population of both cities.
>>> Calling tool: 'web_search' with arguments: {'query': 'Population of Boston and New York'}
=== Agent thoughts:
>> Calling tool: 'web_search' with arguments: {'query': 'Boston vs New York population'}
=== Agent thoughts:
Thought: I can see that the result I'm looking for is in the second result. It mentions that Boston has a population of 654,776 and New York has a population of 1,621,897.
Calling tool: 'final_answer' with arguments: {'answer': 'New York'}
New York
The next example will pull in data from multiple data sources and combine them into a report on a topic.
researcher = """
You're an expert researcher looking to write a paper on {topic}.
Search for websites, scientific papers and Wikipedia related to the topic.
Write a report with summaries and references (with hyperlinks). Write the text as Markdown.
"""
answer = agent(researcher.format(topic="alien life"), maxlength=16000)
======== New task ========
You're an expert researcher looking to write a paper on alien life.
Search for websites, scientific papers and Wikipedia related to the topic.
Write a report with summaries and references (with hyperlinks). Write the text as Markdown.
=== Agent thoughts:
Thought: I need to find the latest research and information on the topic of alien life. I will start by searching the web for relevant websites.
>>> Calling tool: 'web_search' with arguments: {'query': 'alien life research'}
=== Agent thoughts:
Thought: Now that I have a list of relevant websites, I would like to search Wikipedia for relevant articles.
>>> Calling tool: 'wikipedia' with arguments: {'query': 'alien life'}
=== Agent thoughts:
Thought: Now that I have a list of relevant Wikipedia articles, I would like to search the scientific papers database (arxiv) for relevant articles.
>>> Calling tool: 'arxiv' with arguments: {'query': 'alien life'}
=== Agent thoughts:
Thought: Now that I have a list of relevant scientific papers, I would like to write a report with summaries and references (with hyperlinks).
>>> Calling tool: 'final_answer' with arguments: {'answer': "## Alien Life Research Report\n\n### Introduction\n\nThe search for alien life has been an ongoing topic of research and speculation for decades. This report summarizes the current state of knowledge on the topic, including recent discoveries and theories.\n\n### Search for Alien Life\n\nThe search for alien life has led to the discovery of numerous exoplanets, some of which may be habitable. The Drake equation speculates about the existence of sapient life elsewhere in the universe. Astrobiology is the science of extraterrestrial life, and researchers are using a variety of methods to search for life on other planets and moons.\n\n### Recent Discoveries\n\nRecent discoveries have led to a greater understanding of the possibility of life on other planets. The discovery of extremophiles on Earth has led to speculation that life may be thriving on other planets. The search for life on other planets and moons has become a passion for scientists in a variety of fields.\n\n### References\n\n* [Extraterrestrial life](https://en.wikipedia.org/wiki/Extraterrestrial_life)\n* [Alien](https://en.wikipedia.org/wiki/Alien)\n* [Evolving the Alien](https://en.wikipedia.org/wiki/Evolving_the_Alien)\n* [NASA Research Gives Guideline for Future Alien Life Search](https://www.nasa.gov/universe/nasa-research-gives-guideline-for-future-alien-life-search/)\n* [SETI Institute](https://www.seti.org/)\n* [What's the best evidence we've found for alien life?](https://www.livescience.com/space/extraterrestrial-life/whats-the-best-evidence-weve-found-for-alien-life)\n* [Does alien life need a planet to survive? Scientists propose intriguing possibility](https://www.livescience.com/space/extraterrestrial-life/does-alien-life-need-a-planet-to-survive-scientists-propose-intriguing-possibility)\n* [Extraterrestrial Life - Scientific American](https://www.scientificamerican.com/extraterrestrial-life/)\n* [If Alien Life Is Found, How Should Scientists Break the News?](https://www.scientificamerican.com/article/if-alien-life-is-found-how-should-scientists-break-the-news/)\n* [NASA wants a scale to help explain discoveries about alien life](https://www.npr.org/2021/11/02/1051407020/nasa-extraterrestrial-life-research-understanding)\n* [Extraterrestrial Life and Censorship](https://arxiv.org/abs/1104.1314)\n* [The Imprecise Search for Habitability](https://arxiv.org/abs/1604.05078)\n* [Searching for Life on Habitable Planets and Moons](https://arxiv.org/abs/0912.1040)\n* [Wanted Dead or Alive Extraterrestrial Life Forms](https://arxiv.org/abs/1810.10389)\n* [Of Aliens and Exoplanets: Why the search for life, probably, requires the search for water](https://arxiv.org/abs/2104.01683)"}
Report is shown below
The search for alien life has been an ongoing topic of research and speculation for decades. This report summarizes the current state of knowledge on the topic, including recent discoveries and theories.
The search for alien life has led to the discovery of numerous exoplanets, some of which may be habitable. The Drake equation speculates about the existence of sapient life elsewhere in the universe. Astrobiology is the science of extraterrestrial life, and researchers are using a variety of methods to search for life on other planets and moons.
Recent discoveries have led to a greater understanding of the possibility of life on other planets. The discovery of extremophiles on Earth has led to speculation that life may be thriving on other planets. The search for life on other planets and moons has become a passion for scientists in a variety of fields.
- Extraterrestrial life
- Alien
- Evolving the Alien
- NASA Research Gives Guideline for Future Alien Life Search
- SETI Institute
- What's the best evidence we've found for alien life?
- Does alien life need a planet to survive? Scientists propose intriguing possibility
- Extraterrestrial Life - Scientific American
- If Alien Life Is Found, How Should Scientists Break the News?
- NASA wants a scale to help explain discoveries about alien life
- Extraterrestrial Life and Censorship
- The Imprecise Search for Habitability
- Searching for Life on Habitable Planets and Moons
- Wanted Dead or Alive Extraterrestrial Life Forms
- Of Aliens and Exoplanets: Why the search for life, probably, requires the search for water
This is just a basic preview of what's coming soon. The agent framework will be complimentary to the existing workflow framework.
Workflows are best when there is a known process that can be expressed with a directed acyclic graph (DAG).
Agents are more flexible in that a set of tools can be provided and the LLM will choose the execution path.
Pipelines, workflows, agents, embeddings databases and more can all be utilized from both agents and workflows.
More to come soon!
This is great