Spaces:
Sleeping
Sleeping
Transform basic chatbot into DeepSpaceSearch agentic research app
Browse filesMajor enhancements:
- Integrate smolagents CodeAgent framework with multi-step reasoning
- Add web search (DuckDuckGo), webpage scraping, and image generation (FLUX.1) tools
- Implement streaming chat interface with configurable agent parameters (max steps, verbosity, temperature, top-p)
- Add comprehensive README with architecture docs, installation guide, usage examples, and MCP integration roadmap
- Include project infrastructure: requirements.txt, .gitignore, LICENSE (Apache 2.0), and CLAUDE.md instructions
This transforms the template into a production-ready deep research application with OAuth support for HF Spaces deployment.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
- .gitignore +80 -0
- CLAUDE.md +99 -0
- LICENSE +201 -0
- README.md +251 -1
- app.py +126 -41
- docs/security_reviews/security-review-2025-11-23.md +226 -0
- requirements.txt +6 -0
.gitignore
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Python
|
| 2 |
+
__pycache__/
|
| 3 |
+
*.py[cod]
|
| 4 |
+
*$py.class
|
| 5 |
+
*.so
|
| 6 |
+
.Python
|
| 7 |
+
build/
|
| 8 |
+
develop-eggs/
|
| 9 |
+
dist/
|
| 10 |
+
downloads/
|
| 11 |
+
eggs/
|
| 12 |
+
.eggs/
|
| 13 |
+
lib/
|
| 14 |
+
lib64/
|
| 15 |
+
parts/
|
| 16 |
+
sdist/
|
| 17 |
+
var/
|
| 18 |
+
wheels/
|
| 19 |
+
pip-wheel-metadata/
|
| 20 |
+
share/python-wheels/
|
| 21 |
+
*.egg-info/
|
| 22 |
+
.installed.cfg
|
| 23 |
+
*.egg
|
| 24 |
+
MANIFEST
|
| 25 |
+
|
| 26 |
+
# Virtual environments
|
| 27 |
+
venv/
|
| 28 |
+
env/
|
| 29 |
+
ENV/
|
| 30 |
+
env.bak/
|
| 31 |
+
venv.bak/
|
| 32 |
+
.venv/
|
| 33 |
+
|
| 34 |
+
# Gradio
|
| 35 |
+
gradio_cached_examples/
|
| 36 |
+
flagged/
|
| 37 |
+
|
| 38 |
+
# Environment variables
|
| 39 |
+
.env
|
| 40 |
+
.env.local
|
| 41 |
+
.env.*.local
|
| 42 |
+
|
| 43 |
+
# IDE
|
| 44 |
+
.vscode/
|
| 45 |
+
.idea/
|
| 46 |
+
*.swp
|
| 47 |
+
*.swo
|
| 48 |
+
*~
|
| 49 |
+
.project
|
| 50 |
+
.pydevproject
|
| 51 |
+
.settings/
|
| 52 |
+
.claude
|
| 53 |
+
|
| 54 |
+
# OS
|
| 55 |
+
.DS_Store
|
| 56 |
+
.DS_Store?
|
| 57 |
+
._*
|
| 58 |
+
.Spotlight-V100
|
| 59 |
+
.Trashes
|
| 60 |
+
ehthumbs.db
|
| 61 |
+
Thumbs.db
|
| 62 |
+
|
| 63 |
+
# Logs
|
| 64 |
+
*.log
|
| 65 |
+
|
| 66 |
+
# Jupyter Notebook
|
| 67 |
+
.ipynb_checkpoints
|
| 68 |
+
|
| 69 |
+
# pytest
|
| 70 |
+
.pytest_cache/
|
| 71 |
+
.coverage
|
| 72 |
+
htmlcov/
|
| 73 |
+
|
| 74 |
+
# mypy
|
| 75 |
+
.mypy_cache/
|
| 76 |
+
.dmypy.json
|
| 77 |
+
dmypy.json
|
| 78 |
+
|
| 79 |
+
# Project Files
|
| 80 |
+
tmp
|
CLAUDE.md
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# CLAUDE.md
|
| 2 |
+
|
| 3 |
+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
| 4 |
+
|
| 5 |
+
## Project Overview
|
| 6 |
+
|
| 7 |
+
DeepSpaceSearch is an agentic deep research application built with Gradio and smolagents. It provides a chat interface where an AI agent can perform web searches, generate images, and provide comprehensive answers by executing multi-step reasoning tasks. The application is designed to run on Hugging Face Spaces with OAuth authentication.
|
| 8 |
+
|
| 9 |
+
## Architecture
|
| 10 |
+
|
| 11 |
+
This is a single-file Gradio application (`app.py`) built on the **smolagents** framework. Key architectural components:
|
| 12 |
+
|
| 13 |
+
**Agent System** (`app.py:52-64`):
|
| 14 |
+
- Uses `CodeAgent` from smolagents as the core reasoning engine
|
| 15 |
+
- The agent orchestrates multi-step tasks using available tools
|
| 16 |
+
- Configured with `max_steps` to limit execution depth and `verbosity_level` for logging
|
| 17 |
+
|
| 18 |
+
**Tool Ecosystem** (`app.py:17-26`):
|
| 19 |
+
- `DuckDuckGoSearchTool`: Web search with rate limiting (5 results, 2.0s rate limit)
|
| 20 |
+
- `FinalAnswerTool`: Required for the agent to return structured final responses
|
| 21 |
+
- `image_generation_tool`: Remote tool loaded from HF Space (black-forest-labs/FLUX.1-schnell) for image generation
|
| 22 |
+
- Tools are imported from smolagents or dynamically loaded using `Tool.from_space()`
|
| 23 |
+
|
| 24 |
+
**Model Layer** (`app.py:42-49`):
|
| 25 |
+
- Uses `InferenceClientModel` wrapper around Hugging Face Inference API
|
| 26 |
+
- Default model: `Qwen/Qwen2.5-Coder-32B-Instruct` (configurable via `HF_MODEL_ID` env var)
|
| 27 |
+
- Model parameters (max_tokens, temperature, top_p) are user-configurable through the UI
|
| 28 |
+
|
| 29 |
+
**Streaming Interface** (`app.py:66-71`):
|
| 30 |
+
- `stream_to_gradio()` converts agent execution steps into Gradio-compatible message stream
|
| 31 |
+
- Messages are yielded as they're produced, showing agent reasoning in real-time
|
| 32 |
+
- Uses `gr.ChatInterface` with "messages" type format (role/content dictionaries)
|
| 33 |
+
|
| 34 |
+
**Authentication**:
|
| 35 |
+
- OAuth flow configured in README.md (`hf_oauth: true`, scope: `inference-api`)
|
| 36 |
+
- Token accessed via `HF_TOKEN` environment variable (automatically set by HF Spaces with OAuth, manually set for local dev)
|
| 37 |
+
|
| 38 |
+
## Development Commands
|
| 39 |
+
|
| 40 |
+
ALWAYS USE A VIRTUAL ENVIRONMENT BEFORE RUNNING LOCALLY!!!
|
| 41 |
+
|
| 42 |
+
**Setup**:
|
| 43 |
+
```bash
|
| 44 |
+
python -m venv venv
|
| 45 |
+
source venv/bin/activate # On Windows: venv\Scripts\activate
|
| 46 |
+
pip install -r requirements.txt
|
| 47 |
+
```
|
| 48 |
+
|
| 49 |
+
**Run locally**:
|
| 50 |
+
```bash
|
| 51 |
+
python app.py
|
| 52 |
+
```
|
| 53 |
+
Launches Gradio interface at http://127.0.0.1:7860
|
| 54 |
+
|
| 55 |
+
**Environment Configuration**:
|
| 56 |
+
Create a `.env` file for local development:
|
| 57 |
+
```
|
| 58 |
+
HF_TOKEN=hf_... # Your Hugging Face token with inference-api scope
|
| 59 |
+
HF_MODEL_ID=Qwen/Qwen2.5-Coder-32B-Instruct # Optional: override default model
|
| 60 |
+
```
|
| 61 |
+
|
| 62 |
+
## Hugging Face Spaces Deployment
|
| 63 |
+
|
| 64 |
+
The app auto-deploys on HF Spaces via README.md metadata:
|
| 65 |
+
- `sdk: gradio` with `sdk_version: 5.42.0`
|
| 66 |
+
- `app_file: app.py`
|
| 67 |
+
- OAuth is handled automatically by the platform when `hf_oauth: true` is set
|
| 68 |
+
- The `HF_TOKEN` environment variable is automatically populated with the user's OAuth token
|
| 69 |
+
|
| 70 |
+
## Key Dependencies
|
| 71 |
+
|
| 72 |
+
- `smolagents[gradio]`: Agentic framework with Gradio streaming support
|
| 73 |
+
- `gradio[oauth]==5.42.0`: UI framework with OAuth support
|
| 74 |
+
- `duckduckgo_search` / `ddgs`: Web search backend
|
| 75 |
+
- `huggingface_hub`: Inference API client
|
| 76 |
+
- `python-dotenv`: Environment variable management for local development
|
| 77 |
+
|
| 78 |
+
## Adding New Tools
|
| 79 |
+
|
| 80 |
+
To add a tool to the agent:
|
| 81 |
+
|
| 82 |
+
**From smolagents built-ins**:
|
| 83 |
+
```python
|
| 84 |
+
from smolagents import YourTool
|
| 85 |
+
your_tool = YourTool()
|
| 86 |
+
agent = CodeAgent(tools=[search_tool, your_tool, final_answer], ...)
|
| 87 |
+
```
|
| 88 |
+
|
| 89 |
+
**From a Hugging Face Space**:
|
| 90 |
+
```python
|
| 91 |
+
your_tool = Tool.from_space(
|
| 92 |
+
space_id="namespace/space-name",
|
| 93 |
+
name="tool_name",
|
| 94 |
+
description="What this tool does. Returns X.",
|
| 95 |
+
api_name="/endpoint_name",
|
| 96 |
+
)
|
| 97 |
+
```
|
| 98 |
+
|
| 99 |
+
Always include `FinalAnswerTool()` in the tools list - it's required for the agent to return results.
|
LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Apache License
|
| 2 |
+
Version 2.0, January 2004
|
| 3 |
+
http://www.apache.org/licenses/
|
| 4 |
+
|
| 5 |
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
| 6 |
+
|
| 7 |
+
1. Definitions.
|
| 8 |
+
|
| 9 |
+
"License" shall mean the terms and conditions for use, reproduction,
|
| 10 |
+
and distribution as defined by Sections 1 through 9 of this document.
|
| 11 |
+
|
| 12 |
+
"Licensor" shall mean the copyright owner or entity authorized by
|
| 13 |
+
the copyright owner that is granting the License.
|
| 14 |
+
|
| 15 |
+
"Legal Entity" shall mean the union of the acting entity and all
|
| 16 |
+
other entities that control, are controlled by, or are under common
|
| 17 |
+
control with that entity. For the purposes of this definition,
|
| 18 |
+
"control" means (i) the power, direct or indirect, to cause the
|
| 19 |
+
direction or management of such entity, whether by contract or
|
| 20 |
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
| 21 |
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
| 22 |
+
|
| 23 |
+
"You" (or "Your") shall mean an individual or Legal Entity
|
| 24 |
+
exercising permissions granted by this License.
|
| 25 |
+
|
| 26 |
+
"Source" form shall mean the preferred form for making modifications,
|
| 27 |
+
including but not limited to software source code, documentation
|
| 28 |
+
source, and configuration files.
|
| 29 |
+
|
| 30 |
+
"Object" form shall mean any form resulting from mechanical
|
| 31 |
+
transformation or translation of a Source form, including but
|
| 32 |
+
not limited to compiled object code, generated documentation,
|
| 33 |
+
and conversions to other media types.
|
| 34 |
+
|
| 35 |
+
"Work" shall mean the work of authorship, whether in Source or
|
| 36 |
+
Object form, made available under the License, as indicated by a
|
| 37 |
+
copyright notice that is included in or attached to the work
|
| 38 |
+
(an example is provided in the Appendix below).
|
| 39 |
+
|
| 40 |
+
"Derivative Works" shall mean any work, whether in Source or Object
|
| 41 |
+
form, that is based on (or derived from) the Work and for which the
|
| 42 |
+
editorial revisions, annotations, elaborations, or other modifications
|
| 43 |
+
represent, as a whole, an original work of authorship. For the purposes
|
| 44 |
+
of this License, Derivative Works shall not include works that remain
|
| 45 |
+
separable from, or merely link (or bind by name) to the interfaces of,
|
| 46 |
+
the Work and Derivative Works thereof.
|
| 47 |
+
|
| 48 |
+
"Contribution" shall mean any work of authorship, including
|
| 49 |
+
the original version of the Work and any modifications or additions
|
| 50 |
+
to that Work or Derivative Works thereof, that is intentionally
|
| 51 |
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
| 52 |
+
or by an individual or Legal Entity authorized to submit on behalf of
|
| 53 |
+
the copyright owner. For the purposes of this definition, "submitted"
|
| 54 |
+
means any form of electronic, verbal, or written communication sent
|
| 55 |
+
to the Licensor or its representatives, including but not limited to
|
| 56 |
+
communication on electronic mailing lists, source code control systems,
|
| 57 |
+
and issue tracking systems that are managed by, or on behalf of, the
|
| 58 |
+
Licensor for the purpose of discussing and improving the Work, but
|
| 59 |
+
excluding communication that is conspicuously marked or otherwise
|
| 60 |
+
designated in writing by the copyright owner as "Not a Contribution."
|
| 61 |
+
|
| 62 |
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
| 63 |
+
on behalf of whom a Contribution has been received by Licensor and
|
| 64 |
+
subsequently incorporated within the Work.
|
| 65 |
+
|
| 66 |
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
| 67 |
+
this License, each Contributor hereby grants to You a perpetual,
|
| 68 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
| 69 |
+
copyright license to reproduce, prepare Derivative Works of,
|
| 70 |
+
publicly display, publicly perform, sublicense, and distribute the
|
| 71 |
+
Work and such Derivative Works in Source or Object form.
|
| 72 |
+
|
| 73 |
+
3. Grant of Patent License. Subject to the terms and conditions of
|
| 74 |
+
this License, each Contributor hereby grants to You a perpetual,
|
| 75 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
| 76 |
+
(except as stated in this section) patent license to make, have made,
|
| 77 |
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
| 78 |
+
where such license applies only to those patent claims licensable
|
| 79 |
+
by such Contributor that are necessarily infringed by their
|
| 80 |
+
Contribution(s) alone or by combination of their Contribution(s)
|
| 81 |
+
with the Work to which such Contribution(s) was submitted. If You
|
| 82 |
+
institute patent litigation against any entity (including a
|
| 83 |
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
| 84 |
+
or a Contribution incorporated within the Work constitutes direct
|
| 85 |
+
or contributory patent infringement, then any patent licenses
|
| 86 |
+
granted to You under this License for that Work shall terminate
|
| 87 |
+
as of the date such litigation is filed.
|
| 88 |
+
|
| 89 |
+
4. Redistribution. You may reproduce and distribute copies of the
|
| 90 |
+
Work or Derivative Works thereof in any medium, with or without
|
| 91 |
+
modifications, and in Source or Object form, provided that You
|
| 92 |
+
meet the following conditions:
|
| 93 |
+
|
| 94 |
+
(a) You must give any other recipients of the Work or
|
| 95 |
+
Derivative Works a copy of this License; and
|
| 96 |
+
|
| 97 |
+
(b) You must cause any modified files to carry prominent notices
|
| 98 |
+
stating that You changed the files; and
|
| 99 |
+
|
| 100 |
+
(c) You must retain, in the Source form of any Derivative Works
|
| 101 |
+
that You distribute, all copyright, patent, trademark, and
|
| 102 |
+
attribution notices from the Source form of the Work,
|
| 103 |
+
excluding those notices that do not pertain to any part of
|
| 104 |
+
the Derivative Works; and
|
| 105 |
+
|
| 106 |
+
(d) If the Work includes a "NOTICE" text file as part of its
|
| 107 |
+
distribution, then any Derivative Works that You distribute must
|
| 108 |
+
include a readable copy of the attribution notices contained
|
| 109 |
+
within such NOTICE file, excluding those notices that do not
|
| 110 |
+
pertain to any part of the Derivative Works, in at least one
|
| 111 |
+
of the following places: within a NOTICE text file distributed
|
| 112 |
+
as part of the Derivative Works; within the Source form or
|
| 113 |
+
documentation, if provided along with the Derivative Works; or,
|
| 114 |
+
within a display generated by the Derivative Works, if and
|
| 115 |
+
wherever such third-party notices normally appear. The contents
|
| 116 |
+
of the NOTICE file are for informational purposes only and
|
| 117 |
+
do not modify the License. You may add Your own attribution
|
| 118 |
+
notices within Derivative Works that You distribute, alongside
|
| 119 |
+
or as an addendum to the NOTICE text from the Work, provided
|
| 120 |
+
that such additional attribution notices cannot be construed
|
| 121 |
+
as modifying the License.
|
| 122 |
+
|
| 123 |
+
You may add Your own copyright statement to Your modifications and
|
| 124 |
+
may provide additional or different license terms and conditions
|
| 125 |
+
for use, reproduction, or distribution of Your modifications, or
|
| 126 |
+
for any such Derivative Works as a whole, provided Your use,
|
| 127 |
+
reproduction, and distribution of the Work otherwise complies with
|
| 128 |
+
the conditions stated in this License.
|
| 129 |
+
|
| 130 |
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
| 131 |
+
any Contribution intentionally submitted for inclusion in the Work
|
| 132 |
+
by You to the Licensor shall be under the terms and conditions of
|
| 133 |
+
this License, without any additional terms or conditions.
|
| 134 |
+
Notwithstanding the above, nothing herein shall supersede or modify
|
| 135 |
+
the terms of any separate license agreement you may have executed
|
| 136 |
+
with Licensor regarding such Contributions.
|
| 137 |
+
|
| 138 |
+
6. Trademarks. This License does not grant permission to use the trade
|
| 139 |
+
names, trademarks, service marks, or product names of the Licensor,
|
| 140 |
+
except as required for reasonable and customary use in describing the
|
| 141 |
+
origin of the Work and reproducing the content of the NOTICE file.
|
| 142 |
+
|
| 143 |
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
| 144 |
+
agreed to in writing, Licensor provides the Work (and each
|
| 145 |
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
| 146 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
| 147 |
+
implied, including, without limitation, any warranties or conditions
|
| 148 |
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
| 149 |
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
| 150 |
+
appropriateness of using or redistributing the Work and assume any
|
| 151 |
+
risks associated with Your exercise of permissions under this License.
|
| 152 |
+
|
| 153 |
+
8. Limitation of Liability. In no event and under no legal theory,
|
| 154 |
+
whether in tort (including negligence), contract, or otherwise,
|
| 155 |
+
unless required by applicable law (such as deliberate and grossly
|
| 156 |
+
negligent acts) or agreed to in writing, shall any Contributor be
|
| 157 |
+
liable to You for damages, including any direct, indirect, special,
|
| 158 |
+
incidental, or consequential damages of any character arising as a
|
| 159 |
+
result of this License or out of the use or inability to use the
|
| 160 |
+
Work (including but not limited to damages for loss of goodwill,
|
| 161 |
+
work stoppage, computer failure or malfunction, or any and all
|
| 162 |
+
other commercial damages or losses), even if such Contributor
|
| 163 |
+
has been advised of the possibility of such damages.
|
| 164 |
+
|
| 165 |
+
9. Accepting Warranty or Additional Liability. While redistributing
|
| 166 |
+
the Work or Derivative Works thereof, You may choose to offer,
|
| 167 |
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
| 168 |
+
or other liability obligations and/or rights consistent with this
|
| 169 |
+
License. However, in accepting such obligations, You may act only
|
| 170 |
+
on Your own behalf and on Your sole responsibility, not on behalf
|
| 171 |
+
of any other Contributor, and only if You agree to indemnify,
|
| 172 |
+
defend, and hold each Contributor harmless for any liability
|
| 173 |
+
incurred by, or claims asserted against, such Contributor by reason
|
| 174 |
+
of your accepting any such warranty or additional liability.
|
| 175 |
+
|
| 176 |
+
END OF TERMS AND CONDITIONS
|
| 177 |
+
|
| 178 |
+
APPENDIX: How to apply the Apache License to your work.
|
| 179 |
+
|
| 180 |
+
To apply the Apache License to your work, attach the following
|
| 181 |
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
| 182 |
+
replaced with your own identifying information. (Don't include
|
| 183 |
+
the brackets!) The text should be enclosed in the appropriate
|
| 184 |
+
comment syntax for the file format. We also recommend that a
|
| 185 |
+
file or class name and description of purpose be included on the
|
| 186 |
+
same "printed page" as the copyright notice for easier
|
| 187 |
+
identification within third-party archives.
|
| 188 |
+
|
| 189 |
+
Copyright 2025 DeepSpaceSearch Contributors
|
| 190 |
+
|
| 191 |
+
Licensed under the Apache License, Version 2.0 (the "License");
|
| 192 |
+
you may not use this file except in compliance with the License.
|
| 193 |
+
You may obtain a copy of the License at
|
| 194 |
+
|
| 195 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 196 |
+
|
| 197 |
+
Unless required by applicable law or agreed to in writing, software
|
| 198 |
+
distributed under the License is distributed on an "AS IS" BASIS,
|
| 199 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 200 |
+
See the License for the specific language governing permissions and
|
| 201 |
+
limitations under the License.
|
README.md
CHANGED
|
@@ -12,6 +12,256 @@ hf_oauth_scopes:
|
|
| 12 |
- inference-api
|
| 13 |
license: apache-2.0
|
| 14 |
short_description: Agentic Deep Research with MCP
|
|
|
|
|
|
|
| 15 |
---
|
| 16 |
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
- inference-api
|
| 13 |
license: apache-2.0
|
| 14 |
short_description: Agentic Deep Research with MCP
|
| 15 |
+
tags:
|
| 16 |
+
- mcp-in-action-track-creative
|
| 17 |
---
|
| 18 |
|
| 19 |
+
# DeepSpaceSearch 🔍
|
| 20 |
+
|
| 21 |
+
An agentic deep research application powered by [smolagents](https://huggingface.co/docs/smolagents), [Gradio](https://gradio.app), and the [Hugging Face Inference API](https://huggingface.co/docs/api-inference/index). DeepSpaceSearch combines web search, webpage analysis, and image generation capabilities in an intelligent AI agent that can perform multi-step reasoning to answer complex questions.
|
| 22 |
+
|
| 23 |
+
## Features
|
| 24 |
+
|
| 25 |
+
- **🤖 Agentic AI**: Built on smolagents' `CodeAgent` framework for autonomous multi-step task execution
|
| 26 |
+
- **🔎 Web Search**: Integrated DuckDuckGo search for real-time information retrieval
|
| 27 |
+
- **🌐 Web Scraping**: Visit and extract content from webpages using `VisitWebpageTool`
|
| 28 |
+
- **🎨 Image Generation**: Generate images using FLUX.1-schnell through Hugging Face Spaces integration
|
| 29 |
+
- **💬 Streaming Chat Interface**: Real-time streaming of agent reasoning steps
|
| 30 |
+
- **⚙️ Configurable Parameters**: Adjust max steps, verbosity, temperature, and token limits
|
| 31 |
+
- **🔐 OAuth Authentication**: Seamless authentication via Hugging Face OAuth
|
| 32 |
+
|
| 33 |
+
## Architecture
|
| 34 |
+
|
| 35 |
+
DeepSpaceSearch is built as a single-file Gradio application with the following components:
|
| 36 |
+
|
| 37 |
+
### Agent System (`app.py:61-75`)
|
| 38 |
+
- **`CodeAgent`**: Core reasoning engine from smolagents
|
| 39 |
+
- Orchestrates multi-step tasks using available tools
|
| 40 |
+
- Configurable execution depth and verbosity
|
| 41 |
+
|
| 42 |
+
### Tool Ecosystem (`app.py:21-31`)
|
| 43 |
+
- **`DuckDuckGoSearchTool`**: Web search with rate limiting (5 results max, 2.0s rate limit)
|
| 44 |
+
- **`VisitWebpageTool`**: Extract and analyze webpage content
|
| 45 |
+
- **`FinalAnswerTool`**: Required for agent to return structured responses
|
| 46 |
+
- **`image_generation_tool`**: Remote tool from HF Space (black-forest-labs/FLUX.1-schnell)
|
| 47 |
+
|
| 48 |
+
### Model Layer (`app.py:51-58`)
|
| 49 |
+
- **`InferenceClientModel`**: Wrapper around Hugging Face Inference API
|
| 50 |
+
- Default model: `Qwen/Qwen2.5-Coder-32B-Instruct`
|
| 51 |
+
- User-configurable parameters (max_tokens, temperature, top_p)
|
| 52 |
+
|
| 53 |
+
### Streaming Interface (`app.py:86-88`)
|
| 54 |
+
- `stream_to_gradio()` converts agent execution steps to Gradio messages
|
| 55 |
+
- Real-time display of agent reasoning process
|
| 56 |
+
- Messages format: `{role: "assistant", content: "..."}`
|
| 57 |
+
|
| 58 |
+
## Getting Started
|
| 59 |
+
|
| 60 |
+
### Prerequisites
|
| 61 |
+
|
| 62 |
+
- Python 3.10+
|
| 63 |
+
- Hugging Face account (for inference API access)
|
| 64 |
+
- HF token with `inference-api` scope
|
| 65 |
+
|
| 66 |
+
### Installation
|
| 67 |
+
|
| 68 |
+
**ALWAYS USE A VIRTUAL ENVIRONMENT:**
|
| 69 |
+
|
| 70 |
+
```bash
|
| 71 |
+
# Clone the repository
|
| 72 |
+
git clone https://huggingface.co/spaces/YOUR_USERNAME/DeepSpaceSearch
|
| 73 |
+
cd DeepSpaceSearch
|
| 74 |
+
|
| 75 |
+
# Create and activate virtual environment
|
| 76 |
+
python -m venv venv
|
| 77 |
+
source venv/bin/activate # On Windows: venv\Scripts\activate
|
| 78 |
+
|
| 79 |
+
# Install dependencies
|
| 80 |
+
pip install -r requirements.txt
|
| 81 |
+
```
|
| 82 |
+
|
| 83 |
+
### Configuration
|
| 84 |
+
|
| 85 |
+
#### Authentication (Required)
|
| 86 |
+
|
| 87 |
+
**Recommended: Use Hugging Face CLI**
|
| 88 |
+
|
| 89 |
+
The easiest and most secure way to authenticate locally is using the Hugging Face CLI:
|
| 90 |
+
|
| 91 |
+
```bash
|
| 92 |
+
hf auth login
|
| 93 |
+
```
|
| 94 |
+
|
| 95 |
+
This will prompt you to paste your HF token (get one at <https://huggingface.co/settings/tokens> with `inference-api` scope) and securely store it in `~/.cache/huggingface/token`.
|
| 96 |
+
|
| 97 |
+
**Alternative: Use .env file**
|
| 98 |
+
|
| 99 |
+
If you prefer environment variables, create a `.env` file:
|
| 100 |
+
|
| 101 |
+
```env
|
| 102 |
+
HF_TOKEN=hf_... # Your HF token with inference-api scope
|
| 103 |
+
```
|
| 104 |
+
|
| 105 |
+
#### Optional Environment Variables
|
| 106 |
+
|
| 107 |
+
You can customize the application behavior with these optional environment variables in your `.env` file:
|
| 108 |
+
|
| 109 |
+
| Variable | Default | Description |
|
| 110 |
+
|----------|---------|-------------|
|
| 111 |
+
| `HF_MODEL_ID` | `Qwen/Qwen2.5-Coder-32B-Instruct` | Override the default LLM model |
|
| 112 |
+
|
| 113 |
+
Example `.env` with optional variables:
|
| 114 |
+
|
| 115 |
+
```env
|
| 116 |
+
# Optional: Use a different model
|
| 117 |
+
HF_MODEL_ID=meta-llama/Llama-3.3-70B-Instruct
|
| 118 |
+
```
|
| 119 |
+
|
| 120 |
+
### Running Locally
|
| 121 |
+
|
| 122 |
+
```bash
|
| 123 |
+
python app.py
|
| 124 |
+
```
|
| 125 |
+
|
| 126 |
+
The application will launch at http://127.0.0.1:7860
|
| 127 |
+
|
| 128 |
+
## Usage
|
| 129 |
+
|
| 130 |
+
1. **Login**: Click the login button and authenticate with your Hugging Face account
|
| 131 |
+
2. **Ask a question**: Type your query in the chat interface
|
| 132 |
+
3. **Configure settings** (optional): Click "Additional Inputs" to adjust:
|
| 133 |
+
- **Max Steps**: Maximum reasoning steps (default: 6)
|
| 134 |
+
- **Verbosity Level**: Log detail level (default: 1)
|
| 135 |
+
- **Max New Tokens**: Token generation limit (default: 2096)
|
| 136 |
+
- **Temperature**: Creativity control (default: 0.5)
|
| 137 |
+
- **Top-P**: Nucleus sampling threshold (default: 0.95)
|
| 138 |
+
4. **Watch the agent work**: See real-time reasoning steps as the agent searches, analyzes, and formulates answers
|
| 139 |
+
|
| 140 |
+
### Example Queries
|
| 141 |
+
|
| 142 |
+
- "What are the latest developments in quantum computing?"
|
| 143 |
+
- "Look up the 10 day forcast for the EST timezone and generate an image."
|
| 144 |
+
- "Compare the top 3, by number of cars sold, electric vehicles in 2025."
|
| 145 |
+
- "What is the current weather in Tokyo and show me an image of the city."
|
| 146 |
+
|
| 147 |
+
## Deployment
|
| 148 |
+
|
| 149 |
+
### Hugging Face Spaces
|
| 150 |
+
|
| 151 |
+
The app auto-deploys on Hugging Face Spaces via the metadata in README.md:
|
| 152 |
+
|
| 153 |
+
- `sdk: gradio` with `sdk_version: 5.42.0`
|
| 154 |
+
- `app_file: app.py`
|
| 155 |
+
- `hf_oauth: true` enables automatic OAuth authentication
|
| 156 |
+
- `HF_TOKEN` is automatically populated with the user's OAuth token
|
| 157 |
+
|
| 158 |
+
Simply push to your Space's repository and it will deploy automatically.
|
| 159 |
+
|
| 160 |
+
## Dependencies
|
| 161 |
+
|
| 162 |
+
| Package | Purpose |
|
| 163 |
+
|---------|---------|
|
| 164 |
+
| `smolagents[gradio]` | Agentic framework with Gradio streaming |
|
| 165 |
+
| `gradio[oauth]==5.42.0` | UI framework with OAuth support |
|
| 166 |
+
| `duckduckgo_search` / `ddgs` | Web search backend |
|
| 167 |
+
| `huggingface_hub` | Inference API client |
|
| 168 |
+
| `python-dotenv` | Environment variable management |
|
| 169 |
+
|
| 170 |
+
## Adding New Tools
|
| 171 |
+
|
| 172 |
+
### From smolagents built-ins:
|
| 173 |
+
|
| 174 |
+
```python
|
| 175 |
+
from smolagents import YourTool
|
| 176 |
+
your_tool = YourTool()
|
| 177 |
+
agent = CodeAgent(tools=[search_tool, your_tool, final_answer], ...)
|
| 178 |
+
```
|
| 179 |
+
|
| 180 |
+
### From a Hugging Face Space:
|
| 181 |
+
|
| 182 |
+
```python
|
| 183 |
+
your_tool = Tool.from_space(
|
| 184 |
+
space_id="namespace/space-name",
|
| 185 |
+
name="tool_name",
|
| 186 |
+
description="What this tool does. Returns X.",
|
| 187 |
+
api_name="/endpoint_name",
|
| 188 |
+
)
|
| 189 |
+
```
|
| 190 |
+
|
| 191 |
+
**Important**: Always include `FinalAnswerTool()` in the tools list - it's required for the agent to return results.
|
| 192 |
+
|
| 193 |
+
## TODO
|
| 194 |
+
|
| 195 |
+
### MCP Server Integration
|
| 196 |
+
- [ ] **Integrate MCP servers using smolagents**
|
| 197 |
+
- Reference: [smolagents MCP tutorial](https://huggingface.co/docs/smolagents/en/tutorials/tools#use-tools-from-an-mcp-server)
|
| 198 |
+
- Enable dynamic tool loading from Model Context Protocol servers
|
| 199 |
+
- Add support for custom MCP servers (filesystem, database, API integrations)
|
| 200 |
+
|
| 201 |
+
- [ ] **Add Groq MCP Server for enhanced research capabilities**
|
| 202 |
+
- Reference: [Groq AI Research Agent](https://groq.com/blog/how-to-build-your-own-ai-research-agent-with-one-groq-api-call)
|
| 203 |
+
- Reference: [groq-mcp-server](https://github.com/groq/groq-mcp-server)
|
| 204 |
+
- Integrate Groq's ultra-fast inference for parallel research queries
|
| 205 |
+
- Add Groq's Llama models as alternative reasoning engines
|
| 206 |
+
|
| 207 |
+
- [ ] **Create custom MCP servers for specialized research**
|
| 208 |
+
- Academic paper search (arXiv, PubMed, etc.)
|
| 209 |
+
- Code repository search (GitHub, GitLab)
|
| 210 |
+
- News aggregation and fact-checking
|
| 211 |
+
- Social media trend analysis
|
| 212 |
+
|
| 213 |
+
### Enhanced Research Capabilities
|
| 214 |
+
- [ ] **Multi-source verification**
|
| 215 |
+
- Cross-reference information across multiple sources
|
| 216 |
+
- Add confidence scoring for research findings
|
| 217 |
+
- Implement citation tracking
|
| 218 |
+
|
| 219 |
+
- [ ] **Advanced web scraping**
|
| 220 |
+
- PDF extraction and analysis
|
| 221 |
+
- Structured data extraction (tables, lists)
|
| 222 |
+
- Screenshot capture for visual analysis
|
| 223 |
+
|
| 224 |
+
- [ ] **Research report generation**
|
| 225 |
+
- Markdown/HTML formatted reports
|
| 226 |
+
- Automatic citation formatting
|
| 227 |
+
- Export to PDF/DOCX
|
| 228 |
+
|
| 229 |
+
### Tool Improvements
|
| 230 |
+
- [ ] **Add calculator tool** for mathematical queries
|
| 231 |
+
- [ ] **Add code execution tool** for running Python snippets
|
| 232 |
+
- [ ] **Add data visualization tool** for charts and graphs
|
| 233 |
+
- [ ] **Add file upload/download** for document analysis
|
| 234 |
+
|
| 235 |
+
### UI/UX Enhancements
|
| 236 |
+
- [ ] **Add conversation history** persistence
|
| 237 |
+
- [ ] **Add export chat** functionality
|
| 238 |
+
- [ ] **Add model selection** dropdown for different LLMs
|
| 239 |
+
- [ ] **Add cost tracking** for API usage
|
| 240 |
+
- [ ] **Dark mode** support
|
| 241 |
+
|
| 242 |
+
### Performance & Reliability
|
| 243 |
+
- [ ] **Add caching** for repeated searches
|
| 244 |
+
- [ ] **Implement retry logic** for failed API calls
|
| 245 |
+
- [ ] **Add rate limiting** dashboard
|
| 246 |
+
- [ ] **Optimize token usage** with streaming truncation
|
| 247 |
+
|
| 248 |
+
### Testing & Documentation
|
| 249 |
+
- [ ] **Add unit tests** for core functions
|
| 250 |
+
- [ ] **Add integration tests** for tools
|
| 251 |
+
- [ ] **Create video demo** of capabilities
|
| 252 |
+
- [ ] **Write detailed API documentation**
|
| 253 |
+
|
| 254 |
+
## Contributing
|
| 255 |
+
|
| 256 |
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
| 257 |
+
|
| 258 |
+
## License
|
| 259 |
+
|
| 260 |
+
Apache 2.0 - See LICENSE file for details
|
| 261 |
+
|
| 262 |
+
## Acknowledgments
|
| 263 |
+
|
| 264 |
+
- Built with [smolagents](https://huggingface.co/docs/smolagents) by Hugging Face
|
| 265 |
+
- UI powered by [Gradio](https://gradio.app)
|
| 266 |
+
- Image generation by [FLUX.1-schnell](https://huggingface.co/black-forest-labs/FLUX.1-schnell)
|
| 267 |
+
- Search powered by [DuckDuckGo](https://duckduckgo.com)
|
app.py
CHANGED
|
@@ -1,70 +1,155 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
|
|
|
|
| 3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
history: list[dict[str, str]],
|
| 8 |
-
system_message,
|
| 9 |
-
max_tokens,
|
| 10 |
-
temperature,
|
| 11 |
-
top_p,
|
| 12 |
-
hf_token: gr.OAuthToken,
|
| 13 |
-
):
|
| 14 |
-
"""
|
| 15 |
-
For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
|
| 16 |
-
"""
|
| 17 |
-
client = InferenceClient(token=hf_token.token, model="openai/gpt-oss-20b")
|
| 18 |
|
| 19 |
-
|
|
|
|
| 20 |
|
| 21 |
-
|
|
|
|
| 22 |
|
| 23 |
-
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
-
|
| 28 |
-
|
| 29 |
max_tokens=max_tokens,
|
| 30 |
-
stream=True,
|
| 31 |
temperature=temperature,
|
| 32 |
top_p=top_p,
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
token
|
| 36 |
-
|
| 37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
-
|
| 40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
chatbot = gr.ChatInterface(
|
| 47 |
-
respond,
|
| 48 |
type="messages",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
additional_inputs=[
|
| 50 |
-
gr.
|
| 51 |
-
|
| 52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
gr.Slider(
|
| 54 |
-
minimum=0.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
maximum=1.0,
|
| 56 |
value=0.95,
|
| 57 |
step=0.05,
|
| 58 |
-
label="Top-
|
|
|
|
| 59 |
),
|
| 60 |
],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
)
|
| 62 |
|
| 63 |
-
with
|
| 64 |
with gr.Sidebar():
|
|
|
|
| 65 |
gr.LoginButton()
|
| 66 |
-
|
| 67 |
-
|
| 68 |
|
| 69 |
if __name__ == "__main__":
|
| 70 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import os
|
| 3 |
+
import warnings
|
| 4 |
|
| 5 |
+
from dataclasses import asdict
|
| 6 |
+
from smolagents import CodeAgent, Tool
|
| 7 |
+
from smolagents import stream_to_gradio, InferenceClientModel
|
| 8 |
+
from smolagents import DuckDuckGoSearchTool, FinalAnswerTool, VisitWebpageTool
|
| 9 |
+
from dotenv import load_dotenv
|
| 10 |
|
| 11 |
+
# Load environment variables from .env file
|
| 12 |
+
load_dotenv()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
+
# Suppress OAuth warning when running locally (OAuth only works on HF Spaces)
|
| 15 |
+
warnings.filterwarnings("ignore", message=".*Gradio does not support OAuth features outside of a Space environment.*")
|
| 16 |
|
| 17 |
+
# Configuration
|
| 18 |
+
HF_MODEL_ID = os.getenv("HF_MODEL_ID", "Qwen/Qwen2.5-Coder-32B-Instruct")
|
| 19 |
|
| 20 |
+
# smolagents Toolbox
|
| 21 |
+
web_search = DuckDuckGoSearchTool(max_results=5, rate_limit=2.0)
|
| 22 |
+
visit_webpage = VisitWebpageTool()
|
| 23 |
+
final_answer = FinalAnswerTool()
|
| 24 |
|
| 25 |
+
# Import tool from Hub
|
| 26 |
+
image_generation_tool = Tool.from_space(
|
| 27 |
+
space_id="black-forest-labs/FLUX.1-schnell",
|
| 28 |
+
name="image_generator",
|
| 29 |
+
description="Generates an image following your prompt. Returns a PIL Image.",
|
| 30 |
+
api_name="/infer",
|
| 31 |
+
)
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
def interact_with_agent(
|
| 35 |
+
message,
|
| 36 |
+
history,
|
| 37 |
+
max_steps,
|
| 38 |
+
verbosity,
|
| 39 |
+
max_tokens,
|
| 40 |
+
temperature,
|
| 41 |
+
top_p,
|
| 42 |
+
hf_token: gr.OAuthToken | None = None,
|
| 43 |
+
):
|
| 44 |
+
# Extract the user's message content from the message dict
|
| 45 |
+
prompt = message["content"] if isinstance(message, dict) else message
|
| 46 |
+
|
| 47 |
+
# Get token from OAuth (HF Spaces) or environment variable (local dev)
|
| 48 |
+
token = hf_token.token if hf_token else os.getenv("HF_TOKEN")
|
| 49 |
|
| 50 |
+
# Create model with user-specified parameters
|
| 51 |
+
model = InferenceClientModel(
|
| 52 |
max_tokens=max_tokens,
|
|
|
|
| 53 |
temperature=temperature,
|
| 54 |
top_p=top_p,
|
| 55 |
+
model_id=HF_MODEL_ID,
|
| 56 |
+
custom_role_conversions=None,
|
| 57 |
+
token=token,
|
| 58 |
+
)
|
| 59 |
+
|
| 60 |
+
# Initialize the agent with the configured model
|
| 61 |
+
agent = CodeAgent(
|
| 62 |
+
model=model,
|
| 63 |
+
tools=[
|
| 64 |
+
image_generation_tool,
|
| 65 |
+
web_search,
|
| 66 |
+
visit_webpage,
|
| 67 |
+
final_answer
|
| 68 |
+
],
|
| 69 |
+
add_base_tools=False,
|
| 70 |
+
max_steps=max_steps,
|
| 71 |
+
verbosity_level=verbosity,
|
| 72 |
+
planning_interval=None,
|
| 73 |
+
name=None,
|
| 74 |
+
description=None,
|
| 75 |
+
)
|
| 76 |
|
| 77 |
+
# Print the names and descriptions of the added tools
|
| 78 |
+
print("--- Active Tools ---")
|
| 79 |
+
for tool_name, tool in agent.tools.items():
|
| 80 |
+
print(f"Tool Name: {tool_name}")
|
| 81 |
+
print(f"Description: {tool.description}")
|
| 82 |
+
print("-" * 20)
|
| 83 |
|
| 84 |
+
messages = []
|
| 85 |
+
yield messages
|
| 86 |
+
for msg in stream_to_gradio(agent, prompt):
|
| 87 |
+
messages.append(asdict(msg)) # type: ignore
|
| 88 |
+
yield messages
|
| 89 |
+
yield messages
|
| 90 |
|
| 91 |
+
|
| 92 |
+
demo = gr.ChatInterface(
|
| 93 |
+
interact_with_agent,
|
|
|
|
|
|
|
| 94 |
type="messages",
|
| 95 |
+
chatbot=gr.Chatbot(
|
| 96 |
+
label="Agent",
|
| 97 |
+
type="messages",
|
| 98 |
+
avatar_images=(
|
| 99 |
+
None,
|
| 100 |
+
"https://em-content.zobj.net/source/twitter/53/robot-face_1f916.png",
|
| 101 |
+
),
|
| 102 |
+
),
|
| 103 |
additional_inputs=[
|
| 104 |
+
gr.Number(
|
| 105 |
+
value=6,
|
| 106 |
+
label="Max Steps",
|
| 107 |
+
info="Maximum number of steps the agent can take to solve the task."
|
| 108 |
+
),
|
| 109 |
+
gr.Number(
|
| 110 |
+
value=1,
|
| 111 |
+
label="Verbosity Level",
|
| 112 |
+
info="Level of verbosity of the agent's logs."
|
| 113 |
+
),
|
| 114 |
+
gr.Slider(
|
| 115 |
+
minimum=128,
|
| 116 |
+
maximum=4096,
|
| 117 |
+
value=2096,
|
| 118 |
+
step=128,
|
| 119 |
+
label="Max New Tokens",
|
| 120 |
+
info="Maximum number of tokens to generate"
|
| 121 |
+
),
|
| 122 |
gr.Slider(
|
| 123 |
+
minimum=0.0,
|
| 124 |
+
maximum=2.0,
|
| 125 |
+
value=0.5,
|
| 126 |
+
step=0.1,
|
| 127 |
+
label="Temperature",
|
| 128 |
+
info="Controls randomness in generation. Higher = more creative"
|
| 129 |
+
),
|
| 130 |
+
gr.Slider(
|
| 131 |
+
minimum=0.0,
|
| 132 |
maximum=1.0,
|
| 133 |
value=0.95,
|
| 134 |
step=0.05,
|
| 135 |
+
label="Top-P",
|
| 136 |
+
info="Nucleus sampling threshold"
|
| 137 |
),
|
| 138 |
],
|
| 139 |
+
additional_inputs_accordion=gr.Accordion("Additional Inputs", open=False),
|
| 140 |
+
examples=[
|
| 141 |
+
["What are the latest developments in quantum computing?"],
|
| 142 |
+
["Look up the 10 day forcast for the EST timezone and generate an image."],
|
| 143 |
+
["Compare the top 3, by number of cars sold, electric vehicles in 2025."],
|
| 144 |
+
["What is the current weather in Tokyo and show me an image of the city."],
|
| 145 |
+
],
|
| 146 |
)
|
| 147 |
|
| 148 |
+
with demo:
|
| 149 |
with gr.Sidebar():
|
| 150 |
+
gr.Markdown("### Authentication")
|
| 151 |
gr.LoginButton()
|
| 152 |
+
gr.Markdown("Login with your Hugging Face account to use the inference API.")
|
|
|
|
| 153 |
|
| 154 |
if __name__ == "__main__":
|
| 155 |
demo.launch()
|
docs/security_reviews/security-review-2025-11-23.md
ADDED
|
@@ -0,0 +1,226 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Security Review Report - DeepSpaceSearch
|
| 2 |
+
|
| 3 |
+
**Review Date**: 2025-11-23
|
| 4 |
+
**Reviewer**: Automated Security Analysis
|
| 5 |
+
**Scope**: PR changes from basic chatbot to agentic AI application
|
| 6 |
+
**Methodology**: Static code analysis with false positive filtering
|
| 7 |
+
|
| 8 |
+
---
|
| 9 |
+
|
| 10 |
+
## Executive Summary
|
| 11 |
+
|
| 12 |
+
**Result**: No high-confidence security vulnerabilities were identified in this PR.
|
| 13 |
+
|
| 14 |
+
All potential findings were determined to be false positives after rigorous validation against established security precedents and exclusion criteria. Four potential issues were identified during initial analysis, but each failed to meet the required ≥8/10 confidence threshold for reporting.
|
| 15 |
+
|
| 16 |
+
---
|
| 17 |
+
|
| 18 |
+
## Analysis Methodology
|
| 19 |
+
|
| 20 |
+
This review followed a three-phase approach:
|
| 21 |
+
|
| 22 |
+
1. **Initial Vulnerability Identification**: Analyzed code changes for common security issues including injection vulnerabilities, authentication bypasses, and code execution risks
|
| 23 |
+
2. **False Positive Filtering**: Applied strict exclusion criteria including:
|
| 24 |
+
- DoS/resource exhaustion issues (explicitly excluded from scope)
|
| 25 |
+
- Environment variable attacks (per precedent: environment variables are trusted)
|
| 26 |
+
- Lack of hardening measures vs. concrete exploitable vulnerabilities
|
| 27 |
+
- Theoretical vs. practical security risks
|
| 28 |
+
3. **Confidence Scoring**: Assigned confidence scores (1-10) based on exploitability, with threshold of ≥8 required for reporting
|
| 29 |
+
|
| 30 |
+
---
|
| 31 |
+
|
| 32 |
+
## Findings Summary
|
| 33 |
+
|
| 34 |
+
| # | Issue | Initial Severity | Confidence Score | Status |
|
| 35 |
+
|---|-------|------------------|------------------|--------|
|
| 36 |
+
| 1 | Unpinned smolagents dependency (CVE-2025-5120) | HIGH | 6/10 | **Excluded** |
|
| 37 |
+
| 2 | Prompt injection via web browsing | HIGH | 3/10 | **Excluded** |
|
| 38 |
+
| 3 | Unvalidated execution parameters | HIGH | 2/10 | **Excluded** |
|
| 39 |
+
| 4 | Unvalidated HF_MODEL_ID env var | MEDIUM | 2/10 | **Excluded** |
|
| 40 |
+
|
| 41 |
+
---
|
| 42 |
+
|
| 43 |
+
## Detailed Analysis
|
| 44 |
+
|
| 45 |
+
### Finding 1: Unpinned smolagents Dependency
|
| 46 |
+
|
| 47 |
+
**Initial Assessment**: CodeAgent uses unpinned `smolagents[gradio]` dependency which could install versions vulnerable to CVE-2025-5120 (CVSS 9.9 - Critical sandbox escape RCE).
|
| 48 |
+
|
| 49 |
+
**Code Location**:
|
| 50 |
+
- `app.py` lines 61-75 (CodeAgent instantiation)
|
| 51 |
+
- `requirements.txt` line 6 (`smolagents[gradio]` without version pin)
|
| 52 |
+
|
| 53 |
+
**False Positive Analysis**:
|
| 54 |
+
```
|
| 55 |
+
Confidence Score: 6/10 - BELOW THRESHOLD
|
| 56 |
+
|
| 57 |
+
Reasons for exclusion:
|
| 58 |
+
1. Fresh installations today would receive v1.23.0 (patched version)
|
| 59 |
+
2. CVE-2025-5120 affects versions < 1.17.0 (patched May 2025)
|
| 60 |
+
3. This is a dependency management best practice, not an exploitable vulnerability in the current codebase
|
| 61 |
+
4. Deployment on HF Spaces provides containerized isolation
|
| 62 |
+
5. No evidence of vulnerable version being actively deployed
|
| 63 |
+
|
| 64 |
+
Classification: Dependency management issue, not active vulnerability
|
| 65 |
+
```
|
| 66 |
+
|
| 67 |
+
**Recommendation**: While not a reportable vulnerability, consider pinning to `smolagents[gradio]>=1.17.0` as a best practice to prevent regression.
|
| 68 |
+
|
| 69 |
+
---
|
| 70 |
+
|
| 71 |
+
### Finding 2: Prompt Injection via Web Browsing
|
| 72 |
+
|
| 73 |
+
**Initial Assessment**: `VisitWebpageTool` enables fetching arbitrary web content that could contain hidden prompt injection payloads.
|
| 74 |
+
|
| 75 |
+
**Code Location**: `app.py` lines 22, 66 (VisitWebpageTool usage)
|
| 76 |
+
|
| 77 |
+
**False Positive Analysis**:
|
| 78 |
+
```
|
| 79 |
+
Confidence Score: 3/10 - BELOW THRESHOLD
|
| 80 |
+
|
| 81 |
+
Reasons for exclusion:
|
| 82 |
+
1. This is a documented, known limitation of ALL agentic AI systems with web access
|
| 83 |
+
2. Per smolagents official docs: "an agent browsing the web could arrive on a malicious
|
| 84 |
+
website that contains harmful instructions"
|
| 85 |
+
3. Matches HARD EXCLUSION #14: "Including user-controlled content in AI system prompts
|
| 86 |
+
is not a vulnerability"
|
| 87 |
+
4. No actionable fix exists without removing core "deep research" functionality
|
| 88 |
+
5. Same limitation exists in: OpenAI GPT with browsing, Claude with MCP, Gemini with
|
| 89 |
+
extensions, AutoGPT, LangChain agents, etc.
|
| 90 |
+
6. Framework authors acknowledge this as inherent to autonomous agents, not a bug
|
| 91 |
+
|
| 92 |
+
Classification: Expected behavior of agentic AI systems, not a security boundary violation
|
| 93 |
+
```
|
| 94 |
+
|
| 95 |
+
**Recommendation**: This is an inherent characteristic of web-browsing AI agents. If concerned, consider:
|
| 96 |
+
- Documenting this limitation in user-facing documentation
|
| 97 |
+
- Implementing domain allowlisting for high-security deployments (at cost of functionality)
|
| 98 |
+
- Using remote code execution sandboxing (E2B/Docker) for defense-in-depth
|
| 99 |
+
|
| 100 |
+
---
|
| 101 |
+
|
| 102 |
+
### Finding 3: Unvalidated Execution Parameters
|
| 103 |
+
|
| 104 |
+
**Initial Assessment**: Users control agent parameters (`max_steps`, `temperature`) without validation, potentially increasing exploitation probability.
|
| 105 |
+
|
| 106 |
+
**Code Location**: `app.py` lines 34-43, 70, 104-113
|
| 107 |
+
|
| 108 |
+
**False Positive Analysis**:
|
| 109 |
+
```
|
| 110 |
+
Confidence Score: 2/10 - BELOW THRESHOLD
|
| 111 |
+
|
| 112 |
+
Reasons for exclusion:
|
| 113 |
+
1. Matches HARD EXCLUSION #1: "Denial of Service vulnerabilities"
|
| 114 |
+
2. Matches HARD EXCLUSION #3: "Rate limiting or resource exhaustion issues"
|
| 115 |
+
3. Matches HARD EXCLUSION #4: "Memory consumption or CPU exhaustion"
|
| 116 |
+
4. Matches HARD EXCLUSION #6: "Lack of hardening measures"
|
| 117 |
+
5. High max_steps → resource consumption (DoS), not code injection
|
| 118 |
+
6. High temperature → output randomness, not exploitable code injection path
|
| 119 |
+
7. No concrete exploit chain beyond resource exhaustion
|
| 120 |
+
|
| 121 |
+
Classification: Resource exhaustion / missing input validation (hardening issue)
|
| 122 |
+
```
|
| 123 |
+
|
| 124 |
+
**Recommendation**: While not a security vulnerability, consider implementing reasonable limits for operational stability:
|
| 125 |
+
- Cap `max_steps` to 20-50 (vs unlimited)
|
| 126 |
+
- Restrict `temperature` to 0.0-1.0 (vs 0.0-2.0)
|
| 127 |
+
- Add server-side validation
|
| 128 |
+
|
| 129 |
+
---
|
| 130 |
+
|
| 131 |
+
### Finding 4: Unvalidated HF_MODEL_ID Environment Variable
|
| 132 |
+
|
| 133 |
+
**Initial Assessment**: Model ID loaded from environment variable without validation, allowing potential substitution with malicious models.
|
| 134 |
+
|
| 135 |
+
**Code Location**: `app.py` lines 18, 55
|
| 136 |
+
|
| 137 |
+
**False Positive Analysis**:
|
| 138 |
+
```
|
| 139 |
+
Confidence Score: 2/10 - BELOW THRESHOLD
|
| 140 |
+
|
| 141 |
+
Reasons for exclusion:
|
| 142 |
+
1. DIRECTLY INVALIDATED by Precedent #3: "Environment variables and CLI flags are
|
| 143 |
+
trusted values. Attackers are generally not able to modify them in a secure
|
| 144 |
+
environment. Any attack that relies on controlling an environment variable is invalid."
|
| 145 |
+
2. Matches HARD EXCLUSION #6: "Lack of hardening measures"
|
| 146 |
+
3. No concrete attack path without environment variable control
|
| 147 |
+
4. In HF Spaces: env vars controlled by Space owner, not end users
|
| 148 |
+
5. In local dev: if attacker controls env vars, they already have code execution
|
| 149 |
+
|
| 150 |
+
Classification: Invalid per precedent - environment variables are trusted
|
| 151 |
+
```
|
| 152 |
+
|
| 153 |
+
**Recommendation**: If defense-in-depth hardening is desired, consider implementing model ID allowlisting, but this is not fixing a vulnerability.
|
| 154 |
+
|
| 155 |
+
---
|
| 156 |
+
|
| 157 |
+
## Code Changes Summary
|
| 158 |
+
|
| 159 |
+
The PR converts a basic Gradio chatbot to an agentic AI application using smolagents:
|
| 160 |
+
|
| 161 |
+
**Key Changes**:
|
| 162 |
+
- Replaced `InferenceClient` with `CodeAgent` from smolagents
|
| 163 |
+
- Added tools: `DuckDuckGoSearchTool`, `VisitWebpageTool`, `FinalAnswerTool`, image generation
|
| 164 |
+
- Enabled autonomous multi-step reasoning
|
| 165 |
+
- Added configurable parameters: max_steps, verbosity, temperature, top_p
|
| 166 |
+
- Implemented streaming agent responses via `stream_to_gradio()`
|
| 167 |
+
|
| 168 |
+
**Security Posture**:
|
| 169 |
+
- OAuth authentication via HF Spaces (`hf_oauth: true`)
|
| 170 |
+
- Containerized deployment on HF Spaces
|
| 171 |
+
- Token-based authentication for Inference API
|
| 172 |
+
- Standard smolagents security model with local code execution
|
| 173 |
+
|
| 174 |
+
---
|
| 175 |
+
|
| 176 |
+
## Risk Assessment
|
| 177 |
+
|
| 178 |
+
**Overall Risk Level**: **LOW**
|
| 179 |
+
|
| 180 |
+
The code changes introduce standard agentic AI capabilities using the smolagents framework. All identified issues fall into one of these categories:
|
| 181 |
+
|
| 182 |
+
1. **Best practice recommendations** (dependency pinning)
|
| 183 |
+
2. **Inherent limitations of agentic AI** (prompt injection via web content)
|
| 184 |
+
3. **Excluded issue types** (DoS/resource exhaustion)
|
| 185 |
+
4. **Invalid attack vectors** (environment variable control)
|
| 186 |
+
|
| 187 |
+
No high-confidence, exploitable security vulnerabilities were found that meet the reporting criteria.
|
| 188 |
+
|
| 189 |
+
---
|
| 190 |
+
|
| 191 |
+
## Recommendations
|
| 192 |
+
|
| 193 |
+
### Operational Best Practices (Non-Security)
|
| 194 |
+
1. Pin `smolagents[gradio]>=1.17.0` in requirements.txt for dependency stability
|
| 195 |
+
2. Consider implementing max_steps caps (e.g., ≤50) for operational stability
|
| 196 |
+
3. Document inherent limitations of web-browsing agents in user-facing docs
|
| 197 |
+
|
| 198 |
+
### Optional Defense-in-Depth (If Desired)
|
| 199 |
+
4. Implement remote code execution sandboxing (E2B/Docker) per smolagents security guide
|
| 200 |
+
5. Add domain allowlisting for `VisitWebpageTool` in high-security deployments
|
| 201 |
+
6. Create model ID allowlist if model selection is sensitive
|
| 202 |
+
|
| 203 |
+
**Note**: None of the above recommendations address exploitable vulnerabilities. They are hardening measures and operational improvements.
|
| 204 |
+
|
| 205 |
+
---
|
| 206 |
+
|
| 207 |
+
## Conclusion
|
| 208 |
+
|
| 209 |
+
This PR does not introduce any high-confidence security vulnerabilities that meet the established reporting criteria. The conversion from a basic chatbot to an agentic AI application follows standard patterns in the smolagents framework and inherits the security characteristics (and limitations) of autonomous AI agents generally.
|
| 210 |
+
|
| 211 |
+
The application is suitable for deployment on Hugging Face Spaces with standard OAuth authentication. Users should be aware of the inherent limitations of web-browsing AI agents, as documented by the smolagents framework.
|
| 212 |
+
|
| 213 |
+
---
|
| 214 |
+
|
| 215 |
+
## References
|
| 216 |
+
|
| 217 |
+
- [smolagents Secure Code Execution Documentation](https://huggingface.co/docs/smolagents/en/tutorials/secure_code_execution)
|
| 218 |
+
- [CVE-2025-5120 Details](https://www.cvedetails.com/cve/CVE-2025-5120/)
|
| 219 |
+
- [smolagents GitHub Repository](https://github.com/huggingface/smolagents)
|
| 220 |
+
- [NCC Group: Autonomous AI Agents Security Analysis](https://www.nccgroup.com/research-blog/autonomous-ai-agents-a-hidden-risk-in-insecure-smolagents-codeagent-usage/)
|
| 221 |
+
|
| 222 |
+
---
|
| 223 |
+
|
| 224 |
+
**Report Generated**: 2025-11-23
|
| 225 |
+
**Review Methodology**: Automated static analysis with manual false positive validation
|
| 226 |
+
**Confidence Threshold**: ≥8/10 for reportable findings
|
requirements.txt
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
ddgs
|
| 2 |
+
duckduckgo_search
|
| 3 |
+
gradio[oauth]==5.42.0
|
| 4 |
+
huggingface_hub
|
| 5 |
+
python-dotenv
|
| 6 |
+
smolagents[gradio]
|