timhuang1018/google-home-api-agent
If you are the rightful owner of google-home-api-agent and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.
The Google Home API Agent is a Retrieval-Augmented Generation (RAG) powered agent designed to facilitate querying of the Google Home Android API documentation.
Google Home API Agent
A RAG (Retrieval-Augmented Generation) powered agent for querying Google Home Android API documentation.
Overview
This project provides an intelligent agent that can answer questions about the Google Home Android API by:
- Crawling official documentation from developers.home.google.com
- Processing and chunking documentation into semantic sections
- Building a hybrid search index (vector embeddings + BM25)
- Using LLMs to provide accurate, context-aware answers
- NEW: MCP server with context-aware output modes (question vs integration)
Project Structure
google-home-api-agent/
āāā data/
ā āāā home-api/
ā āāā android/
ā āāā *.md # Raw crawled markdown files
ā āāā processed/ # Processed chunks and metadata
ā ā āāā chunks.jsonl
ā ā āāā code_examples.jsonl
ā ā āāā metadata.json
ā āāā index/ # Search indices
ā āāā chroma/ # Vector embeddings
ā āāā bm25_index.pkl # Keyword search index
ā āāā chunk_mapping.json # Chunk ID mappings
āāā scripts/
ā āāā google-home-android-api.py # Documentation crawler
ā āāā process_docs.py # Document processor
ā āāā build_index.py # Index builder
āāā google_home_rag/
ā āāā __init__.py
ā āāā agent.py # RAG agent implementation
ā āāā retriever.py # Hybrid retriever
āāā tests/
ā āāā rag_tests/
ā āāā evaluation_framework.py # Evaluation tools
ā āāā run_evaluation.py # Test runner
ā āāā profile_performance.py # Performance profiling
āāā google_home_mcp_server.py # MCP server implementation
āāā run_mcp_server.py # MCP server startup script
āāā MCP_SERVER.md # MCP server documentation
āāā pyproject.toml
āāā .env.example
āāā README.md
Setup
1. Prerequisites
- Python 3.10 or higher
- uv (recommended) or pip
2. Installation
Using uv (recommended):
cd /Users/tim/PycharmProjects/google-home-api-agent
# Create virtual environment and install dependencies
uv venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
uv pip install -e .
Using pip:
cd /Users/tim/PycharmProjects/google-home-api-agent
# Create virtual environment
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
# Install dependencies
pip install -e .
3. Configuration
Copy the example environment file and add your API keys:
cp .env.example .env
Edit .env
and add your OpenAI API key:
OPENAI_API_KEY=your-actual-api-key-here
Usage
MCP Server (Recommended for AI Assistants)
NEW: Use the MCP server for seamless integration with Claude Desktop, Cline, and other MCP clients:
# Start the MCP server
python run_mcp_server.py
The MCP server provides:
ask_question
- Get lean code snippets without imports (for learning)get_code_integration
- Get complete code with imports (for implementation)search_documentation
- Browse documentation sections
š
Crawling Documentation
To update or re-crawl the documentation:
python scripts/google-home-android-api.py
This will:
- Crawl all configured pages from developers.home.google.com
- Save markdown files to
data/home-api/android/
Processing Documents
Process the raw markdown into structured chunks:
python scripts/process_docs.py
This will:
- Parse markdown files
- Extract code blocks and metadata
- Chunk documents by sections
- Save processed data to
data/home-api/android/processed/
Building the Index
Build the hybrid search index:
python scripts/build_index.py
This will:
- Create vector embeddings using ChromaDB
- Build BM25 keyword index
- Save indices to
data/home-api/android/index/
Using the RAG Agent
from pathlib import Path
from google_home_rag import RAGAgent
# Initialize the agent
index_dir = Path("data/home-api/android/index")
agent = RAGAgent(index_dir=index_dir, model="gpt-4o-mini")
# Ask a question
question = "How do I commission a device using the Android API?"
answer = agent.answer(question, top_k=5)
print(answer)
Running Evaluations
To evaluate the RAG system performance:
cd tests/rag_tests
python run_evaluation.py
Performance Profiling
To profile the RAG system:
cd tests/rag_tests
python profile_performance.py
Documentation Coverage
The agent currently covers:
Get Started
- SDK setup and OAuth
- Initialization and permissions
API Guides
- Overview and data model
- Connectivity and interoperability
- Error handling
Commissioning API
- Device commissioning
- Multi-admin support
Structure API
- Home structure management
Device API
- Device control and monitoring
- Supported device types and traits
- Manufacturer-specific traits
Automation API
- Automation design and building
- DSL (Domain Specific Language)
- Basic patterns
- Complex patterns
- Recurring starters
- Supported traits and simplified traits
- Blocked actions
- Discovery and examples
Testing
- Test guidelines
Development
Adding New Documentation Pages
Edit scripts/google-home-android-api.py
and add URLs to the PAGES_TO_CRAWL
list:
PAGES_TO_CRAWL = [
"/apis/android/your-new-page",
# ...
]
Then re-run the crawler, processor, and index builder.
Customizing the RAG Agent
The RAG agent can be customized in google_home_rag/agent.py
:
- Adjust retrieval parameters (top_k, reranking)
- Modify prompt templates
- Change LLM models
- Add custom filters
Testing
Add test cases to tests/rag_tests/test_cases/
:
[
{
"question": "Your question here",
"expected_keywords": ["keyword1", "keyword2"],
"category": "category_name"
}
]
Dependencies
Core dependencies:
- crawl4ai: Web crawling and content extraction
- chromadb: Vector database for embeddings
- sentence-transformers: Embedding generation
- rank-bm25: Keyword-based search
- openai: LLM interface
- litellm: Multi-provider LLM support
Troubleshooting
ChromaDB Issues
If you encounter ChromaDB errors:
# Clear the index and rebuild
rm -rf data/home-api/android/index/chroma
python scripts/build_index.py
Import Errors
Make sure the project is installed in editable mode:
uv pip install -e .
# or
pip install -e .
API Key Issues
Verify your .env
file is in the project root and contains:
OPENAI_API_KEY=sk-...
License
This project is for educational and research purposes. Please refer to Google's terms of service for their API documentation.
Contributing
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch
- Make your changes
- Submit a pull request
Support
For issues or questions, please open an issue on the project repository.