Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ innovation-lab-examples/
|---------|-------------|------------|------------|
| [contributors/community_agent](contributors/community_agent/) | AI community growth agent for events and hackathons | Python, uAgents, ASI:One, Tavily | 🟡 Intermediate |
| [contributors/news-summarizer-agent](contributors/news-summarizer-agent/) | Fetches top headlines for a topic via NewsAPI and summarizes them with ASI:One, via Chat Protocol | Python, uAgents, NewsAPI, ASI:One | 🟡 Intermediate |
| contributors/workspace-context-provider | Hybrid AI workspace context provider that indexes local codebases and exposes them through a Streamlit RAG interface and an MCP server for IDE integration | Python, Streamlit, FastMCP, ChromaDB, Sentence Transformers, Watchdog, ASI API | 🟡 Intermediate |

### 🌐 Web3 & Blockchain

Expand Down
1 change: 1 addition & 0 deletions contributors/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ Format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
- `contributors/` folder and contribution guide for community agent examples
- `contributors/community_agent/` — moved from repository root; AI community growth agent for events and hackathons
- `contributors/news-summarizer-agent/` — beginner-friendly agent that fetches top headlines via NewsAPI and summarizes them with ASI:One; now a uAgent with Chat Protocol support
- `contributors/workspace-context-provider/` : Hybrid AI workspace context provider that indexes local codebases and exposes them through a Streamlit RAG interface and an MCP server for IDE integration
232 changes: 232 additions & 0 deletions contributors/workspace-context-provider/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,232 @@
# Autonomous Workspace Context Provider

A hybrid AI context provider that continuously indexes your local workspace and exposes it through a Streamlit web interface and an MCP server for AI-powered code understanding.

---

# 1. Overview

The **Autonomous Workspace Context Provider** is a local Retrieval-Augmented Generation (RAG) agent that monitors your workspace, embeds your source code and documentation into a persistent vector database, and provides contextual information through two interfaces:

* **Streamlit Web UI** for chatting with your codebase using the **ASI**** LLM API**
* **Model Context Protocol (MCP) Server** for integrating your local RAG pipeline with AI coding assistants such as VS Code (Cline/Roo Code), cursor, claude Desktop etc.

### Category

MCP, RAG, Tooling, Frontend

### Tech Stack

* Python
* Streamlit
* FastMCP
* ChromaDB
* Sentence Transformers
* Watchdog
* ASI API


---

# 2. Features

* 🔄 Real-time workspace indexing using **watchdog**
* 🧠 Local embeddings with **all-MiniLM-L6-v2**
* 💾 Persistent vector storage using **ChromaDB**
* 🤖 Chat with your codebase through **ASI**
* 🔌 MCP server for IDE integration
* ⚡ Automatic vector database updates whenever files change

---

# 3. Prerequisites

* Python 3.10+
* pip
* ASI API Key *(optional, required only for Streamlit chat)*

---

# 4. Installation

```bash
cd contributors/workspace-context-provider

python -m venv venv

# Windows
venv\Scripts\activate

# macOS/Linux
source venv/bin/activate

pip install -r requirements.txt
```

---

# 5. Environment Variables

Create a `.env` file.

```bash
cp .env.example .env
```

Example `.env.example`

```env
# Required only for Streamlit AI chat
ASI1_API_KEY=your_asi1_api_key_here

# Local directory to monitor and index
WORKSPACE_DIR=./target_workspace
```

### Variables

| Variable | Description |
| --------------- | ----------------------------------------------------------------- |
| `ASI1_API_KEY` | Optional. Used for ASI LLM requests in the Streamlit application. |
| `WORKSPACE_DIR` | Directory that will be monitored and indexed into ChromaDB. |

---

# 6. Run the Agent

## Streamlit Web UI

```bash
streamlit run app.py
```

The application will automatically begin monitoring the directory specified by `WORKSPACE_DIR`.

---

## MCP Server

Configure your IDE (Cline/Roo Code) by adding the following configuration to `cline_mcp_settings.json`.

```json
{
"mcpServers": {
"workspace-rag-provider": {
"command": "C:/path/to/venv/Scripts/python.exe",
"args": ["-m", "src.mcp_server"],
"cwd": "C:/path/to/contributors/workspace-context-provider",
"env": {
"WORKSPACE_DIR": "./target_workspace"
}
}
}
}
```

> **Note:** Replace the `command` and `cwd` values with the absolute paths on your machine.

---

# 7. Expected Output

After running the project:

* ✅ Workspace monitoring starts successfully
* ✅ Modified files are automatically indexed
* ✅ Embeddings are stored in ChromaDB
* ✅ Streamlit UI answers questions about your codebase
* ✅ MCP server connects successfully to your IDE
* ✅ AI assistants can retrieve relevant workspace context

---

# 8. Demo

Add screenshots or GIFs demonstrating the project.

```markdown
![Workspace Context Provider Demo](./assets/demo.png)
```

---



# 9. Architecture

```
Workspace Files
Watchdog Observer
File Change Events
Sentence Transformer Embeddings
(all-MiniLM-L6-v2 Model)
ChromaDB
(Persistent Vector Store)
▲ ▲
│ │
│ │
Streamlit UI FastMCP Server
│ │
▼ ▼
ASI:One API VS Code / Cursor / claude desktop
```

---

# 10. Troubleshooting

### Missing `ASI1_API_KEY`

If using the Streamlit chat interface, ensure the API key is present in your `.env` file.

---

### Workspace not being indexed

* Verify that `WORKSPACE_DIR` exists.
* Ensure the application has permission to access the directory.

---

### MCP server not connecting

* Check the absolute paths in `cline_mcp_settings.json`.
* Restart your IDE after updating the MCP configuration.

---

### Dependency issues

Recreate the virtual environment and reinstall dependencies.

```bash
rm -rf venv

python -m venv venv

pip install -r requirements.txt
```

---

# 12. License

This project follows the license of the parent repository unless stated otherwise.

---

# ✅ Quick Checklist Before PR

* [x] README updated using the repository template
* [x] `.env.example` added
* [ ] Demo image/GIF added under `assets/`
* [ ] Agent profile link included (if available)
* [ ] `ruff check .` passed
* [ ] `ruff format .` applied
117 changes: 117 additions & 0 deletions contributors/workspace-context-provider/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
import streamlit as st
from openai import OpenAI
import os
from dotenv import load_dotenv
from src.rag_pipeline import LocalRagEngine
from src.watcher import start_directory_watcher

# Load environment variables
load_dotenv()
ASI1_API_KEY = os.getenv("ASI1_API_KEY", "")
WORKSPACE_DIR = os.getenv("WORKSPACE_DIR", "./target_workspace")


# ==========================================
# 1. INITIALIZE RAG & WATCHER (Cached)
# ==========================================
@st.cache_resource
def init_rag_system():
"""Initializes the vector DB and background watcher only once per session."""
engine = LocalRagEngine()
# Start the background file watcher thread
start_directory_watcher(engine, WORKSPACE_DIR)
return engine


rag_engine = init_rag_system()

# ==========================================
# 2. INITIALIZE ASI:ONE API CLIENT
# ==========================================
# ASI:One uses OpenAI-compatible endpoints.
client = OpenAI(
api_key=ASI1_API_KEY,
base_url="https://api.asi1.ai/v1", # Standard ASI:One endpoint
)

# ==========================================
# 3. STREAMLIT UI SETUP
# ==========================================
st.set_page_config(page_title="Workspace Context Agent", page_icon="🤖", layout="wide")
st.title("🤖 Autonomous Workspace Agent")
st.markdown("*Powered by ASI:One & Local RAG*")

# Initialize chat history
if "messages" not in st.session_state:
st.session_state.messages = []

# Display chat history
for message in st.session_state.messages:
with st.chat_message(message["role"]):
st.markdown(message["content"])

# ==========================================
# 4. CHAT LOGIC & RAG INJECTION
# ==========================================
if prompt := st.chat_input("Ask about your codebase... (e.g., 'How does auth work?')"):
# Display user prompt
with st.chat_message("user"):
st.markdown(prompt)
st.session_state.messages.append({"role": "user", "content": prompt})

# Fetch context from our local RAG pipeline
with st.spinner("🔍 Scanning local workspace..."):
local_context = rag_engine.query_context(prompt, top_k=3)

# Construct the grounded prompt for ASI:One
system_prompt = f"""
You are an expert developer AI assistant.
Use the following retrieved local workspace context to answer the user's question accurately.
If the answer isn't in the context, say so.

LOCAL WORKSPACE CONTEXT:
{local_context}
"""

# Display assistant response
with st.chat_message("assistant"):
message_placeholder = st.empty()

if not ASI1_API_KEY:
st.error(
"⚠️ ASI1_API_KEY is missing in your .env file! Displaying retrieved raw context instead:"
)
message_placeholder.code(local_context)
st.session_state.messages.append(
{
"role": "assistant",
"content": f"**Raw Context Retrieved:**\n```\n{local_context}\n```",
}
)
else:
try:
# Call ASI:One API
stream = client.chat.completions.create(
model="asi1-mini", # Replace with specific ASI1 model if needed
messages=[
{"role": "system", "content": system_prompt},
{"role": "user", "content": prompt},
],
stream=True,
)

full_response = ""
for chunk in stream:
# SAFETY CHECK: Ensure choices list is not empty!
if chunk.choices and len(chunk.choices) > 0:
if chunk.choices[0].delta.content is not None:
full_response += chunk.choices[0].delta.content
message_placeholder.markdown(full_response + "▌")

message_placeholder.markdown(full_response)
st.session_state.messages.append(
{"role": "assistant", "content": full_response}
)

except Exception as e:
st.error(f"API Error: {e}")
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
7 changes: 7 additions & 0 deletions contributors/workspace-context-provider/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
uagents
chromadb
sentence-transformers
langchain-text-splitters
watchdog
streamlit
openai
Empty file.
Loading
Loading