chore: import upstream snapshot with attribution
This commit is contained in:
@@ -0,0 +1,141 @@
|
||||
# Configuration
|
||||
|
||||
An agent takes two main arguments, an LLM and a list of tools.
|
||||
|
||||
The txtai agent framework is built with [smolagents](https://github.com/huggingface/smolagents). Additional options can be passed in the `Agent` constructor.
|
||||
|
||||
```python
|
||||
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(
|
||||
model="Qwen/Qwen3-4B-Instruct-2507",
|
||||
tools=[today, wikipedia, arxiv, "websearch"],
|
||||
)
|
||||
```
|
||||
|
||||
## model
|
||||
|
||||
```yaml
|
||||
model: string|llm instance
|
||||
```
|
||||
|
||||
LLM model path or LLM pipeline instance. The `llm` parameter is also supported for backwards compatibility.
|
||||
|
||||
See the [LLM pipeline](../../pipeline/text/llm) for more information.
|
||||
|
||||
## tools
|
||||
|
||||
```yaml
|
||||
tools: list
|
||||
```
|
||||
|
||||
List of tools to supply to the agent. Supports the following configurations.
|
||||
|
||||
### function
|
||||
|
||||
A function tool takes the following dictionary fields.
|
||||
|
||||
| Field | Description |
|
||||
|:------------|:-------------------------|
|
||||
| name | name of the tool |
|
||||
| description | tool description |
|
||||
| target | target method / callable |
|
||||
|
||||
A function or callable method can also be directly supplied in the `tools` list. In this case, the fields are inferred from the method documentation.
|
||||
|
||||
### embeddings
|
||||
|
||||
Embeddings indexes have built-in support. Provide the following dictionary configuration to add an embeddings index as a tool.
|
||||
|
||||
| Field | Description |
|
||||
|:------------|:-------------------------------------------|
|
||||
| name | embeddings index name |
|
||||
| description | embeddings index description |
|
||||
| **kwargs | Parameters to pass to [embeddings.load](../../embeddings/methods/#txtai.embeddings.Embeddings.load) |
|
||||
|
||||
### tool
|
||||
|
||||
The following shortcut strings load tools directly. Passing a Tool instance is also supported.
|
||||
|
||||
| Tool | Description |
|
||||
|:------------|:----------------------------------------------------------|
|
||||
| bash | Runs a shell command through subprocess |
|
||||
| defaults | Loads all of these tools as the default toolkit |
|
||||
| edit | Edits a file in place and returns a diff |
|
||||
| glob | Finds matching file patterns in a directory |
|
||||
| grep | Finds matching file content in a directory |
|
||||
| http.* | HTTP Path to a [Model Context Protocol (MCP)](https://modelcontextprotocol.io/docs/getting-started/intro) server |
|
||||
| python | Runs a Python action |
|
||||
| read | Reads file or url content, supports text extraction |
|
||||
| todowrite | Generates a task list to organize complex tasks |
|
||||
| websearch | Runs a websearch using the built-in websearch tool |
|
||||
| webview | Extracts content from a web page. Alias for `read` tool |
|
||||
| write | Writes content to file |
|
||||
| *.md | Loads a [`skill.md`](https://agentskills.io/specification) file |
|
||||
|
||||
## instructions
|
||||
|
||||
```yaml
|
||||
instructions: string|path
|
||||
```
|
||||
|
||||
Supports loading an `agents.md` file. Can be provided directly as a string or as a path to a file.
|
||||
|
||||
[Read more about agents.md here](https://github.com/agentsmd/agents.md)
|
||||
|
||||
## template
|
||||
|
||||
```yaml
|
||||
template: string
|
||||
```
|
||||
|
||||
Customize the prompt template used by this agent. Supports Jinja templates. Uses a default template when this parameter is not provided.
|
||||
Must include `{{ text }}` and `{{ memory }}` placeholders.
|
||||
|
||||
## memory
|
||||
|
||||
```yaml
|
||||
memory: int
|
||||
```
|
||||
|
||||
Keeps a rolling window of `memory` inputs and outputs. These are added to future prompts and serve as "agent memory".
|
||||
|
||||
Supports storing memory by `session` to enable multiple conversation threads. Defaults to shared memory when not set. See the [method documentation](../methods#txtai.agent.base.Agent.__call__) for more information.
|
||||
|
||||
## method
|
||||
|
||||
```yaml
|
||||
method: code|tool
|
||||
```
|
||||
|
||||
Sets the agent method. Supports either a `code` or `tool` (default) calling agent. A code agent generates Python code and executes that. A tool calling agent generates JSON blocks and calls the agents within those blocks.
|
||||
|
||||
Additional options can be directly passed. See [CodeAgent](https://huggingface.co/docs/smolagents/main/en/reference/agents#smolagents.CodeAgent) or [ToolCallingAgent](https://huggingface.co/docs/smolagents/main/en/reference/agents#smolagents.ToolCallingAgent) for a list of parameters.
|
||||
|
||||
[Read more here](https://huggingface.co/docs/smolagents/main/en/guided_tour).
|
||||
@@ -0,0 +1,156 @@
|
||||
# Agent
|
||||
|
||||

|
||||
|
||||
An agent automatically creates workflows to answer multi-faceted user requests. Agents iteratively prompt and/or interface with tools to
|
||||
step through a process and ultimately come to an answer for a request.
|
||||
|
||||
Agent prompting with [`agents.md`](https://github.com/agentsmd/agents.md) and [`skill.md`](https://agentskills.io/specification) are also supported. [Read the configuration](./configuration/#tool) for more on how to setup those up.
|
||||
|
||||
Agents excel at complex tasks where multiple tools and/or methods are required. They incorporate a level of randomness similar to different
|
||||
people working on the same task. When the request is simple and/or there is a rule-based process, other methods such as RAG and Workflows
|
||||
should be explored.
|
||||
|
||||
The following code snippet defines a basic agent.
|
||||
|
||||
```python
|
||||
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(
|
||||
model="Qwen/Qwen3-4B-Instruct-2507",
|
||||
tools=[today, wikipedia, arxiv, "websearch"],
|
||||
max_steps=10,
|
||||
)
|
||||
```
|
||||
|
||||
The agent above has access to two embeddings databases (Wikipedia and ArXiv) and the web. Given the user's input request, the agent decides the best tool to solve the task.
|
||||
|
||||
## Example
|
||||
|
||||
The first example will solve a problem with multiple data points. See below.
|
||||
|
||||
```python
|
||||
agent("Which city has the highest population, Boston or New York?")
|
||||
```
|
||||
|
||||
This requires looking up the population of each city before knowing how to answer the question. Multiple search requests are run to generate a final answer.
|
||||
|
||||
## Agentic RAG
|
||||
|
||||
Standard retrieval augmented generation (RAG) runs a single vector search to obtain a context and builds a prompt with the context + input question. Agentic RAG is a more complex process that goes through multiple iterations. It can also utilize multiple databases to come to a final conclusion.
|
||||
|
||||
The example below aggregates information from multiple sources and builds a report on a topic.
|
||||
|
||||
```python
|
||||
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.
|
||||
"""
|
||||
|
||||
agent(researcher.format(topic="alien life"))
|
||||
```
|
||||
|
||||
## Agent Teams
|
||||
|
||||
Agents can also be tools. This enables the concept of building "Agent Teams" to solve problems. The previous example can be rewritten as a list of agents.
|
||||
|
||||
```python
|
||||
from txtai import Agent, LLM
|
||||
|
||||
llm = LLM("Qwen/Qwen3-4B-Instruct-2507")
|
||||
|
||||
websearcher = Agent(
|
||||
model=llm,
|
||||
tools=["websearch"],
|
||||
)
|
||||
|
||||
wikiman = Agent(
|
||||
model=llm,
|
||||
tools=[{
|
||||
"name": "wikipedia",
|
||||
"description": "Searches a Wikipedia database",
|
||||
"provider": "huggingface-hub",
|
||||
"container": "neuml/txtai-wikipedia"
|
||||
}],
|
||||
)
|
||||
|
||||
researcher = Agent(
|
||||
model=llm,
|
||||
tools=[{
|
||||
"name": "arxiv",
|
||||
"description": "Searches a database of scientific papers",
|
||||
"provider": "huggingface-hub",
|
||||
"container": "neuml/txtai-arxiv"
|
||||
}],
|
||||
)
|
||||
|
||||
agent = Agent(
|
||||
model=llm,
|
||||
tools=[{
|
||||
"name": "websearcher",
|
||||
"description": "I run web searches, there is no answer a web search can't solve!",
|
||||
"target": websearcher
|
||||
}, {
|
||||
"name": "wikiman",
|
||||
"description": "Wikipedia has all the answers, I search Wikipedia and answer questions",
|
||||
"target": wikiman
|
||||
}, {
|
||||
"name": "researcher",
|
||||
"description": "I'm a science guy. I search arXiv to get all my answers.",
|
||||
"target": researcher
|
||||
}],
|
||||
max_steps=10
|
||||
)
|
||||
```
|
||||
|
||||
This provides another level of intelligence to the process. Instead of just a single tool execution, each agent-tool combination has it's own reasoning engine.
|
||||
|
||||
```python
|
||||
agent("""
|
||||
Research fundamental concepts about Signal Processing and build a comprehensive report.
|
||||
Write the output in Markdown.
|
||||
""")
|
||||
```
|
||||
|
||||
# More examples
|
||||
|
||||
Check out this [Agent Quickstart Example](https://github.com/neuml/txtai/blob/master/examples/agent_quickstart.py). Additional examples are listed below.
|
||||
|
||||
| Notebook | Description | |
|
||||
|:----------|:-------------|------:|
|
||||
| [What's new in txtai 8.0](https://github.com/neuml/txtai/blob/master/examples/67_Whats_new_in_txtai_8_0.ipynb) | Agents with txtai | [](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/67_Whats_new_in_txtai_8_0.ipynb) |
|
||||
| [Analyzing Hugging Face Posts with Graphs and Agents](https://github.com/neuml/txtai/blob/master/examples/68_Analyzing_Hugging_Face_Posts_with_Graphs_and_Agents.ipynb) | Explore a rich dataset with Graph Analysis and Agents | [](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/68_Analyzing_Hugging_Face_Posts_with_Graphs_and_Agents.ipynb) |
|
||||
| [Granting autonomy to agents](https://github.com/neuml/txtai/blob/master/examples/69_Granting_autonomy_to_agents.ipynb) | Agents that iteratively solve problems as they see fit | [](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/69_Granting_autonomy_to_agents.ipynb) |
|
||||
| [Analyzing LinkedIn Company Posts with Graphs and Agents](https://github.com/neuml/txtai/blob/master/examples/71_Analyzing_LinkedIn_Company_Posts_with_Graphs_and_Agents.ipynb) | Exploring how to improve social media engagement with AI | [](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/71_Analyzing_LinkedIn_Company_Posts_with_Graphs_and_Agents.ipynb) |
|
||||
| [Parsing the stars with txtai](https://github.com/neuml/txtai/blob/master/examples/72_Parsing_the_stars_with_txtai.ipynb) | Explore an astronomical knowledge graph of known stars, planets, galaxies | [](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/72_Parsing_the_stars_with_txtai.ipynb) |
|
||||
| [Agentic College Search](https://github.com/neuml/txtai/blob/master/examples/82_Agentic_College_Search.ipynb) | Identify list of strong engineering colleges | [](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/82_Agentic_College_Search.ipynb) |
|
||||
| [TxtAI got skills](https://github.com/neuml/txtai/blob/master/examples/83_TxtAI_got_skills.ipynb) | Integrate skill.md files with your agent | [](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/83_TxtAI_got_skills.ipynb) |
|
||||
| [Agent Tools](https://github.com/neuml/txtai/blob/master/examples/84_Agent_Tools.ipynb) [▶️](https://www.youtube.com/watch?v=RDNaFXQy3GQ) | Learn about the txtai agent toolkit | [](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/84_Agent_Tools.ipynb) |
|
||||
@@ -0,0 +1,4 @@
|
||||
# Methods
|
||||
|
||||
## ::: txtai.agent.base.Agent.__init__
|
||||
## ::: txtai.agent.base.Agent.__call__
|
||||
Reference in New Issue
Block a user