Skip to content
Draft
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
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,17 @@ venv.bak/

# VSCode
.vscode/

# Xcode
ios/**/xcuserdata/
ios/**/DerivedData/
ios/**/*.xcworkspace/xcuserdata/
ios/**/*.xcodeproj/project.xcworkspace/xcuserdata/
ios/**/*.xcodeproj/xcuserdata/
ios/**/build/
*.ipa
*.dSYM.zip
*.dSYM
ml_agent/__pycache__/__init__.cpython-313.pyc
uv.lock
ml_agent/__pycache__/__init__.cpython-313.pyc
Expand Down
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ web: ## Run the ADK web demo server
api_server: ## Run the ADK FastAPI server
@uv run adk api_server src/agents/

.PHONY: mobile-api
mobile-api: ## Run the Home Security Mobile API server
@echo "🚀 Starting Home Security Mobile API server..."
@PYTHONPATH=$(ROOT_DIR) uv run uvicorn src.mobile_api.app:app --host 0.0.0.0 --port 8000 --reload

.PHONY: home-security-web
home-security-web: ## Run the Home Security Agent via ADK web interface
@uv run adk web --reload src/agents/home_security_agent/

.PHONY: prefect-server
prefect-server: ## Start Prefect server and serve flows
@./scripts/start_prefect.sh
Expand Down
180 changes: 157 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,61 +14,195 @@ echo 'OLLAMA_API_BASE="http://localhost:11434"' > .env
# Run agents via web interface
make web

# Run Home Security Mobile API
make mobile-api

# Run Prefect workflows
make prefect-server
```

## Components

### Agents
- **`doc_agent`**: Technical writing assistant with Google Docs integration
- Uses local Ollama models (`gpt-oss:20b`) via LiteLLM
- Includes Google Docs tools for creating and formatting documents

#### Home Security Agent (NEW)
An AI-powered home security monitoring agent that manages smart locks, cameras, and sensors. Uses **Gemma 2 9B** by default via local Ollama.

**Features:**
- **Smart Lock Management**: View status, lock/unlock doors remotely
- **Camera Monitoring**: View camera status, capture snapshots, review motion events
- **Sensor Monitoring**: Track motion, door/window, smoke, and water leak sensors
- **Security System Control**: Arm/disarm with multiple modes (away, home, night)
- **AI Chat Interface**: Natural language interaction for security queries
- **Quick Actions**: Pre-built routines for common scenarios (goodnight, leaving, arriving)
- **Push Notifications**: Register devices for real-time security alerts

**Run the Mobile API:**
```bash
make mobile-api
# API available at http://localhost:8000
# Swagger docs at http://localhost:8000/docs
```

**Example API Calls:**
```bash
# Get home security summary
curl http://localhost:8000/api/summary

# Get all locks status
curl http://localhost:8000/api/locks

# Lock a specific door
curl -X POST http://localhost:8000/api/locks/front_door/lock

# Chat with the AI assistant
curl -X POST http://localhost:8000/api/chat \
-H "Content-Type: application/json" \
-d '{"message": "What is going on at home?"}'

# Execute goodnight routine (lock all doors + arm in night mode)
curl -X POST http://localhost:8000/api/quick-actions/goodnight
```

#### Doc Agent
Technical writing assistant with Google Docs integration.
- Uses local Ollama models (`gpt-oss:20b`) via LiteLLM
- Includes Google Docs tools for creating and formatting documents

### Workflows
- **`pipeline.py`**: Prefect workflow for orchestrating document creation and content generation
- **`serve.py`**: Entry point for serving Prefect flows

### Tools
- **Google Docs Tool** (`doc_agent/tools/google_docs_tool.py`):
- Create new Google Docs
- Write plain text or markdown content
- Convert markdown to formatted Google Docs (headings, lists, bold/italic, links, code blocks, blockquotes, etc.)
### Mobile API
A FastAPI-based REST API designed for iOS/Android mobile app consumption.

**Endpoints:**
| Endpoint | Method | Description |
|----------|--------|-------------|
| `/api/summary` | GET | Home security dashboard summary |
| `/api/locks` | GET | All locks status |
| `/api/locks/{id}/lock` | POST | Lock a specific door |
| `/api/locks/{id}/unlock` | POST | Unlock a door (requires confirmation) |
| `/api/locks/lock-all` | POST | Lock all doors |
| `/api/cameras` | GET | All cameras status |
| `/api/cameras/{id}/snapshot` | POST | Capture camera snapshot |
| `/api/cameras/motion-events` | GET | Recent motion detection events |
| `/api/sensors` | GET | All sensors status |
| `/api/security-system` | GET | Security system status |
| `/api/security-system/arm` | POST | Arm security system |
| `/api/security-system/disarm` | POST | Disarm security system |
| `/api/activity` | GET | Recent activity log |
| `/api/chat` | POST | AI assistant chat |
| `/api/quick-actions/goodnight` | POST | Execute goodnight routine |
| `/api/quick-actions/leaving` | POST | Execute leaving home routine |
| `/api/quick-actions/arriving` | POST | Execute arriving home routine |

## Prerequisites

- Python 3.13+
- Ollama installed and running
- Google OAuth credentials (`credentials.json`) for Google Docs API
- Python 3.10+
- Ollama installed and running (for AI agents)
- Google OAuth credentials (`credentials.json`) for Google Docs API (optional)

## Commands

```bash
make web # Run ADK web interface
make api_server # Run ADK FastAPI server
make prefect-server # Start Prefect server and serve flows
make prefect-flows # Serve flows (server must be running)
make test # Run tests
make check # Lint and type check
make web # Run ADK web interface (all agents)
make mobile-api # Run Home Security Mobile API server
make home-security-web # Run Home Security Agent via ADK web
make api_server # Run ADK FastAPI server
make prefect-server # Start Prefect server and serve flows
make test # Run tests
make check # Lint and type check
make clean # Remove build artifacts and cache
```

## Project Structure

```
src/
├── agents/
│ └── doc_agent/ # Technical writing assistant
│ ├── agent.py # Agent definition
│ ├── doc_agent/ # Technical writing assistant
│ │ ├── agent.py # Agent definition
│ │ └── tools/
│ │ └── google_docs_tool.py
│ └── home_security_agent/ # Home security monitoring agent
│ ├── __init__.py
│ ├── agent.py # Agent definition with tools
│ └── tools/
│ └── google_docs_tool.py # Google Docs integration
│ ├── __init__.py
│ └── device_tools.py # Smart device integration
├── mobile_api/ # REST API for mobile apps
│ ├── __init__.py
│ ├── app.py # FastAPI application
│ ├── models.py # Pydantic models
│ └── server.py # Server entry point
└── workflows/
├── pipeline.py # Main Prefect workflow
├── serve.py # Flow serving entry point
└── discover.py # Flow discovery utility
├── pipeline.py # Main Prefect workflow
├── serve.py # Flow serving entry point
└── discover.py # Flow discovery utility
tests/
├── test_home_security_agent.py # Agent tool tests
└── test_mobile_api.py # API endpoint tests
```

## iOS App

A complete SwiftUI iOS app is included in the `ios/` directory.

### Features
- **Dashboard**: Security score gauge, quick actions, status overview
- **Locks**: View/control all smart locks with battery indicators
- **Cameras**: Camera grid with motion detection events
- **AI Chat**: Natural language assistant for security queries
- **Settings**: Server config, arm/disarm, notifications, activity log

### Quick Start

```bash
# 1. Start the backend
make mobile-api

# 2. Open in Xcode
open ios/HomeSecurityApp/HomeSecurityApp.xcodeproj

# 3. Build and run (⌘R)
```

### Requirements
- iOS 17.0+
- Xcode 15.0+

See [ios/README.md](ios/README.md) for detailed setup instructions.

## Configuration

- **Ollama**: Set `OLLAMA_API_BASE` in `.env` or environment
- **Home Security Model**: Set `HOME_SECURITY_MODEL` to override the default Gemma model
- Default: `ollama_chat/gemma2:9b` (local Ollama)
- Options: `ollama_chat/gemma2:27b`, `ollama_chat/gemma:7b`, `gemini/gemma-2-9b-it`
- **Google Docs**: Place `credentials.json` in project root (token.json auto-generated)
- **Prefect UI**: Available at `http://127.0.0.1:4200` (or port specified by `PREFECT_PORT`)
- **Mobile API**: Default port 8000, configurable via uvicorn options

### Setting up Gemma with Ollama

```bash
# Install Ollama (if not already installed)
curl -fsSL https://ollama.com/install.sh | sh

# Pull Gemma 2 9B model
ollama pull gemma2:9b

# Or for the larger 27B model (requires more RAM)
ollama pull gemma2:27b

# Start Ollama server
ollama serve
```

## Security Notes

- In production, add authentication (JWT/OAuth2) to the Mobile API
- Use HTTPS for all API communications
- Store sensitive credentials in environment variables
- The current implementation uses simulated device data for demonstration
Loading