Introduction
The AgenticPal API is a FastAPI-based backend that powers a LangGraph personal assistant agent. It provides endpoints for managing Google Calendar events, Gmail messages, and Google Tasks through natural language conversations. Current Version:v0.1.0
Architecture
The API is built with:- FastAPI - Modern, high-performance web framework
- LangGraph - Stateful agent orchestration
- Redis - Session management and conversation state persistence
- Google OAuth2 - Secure authentication
- Server-Sent Events (SSE) - Real-time streaming responses
Core Components
Chat Endpoints
Synchronous and streaming chat interfaces with the LangGraph agent
Authentication
Google OAuth2 flow with session-based credential storage
Session Management
Redis-backed sessions with HttpOnly cookies
State Persistence
LangGraph checkpoints stored in Redis for conversation continuity
Base URL
The API runs on configurable host and port:API Documentation
Interactive API documentation is available at:- Swagger UI:
/docs - ReDoc:
/redoc
Rate Limiting
The API implements per-session rate limiting using theslowapi middleware.
Rate limit for authenticated requests. Tracks by session ID if available, otherwise by IP address.
- If session cookie exists:
session:{session_id} - Otherwise: client IP address
CORS Configuration
CORS is configured to allow requests from specified origins: Default allowed origins:http://localhost:3000- Local developmenthttps://app.example.com- Production frontend (placeholder)
- Credentials: Enabled (cookies supported)
- Methods:
GET,POST,OPTIONS - Headers: All (
*)
Health Checks
The API provides health check endpoints to monitor service status.GET /health
Returns the health status of the API and its dependencies. Response:Service status:
healthy or degradedAPI version (e.g.,
0.1.0)Whether Redis connection is active
Current server timestamp (UTC)
GET /
API root endpoint returning basic information. Example Response:Redis Configuration
The API uses Redis for two purposes with separate database indexes:Database 0: Sessions
- User sessions (7-day TTL)
- OAuth credentials
- OAuth state tokens (10-minute TTL)
- Pending messages for streaming (5-minute TTL)
Database 1: LangGraph Checkpoints
- Conversation state
- Agent execution history
- Thread persistence
Environment Variables
Key configuration options:API server host
API server port
Environment mode:
development or productionRedis connection URL
Comma-separated list of allowed CORS origins
API rate limit per session/IP
Secret key for session signing (required in production)
Session expiration time (default: 7 days)
Path to Google OAuth credentials file
OAuth callback URL
Frontend application URL for post-auth redirects
Cookie domain (leave unset for localhost)
Error Handling
The API uses consistent error response format:| Code | Status | Description |
|---|---|---|
no_session | 401 | No active session cookie |
session_expired | 401 | Session has expired |
no_credentials | 401 | Not authenticated with Google |
rate_limit_exceeded | 429 | Too many requests |
agent_error | 500 | LangGraph agent execution error |
internal_error | 500 | Unexpected server error |
Next Steps
Authentication
Learn how to authenticate with Google OAuth
Chat Endpoints
Send messages and stream agent responses