Spaces:
Sleeping
Sleeping
File size: 5,027 Bytes
0128def e3d7fcc 0128def 9f39c86 0128def 3ce50c4 e0cc0af e8d4494 e3d7fcc 0128def 3334632 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
---
title: First Agent Template
emoji: ⚡
colorFrom: pink
colorTo: yellow
sdk: gradio
sdk_version: 5.23.1
app_file: app.py
pinned: false
tags:
- smolagents
- agent
- smolagent
- tool
- agent-course
---
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
# 🤖 First Agent Project
Welcome to the **First Agent Project** — an elegant and modular AI agent system powered by [SmolAgents](https://github.com/huggingface/smol-agents), capable of solving complex tasks using structured reasoning, tool use, and code execution. Designed with usability and extensibility in mind, this project features a dynamic Gradio-based interface, plug-and-play tools, and a powerful HuggingFace model backend.
---
## ✨ Features
- 🔁 **Multi-Step Reasoning** with an agent that can plan, execute code, and invoke tools.
- 🌐 **Web Search Tool** via DuckDuckGo for live queries.
- 🧭 **Webpage Reader Tool** to fetch and parse web pages in Markdown.
- 📅 **Time and Weather Tools** for real-time timezone and temperature queries.
- 🖼️ **Image Generation** support using HuggingFace tool hub.
- 🎯 **Gradio UI Integration** with step-wise conversational tracing.
- 📦 Modular structure — easily extensible with custom tools.
---
## 🧠 Project Structure
```bash
.
├── app.py # Main entrypoint - defines tools, loads agent, and launches Gradio UI
├── Gradio_UI.py # Elegant multi-step UI for interaction using Gradio
├── tools/final_answer.py # Defines a final answer tool to conclude tasks
├── tools/visit_webpage.py # Tool to visit a URL and extract readable markdown content
├── tools/web_search.py # Tool for DuckDuckGo web search queries
├── requirements.txt # Python dependencies
├── agent.json # Agent configuration (tools, model, prompts, rules)
```
---
## 🧰 Built-in Tools
| Tool Name | Description |
|-------------------|-----------------------------------------------------------------------------|
| `web_search` | Search the web using DuckDuckGo |
| `visit_webpage` | Visit and parse the content of a webpage as markdown |
| `get_temperature` | Get real-time temperature of a given city |
| `get_current_time_in_timezone` | Get local time in a specified timezone |
| `final_answer` | Returns the final response to a task |
| `text-to-image` | Generates images using HuggingFace image generation API (remote tool) |
---
## 🚀 Quick Start
### 1. Install Dependencies
```bash
pip install -r requirements.txt
```
### 2. Run the App
```bash
python app.py
```
This will launch a Gradio interface where you can interact with your agent conversationally.
---
## 🌈 Sample Tasks
Try asking the agent:
- "What is the current temperature in Tokyo?"
- "Find the age of the Pope and raise it to the power of 0.36"
- "Search for latest news on Mars exploration"
- "Generate an image of a futuristic AI-powered city"
- "What’s the current time in New York?"
---
## 🛠️ Under the Hood
### 🧠 Agent Model
- Powered by [`Qwen/Qwen2.5-Coder-32B-Instruct`](https://huggingface.co/Qwen/Qwen2.5-Coder-32B-Instruct)
- HuggingFace API wrapper (`HfApiModel`) with streaming and code execution.
### 💬 Prompt Planning Logic
- Configured in `agent.json` with step-by-step templates, planning logic, and reasoning strategy.
- Structured prompt system encourages:
- Thought → Code → Observation → Final Answer loops
---
## 🖼️ UI Highlights
- 💬 Chat-based interface with message tracking
- ⚙️ Shows tool usage logs, execution reasoning, and token statistics
- 📁 Supports file uploads (PDF, DOCX, TXT)
- 🧵 Maintains step context and memory
---
## 🔧 Customize or Extend
### Adding Your Own Tool
You can add custom tools easily by subclassing `Tool`. Example:
```python
from smolagents.tools import Tool
class MyTool(Tool):
name = "my_tool"
description = "Describe what your tool does here."
inputs = {'input1': {'type': 'string', 'description': 'Your input'}}
output_type = "string"
def forward(self, input1: str) -> str:
# Your logic
return "Output result"
```
Then add it in `app.py` to the agent's tools list.
---
## 📜 License
This project is licensed under the Apache 2.0 License. See the [LICENSE](https://www.apache.org/licenses/LICENSE-2.0) file for details.
---
## 🌟 Acknowledgements
Built using:
- 🤖 [SmolAgents](https://github.com/huggingface/smol-agents)
- 🌐 [DuckDuckGo Search](https://pypi.org/project/duckduckgo-search/)
- 🧾 [Markdownify](https://pypi.org/project/markdownify/)
- 🔥 [Gradio](https://gradio.app/)
- 🧠 [Qwen Model on HuggingFace](https://huggingface.co/Qwen)
|