Spaces:
Sleeping
Sleeping
Joachim M. Vis commited on
Update README.md
Browse files
README.md
CHANGED
|
@@ -1,204 +1,217 @@
|
|
| 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 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 204 |
*For more information, questions, or issues, please visit the repository on Hugging Face Spaces or submit an issue on GitHub.*
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: GAIA Agent
|
| 3 |
+
emoji: π€
|
| 4 |
+
colorFrom: blue
|
| 5 |
+
colorTo: green
|
| 6 |
+
sdk: gradio
|
| 7 |
+
sdk_version: 3.44.4
|
| 8 |
+
app_file: app.py
|
| 9 |
+
pinned: false
|
| 10 |
+
hf_oauth: true
|
| 11 |
+
hf_oauth_expiration_minutes: 480
|
| 12 |
+
---
|
| 13 |
+
|
| 14 |
+
# GAIA Agent - Grounded AI Assistant
|
| 15 |
+
|
| 16 |
+

|
| 17 |
+
|
| 18 |
+
GAIA (Grounded AI Assistant) is a robust, LangGraph-based agent designed to provide accurate, well-reasoned responses by leveraging real-time web data and structured reasoning. This implementation offers a streamlined, production-ready version optimized for deployment on Hugging Face Spaces.
|
| 19 |
+
|
| 20 |
+
## Core Capabilities
|
| 21 |
+
|
| 22 |
+
GAIA Agent delivers high-quality answers through:
|
| 23 |
+
|
| 24 |
+
- **Web-Grounded Responses**: Retrieves current information from multiple search engines
|
| 25 |
+
- **Structured Reasoning Process**: Follows a systematic workflow for analysis, planning, and answer formulation
|
| 26 |
+
- **Adaptable Tool Usage**: Dynamically selects and executes appropriate tools based on question requirements
|
| 27 |
+
- **Robust Error Handling**: Includes multiple fallback mechanisms to ensure reliability
|
| 28 |
+
|
| 29 |
+
## Key Features
|
| 30 |
+
|
| 31 |
+
- **LangGraph Workflow Integration**: Manages the agent's reasoning process with a clear state-based approach
|
| 32 |
+
- **Multiple Search Backends**: Supports both DuckDuckGo and Serper API for web searches
|
| 33 |
+
- **Content Extraction**: Can analyze and extract relevant information from web pages
|
| 34 |
+
- **Memory Management**: Efficiently caches responses and manages conversation context
|
| 35 |
+
- **Special Case Detection**: Includes handling for edge cases like reversed text questions
|
| 36 |
+
- **Graceful Degradation**: Continues functioning even with limited API access or resources
|
| 37 |
+
|
| 38 |
+
## Setup & Installation
|
| 39 |
+
|
| 40 |
+
### Environment Requirements
|
| 41 |
+
|
| 42 |
+
The GAIA Agent requires the following environment variables:
|
| 43 |
+
|
| 44 |
+
```
|
| 45 |
+
OPENAI_API_KEY=your_openai_key_here
|
| 46 |
+
SERPER_API_KEY=your_serper_key_here # Optional, falls back to DuckDuckGo
|
| 47 |
+
SUPABASE_URL=your_supabase_url # Optional, for enhanced memory
|
| 48 |
+
SUPABASE_KEY=your_supabase_key # Optional, for enhanced memory
|
| 49 |
+
```
|
| 50 |
+
|
| 51 |
+
### Installation Steps
|
| 52 |
+
|
| 53 |
+
1. Clone this repository
|
| 54 |
+
2. Install dependencies:
|
| 55 |
+
```bash
|
| 56 |
+
pip install -r requirements.txt
|
| 57 |
+
```
|
| 58 |
+
3. Set up environment variables (create a `.env` file or set them in your environment)
|
| 59 |
+
4. Run the application:
|
| 60 |
+
```bash
|
| 61 |
+
python app.py
|
| 62 |
+
```
|
| 63 |
+
|
| 64 |
+
### Dependencies
|
| 65 |
+
|
| 66 |
+
The GAIA Agent requires the following key packages:
|
| 67 |
+
|
| 68 |
+
- `langchain` and `langgraph`: Core agent architecture components
|
| 69 |
+
- `langchain-openai`: Integration with OpenAI models
|
| 70 |
+
- `duckduckgo-search`: Web search capability
|
| 71 |
+
- `requests` and `beautifulsoup4`: Web content extraction
|
| 72 |
+
- `gradio`: User interface components
|
| 73 |
+
|
| 74 |
+
## Usage Instructions
|
| 75 |
+
|
| 76 |
+
### Basic Usage
|
| 77 |
+
|
| 78 |
+
1. Start the application with `python app.py`
|
| 79 |
+
2. Open the displayed URL in your browser
|
| 80 |
+
3. Type your question in the input box and click "Submit"
|
| 81 |
+
4. The agent will analyze your question, gather information, and provide a response
|
| 82 |
+
|
| 83 |
+
### API Usage
|
| 84 |
+
|
| 85 |
+
You can also use the agent programmatically by importing the `GAIAAgent` class:
|
| 86 |
+
|
| 87 |
+
```python
|
| 88 |
+
from agent import GAIAAgent
|
| 89 |
+
|
| 90 |
+
# Initialize the agent
|
| 91 |
+
agent = GAIAAgent()
|
| 92 |
+
|
| 93 |
+
# Process a question and get a simple string response
|
| 94 |
+
response = agent.process_question("What is the capital of France?")
|
| 95 |
+
print(response)
|
| 96 |
+
|
| 97 |
+
# Or get a detailed response with metadata
|
| 98 |
+
result = agent.query("What is the capital of France?")
|
| 99 |
+
print(result["answer"])
|
| 100 |
+
print(result["tools_used"])
|
| 101 |
+
```
|
| 102 |
+
|
| 103 |
+
### Testing the Agent
|
| 104 |
+
|
| 105 |
+
Run the test suite to verify the agent's functionality:
|
| 106 |
+
|
| 107 |
+
```bash
|
| 108 |
+
# Run all tests
|
| 109 |
+
python test_agent.py run
|
| 110 |
+
|
| 111 |
+
# Run specific test categories
|
| 112 |
+
python test_agent.py web # Test web search functionality
|
| 113 |
+
python test_agent.py special # Test special case handling
|
| 114 |
+
python test_agent.py memory # Test memory functionality
|
| 115 |
+
```
|
| 116 |
+
|
| 117 |
+
## Architecture & Design
|
| 118 |
+
|
| 119 |
+
The GAIA Agent follows a structured workflow implemented with LangGraph:
|
| 120 |
+
|
| 121 |
+
1. **Question Analysis**: Examines the question to determine its type, complexity, and required tools
|
| 122 |
+
2. **Plan Creation**: Generates a step-by-step plan for answering the question
|
| 123 |
+
3. **Tool Execution**: Runs necessary tools (web search, content extraction) according to the plan
|
| 124 |
+
4. **Answer Formulation**: Synthesizes information into a comprehensive, accurate response
|
| 125 |
+
|
| 126 |
+
### Component Architecture
|
| 127 |
+
|
| 128 |
+
```
|
| 129 |
+
GAIAAgent
|
| 130 |
+
βββ LangGraph Workflow
|
| 131 |
+
β βββ analyze_question()
|
| 132 |
+
β βββ create_plan()
|
| 133 |
+
β βββ execute_tool()
|
| 134 |
+
β βββ formulate_answer()
|
| 135 |
+
β
|
| 136 |
+
βββ Tool Components
|
| 137 |
+
β βββ WebSearchTool
|
| 138 |
+
β β βββ DuckDuckGo search
|
| 139 |
+
β β βββ Serper API fallback
|
| 140 |
+
β βββ ContentExtractor
|
| 141 |
+
β
|
| 142 |
+
βββ SimpleMemory
|
| 143 |
+
βββ Conversation history
|
| 144 |
+
βββ Result caching
|
| 145 |
+
```
|
| 146 |
+
|
| 147 |
+
### File Structure
|
| 148 |
+
|
| 149 |
+
- `agent.py`: Core implementation of the GAIA Agent using LangGraph
|
| 150 |
+
- `app.py`: Gradio-based user interface for interacting with the agent
|
| 151 |
+
- `test_agent.py`: Comprehensive test suite for validating functionality
|
| 152 |
+
- `requirements.txt`: Required dependencies
|
| 153 |
+
- `run_test.py` and `run_test.sh`: Convenience scripts for testing
|
| 154 |
+
|
| 155 |
+
## API Requirements
|
| 156 |
+
|
| 157 |
+
For full functionality, GAIA requires:
|
| 158 |
+
|
| 159 |
+
- **OpenAI API**: Powers the large language model capabilities (required)
|
| 160 |
+
- **Serper API**: Alternative web search backend (optional, falls back to DuckDuckGo)
|
| 161 |
+
- **Supabase**: Enhanced memory capabilities (optional)
|
| 162 |
+
|
| 163 |
+
## Limitations & Known Issues
|
| 164 |
+
|
| 165 |
+
- **Rate Limiting**: Web search tools may be subject to rate limiting when used extensively
|
| 166 |
+
- **Content Extraction**: May struggle with some complex or JavaScript-heavy websites
|
| 167 |
+
- **Answer Quality**: Responses depend on the quality of available search results
|
| 168 |
+
- **Context Length**: Limited by the underlying LLM's context window size
|
| 169 |
+
- **Computation Time**: Complex questions requiring multiple searches may take longer to answer
|
| 170 |
+
|
| 171 |
+
## Troubleshooting
|
| 172 |
+
|
| 173 |
+
### Common Issues
|
| 174 |
+
|
| 175 |
+
1. **Missing API Keys**
|
| 176 |
+
- Error: "Error: GAIA Agent is not initialized"
|
| 177 |
+
- Solution: Ensure the required environment variables are set, especially `OPENAI_API_KEY`
|
| 178 |
+
|
| 179 |
+
2. **Search Limitations**
|
| 180 |
+
- Error: "Error searching with DuckDuckGo"
|
| 181 |
+
- Solution: Retry with a different search query or try enabling the Serper API
|
| 182 |
+
|
| 183 |
+
3. **Model Errors**
|
| 184 |
+
- Error: "Error during question analysis" or "Error formulating answer"
|
| 185 |
+
- Solution: Check your OpenAI API key and quota, or try a less complex question
|
| 186 |
+
|
| 187 |
+
4. **Web Content Issues**
|
| 188 |
+
- Error: "Error extracting content"
|
| 189 |
+
- Solution: The target website may be blocking scraping; try a different source
|
| 190 |
+
|
| 191 |
+
### Debug Mode
|
| 192 |
+
|
| 193 |
+
For enhanced debugging, modify the logging level in `agent.py`:
|
| 194 |
+
|
| 195 |
+
```python
|
| 196 |
+
logging.basicConfig(
|
| 197 |
+
level=logging.DEBUG, # Change from INFO to DEBUG
|
| 198 |
+
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
|
| 199 |
+
)
|
| 200 |
+
```
|
| 201 |
+
|
| 202 |
+
## Extending GAIA
|
| 203 |
+
|
| 204 |
+
You can extend GAIA's capabilities by:
|
| 205 |
+
|
| 206 |
+
1. **Adding New Tools**: Implement new tools in the `execute_tool` function in `agent.py`
|
| 207 |
+
2. **Customizing Prompts**: Modify the prompt templates in `analyze_question`, `create_plan`, and `formulate_answer`
|
| 208 |
+
3. **Enhancing Memory**: Extend the `SimpleMemory` class with additional storage options
|
| 209 |
+
4. **Optimizing Search**: Implement additional search backends or content extraction methods
|
| 210 |
+
|
| 211 |
+
## License & Attribution
|
| 212 |
+
|
| 213 |
+
GAIA Agent is developed as part of the Hugging Face Agents course and is intended for educational and demonstration purposes.
|
| 214 |
+
|
| 215 |
+
---
|
| 216 |
+
|
| 217 |
*For more information, questions, or issues, please visit the repository on Hugging Face Spaces or submit an issue on GitHub.*
|