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.txtCreate 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.pyUse the Gradio interface to interact with the agent and perform tasks.
- Python 3.11 or higher
- Hugging Face
smolagentslibrary Gradiofor 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-Instructmodel by default. If the model is overloaded, you can switch to another Hugging Face model or endpoint. - The
.envfile should not be pushed to version control as it contains sensitive information.