This project implements a multi-tool AI agent using the smolagents framework by Hugging Face. The agent is capable of performing multiple tasks, such as generating jokes, fetching the current time in a specific timezone, and generating images using integrated tools.
- Random Joke Generator: Fetches a random joke from an online API.
- Timezone-based Time Fetcher: Retrieves the current time for a specified timezone.
- Image Generator: Generates images using a pre-built tool from the Hugging Face Hub.
- Gradio Integration: Provides an interactive user interface for interacting with the agent.
multi-tool-ai-agent/
├── .gitignore
├── README.md
├── JokeAndImageGenerator_LocalTimeTeller/
│ ├── .env
│ ├── .gitattributes
│ ├── agent.json
│ ├── app.py
│ ├── Gradio_UI.py
│ ├── prompts.yaml
│ ├── README.md
│ ├── requirements.txt
│ ├── __pycache__/
│ │ └── Gradio_UI.cpython-311.pyc
│ ├── .gradio/
│ │ └── certificate.pem
│ └── tools/
│ ├── final_answer.py
│ ├── visit_webpage.py
│ ├── web_search.py
│ └── __pycache__/
│ └── final_answer.cpython-311.pyc
app.py
: The main application file where the agent and its tools are defined and configured.Gradio_UI.py
: Contains the Gradio-based user interface for interacting with the agent.prompts.yaml
: Stores system prompts for guiding the agent's behavior.tools/
: Contains custom tools used by the agent, such asfinal_answer.py
,visit_webpage.py
, andweb_search.py
..env
: Stores environment variables, such as the Hugging Face API token (HF_TOKEN
).
Defined in app.py
:
@tool
def get_random_joke() -> str:
"""A tool that fetches a random joke from an online API."""
Defined in app.py
:
@tool
def get_current_time_in_timezone(timezone: str) -> str:
"""Fetches the current time for a given timezone."""
Imported from the Hugging Face Hub:
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
Install the required Python packages using requirements.txt
:
pip install -r requirements.txt
Create a .env
file in the JokeAndImageGenerator_LocalTimeTeller/
directory and add your Hugging Face API token:
HF_TOKEN=your_huggingface_api_token
Launch the Gradio interface:
python app.py
Use the Gradio interface to interact with the agent and perform tasks.
- Python 3.11 or higher
- Hugging Face
smolagents
library Gradio
for the user interface
- Generate a Joke: Ask the agent to fetch a random joke.
- Get Current Time: Provide a timezone, and the agent will return the current time in that timezone.
- Generate an Image: Use the image generation tool to create AI-generated images.
- The agent uses the
Qwen/Qwen2.5-Coder-32B-Instruct
model by default. If the model is overloaded, you can switch to another Hugging Face model or endpoint. - The
.env
file should not be pushed to version control as it contains sensitive information.