/ examples / agent_quickstart.py
agent_quickstart.py
 1  """
 2  Agent Quick Start
 3  Easy to use way to get started with AI Agents.
 4  
 5  TxtAI has many example notebooks covering everything the framework provides
 6  Examples: https://neuml.github.io/txtai/examples
 7  
 8  Install TxtAI
 9    pip install txtai[agent]
10  """
11  
12  # pylint: disable=C0103
13  from datetime import datetime
14  from txtai import Agent
15  
16  # Step 1: Define your Embeddings database
17  #
18  # Replace provider/container with a path to a local Embeddings database
19  # See RAG Quickstart for an example of building your own custom database
20  embeddings = {
21      "name": "wikipedia",
22      "description": "Searches a Wikipedia database",
23      # "path": "path to your embeddings database"
24      "provider": "huggingface-hub",
25      "container": "neuml/txtai-wikipedia",
26  }
27  
28  
29  # Step 2: Define other tools
30  #
31  # Add any Python function. Just need to describe it.
32  def today() -> str:
33      """
34      Gets the current date and time
35  
36      Returns:
37          current date and time
38      """
39  
40      return datetime.today().isoformat()
41  
42  
43  # Step 3: Create a list of available tools
44  #
45  # Combine defined tools with default tools
46  tools = [
47      embeddings,  # Embeddings database with YOUR data
48      today,  # Python function
49      "websearch",  # Runs a websearch using default engine
50      "webview",  # Loads a web page
51  ]
52  
53  # Step 4: Set LLM configuration
54  #
55  # LLM APIs
56  #  model = "gpt-5.1"
57  #  model = "claude-opus-4-5-20251101"
58  #  model = "gemini/gemini-3-pro-preview"
59  #
60  # Local LLMs
61  #  model = "ollama/gpt-oss
62  #  model = "openai/gpt-oss-20b"
63  #  model = "unsloth/gpt-oss-20b-GGUF/gpt-oss-20b-Q4_K_M.gguf"
64  #
65  # Pass multiple options as a dictionary
66  #  model = {
67  #    "path": "unsloth/Qwen3-30B-A3B-Instruct-2507-GGUF/Qwen3-30B-A3B-Instruct-2507-Q4_K_M.gguf",
68  #    "n_ctx": 25000
69  #  }
70  model = "Qwen/Qwen3-4B-Instruct-2507"
71  
72  # Step 4: Create an Agent
73  #
74  # Set LLM, tools and other configuration
75  # See this for more options: https://huggingface.co/docs/smolagents/reference/agents#agents
76  agent = Agent(model=model, tools=tools, max_steps=10)
77  
78  print(agent("Tell me about the Roman Empire"))
79  print(agent("What is the current date?"))
80  print(agent("Get the 5 top news stories for today", maxlength=25000))