Skip to content

A multi-tool AI agent powered by Hugging Face's SmolAgents framework. Supports joke generation, timezone-based time retrieval, and AI image generation with an interactive Gradio UI.

Notifications You must be signed in to change notification settings

sahilmate/simple-multi-tool-ai-agent

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Multi-Tool AI Agent

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.

Features

  • 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.

Folder Structure

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

Key Files

  • 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 as final_answer.py, visit_webpage.py, and web_search.py.
  • .env: Stores environment variables, such as the Hugging Face API token (HF_TOKEN).

Tools

1. Random Joke Generator

Defined in app.py:

@tool
def get_random_joke() -> str:
    """A tool that fetches a random joke from an online API."""

2. Timezone-based Time Fetcher

Defined in app.py:

@tool
def get_current_time_in_timezone(timezone: str) -> str:
    """Fetches the current time for a given timezone."""

3. Image Generator

Imported from the Hugging Face Hub:

image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)

How to Run

1. Install Dependencies

Install the required Python packages using requirements.txt:

pip install -r requirements.txt

2. Set Up Environment Variables

Create a .env file in the JokeAndImageGenerator_LocalTimeTeller/ directory and add your Hugging Face API token:

HF_TOKEN=your_huggingface_api_token

3. Run the Application

Launch the Gradio interface:

python app.py

4. Interact with the Agent

Use the Gradio interface to interact with the agent and perform tasks.

Requirements

  • Python 3.11 or higher
  • Hugging Face smolagents library
  • Gradio for the user interface

Example Usage

  • 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.

Notes

  • 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.

Next Up

smolagents

Fine tuning a model for Function Calling

smolagents Party Planner with CodeAgent

smolagents Party Planner with ToolCallingAgent

Tool Creation methods

Agentic RAG systems

Multi Agent Systems

Vision and Browser Agents

Acknowledgments

About

A multi-tool AI agent powered by Hugging Face's SmolAgents framework. Supports joke generation, timezone-based time retrieval, and AI image generation with an interactive Gradio UI.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages