A FastAPI-powered backend with LangChain AI agents for intelligent task management.
Built with LangGraph, Groq LLM, and streaming responses via Server-Sent Events (SSE).
Frontend Repository: AI-Assistant-Task-Manager-Frontend
- π€ AI-powered task management using LangChain agents
- π οΈ 5 core tools: Add, List, Complete, Edit, Delete tasks
- β‘ Real-time streaming responses via SSE
- π§΅ Thread-based memory for conversation context
- π― Multi-agent architecture with tool orchestration
- π Natural language processing - users interact conversationally
- π FastAPI for high-performance async endpoints
- Python 3.9+
- uv package manager (Install uv)
- Groq API Key (Get one here)
# macOS and Linux
curl -LsSf https://astral.sh/uv/install.sh | sh
# Windows
powershell -c "irm https://astral.sh/uv/install.ps1 | iex"# Clone repository
git clone https://github.com/babs12316/AI-Assistant-Task-Manager-Backend.git
cd AI-Assistant-Task-Manager-Backend
# Install dependencies
uv sync
# Create .env file
echo "GROQ_API_KEY=your_groq_api_key_here" > .env- Visit Groq Console
- Sign up or log in
- Generate a new API key
- Add it to your
.envfile
uv run uvicorn src.api:app --reloadServer will run at: http://localhost:8000
curl http://localhost:8000/healthResponse:
{"status": "healthy"}Stream AI agent responses using Server-Sent Events.
Request:
curl -X POST http://localhost:8000/chat \
-H "Content-Type: application/json" \
-d '{
"message": "Add gym at 6pm today",
"thread_id": "user-123"
}'Response (SSE Stream):
data: β
Added **Gym** [9a8cca01] for today at **6 PM**.
data:
data: Anything else you'd like to add?
data: [DONE]
Request Body:
{
"message": "string", // User's natural language input (required)
"thread_id": "string" // Unique conversation thread ID (required)
}Thread ID:
- Use the same
thread_idto maintain conversation context - Each user should have a unique thread ID
- Example:
"user-123","session-abc-456", etc.
The AI agent has access to these tools:
Add a new task to the list.
Example:
- User:
"Add gym at 6pm today" - Agent:
add_task("Gym", "today", "18:00") - Response:
"β Added 'Gym' [abc123] for today at 6 PM"
List tasks for a specific day or all tasks.
Example:
- User:
"Show me today's tasks" - Agent:
list_tasks("today") - Response: Task list with IDs
Mark a task as completed.
Example:
- User:
"Complete gym" - Agent: Finds task ID β
complete_task("abc123") - Response:
"π Awesome! Marked 'Gym' as complete!"
Edit an existing task.
Example:
- User:
"Change gym to 7pm" - Agent:
edit_task("abc123", updated_due_time="19:00") - Response:
"β Updated 'Gym': time β 19:00"
Delete a task.
Example:
- User:
"Delete gym" - Agent:
delete_task("abc123") - Response:
"ποΈ Deleted: Gym"
User: "Add gym at 6pm and show my tasks"
β
Agent analyzes intent
β
Step 1: Calls add_task("Gym", "today", "18:00")
β
Step 2: Calls list_tasks("today")
β
Streams response back to user via SSE
β
User sees: "β
Added Gym. π Tasks: [abc123] Gym @ 6 PM"
User: "Complete gym"
β
Agent: "I need to find the gym task ID first"
β
Agent: Calls list_tasks() β Finds [abc123] Gym
β
Agent: Calls complete_task("abc123")
β
Agent: "β
Nice work! 'Gym' is done!"
| User Input | Agent Actions |
|---|---|
Add gym at 6pm |
add_task("Gym", "today", "18:00") |
Show my tasks |
list_tasks() |
What's on my plate today? |
list_tasks("today") |
Complete gym |
list_tasks() β complete_task("abc123") |
Change lunch to 2pm |
list_tasks() β edit_task(...) |
Delete the gym task |
list_tasks() β delete_task("abc123") |
Add gym and call mom, then list |
Multiple tool calls in sequence |
curl -X POST http://localhost:8000/chat \
-H "Content-Type: application/json" \
-d '{"message": "Add gym at 6pm", "thread_id": "user-123"}'Response:
data: β
Added **Gym** [9a8cca01] for today at **6 PM**.
data:
data: Anything else you'd like to add?
data: [DONE]
curl -X POST http://localhost:8000/chat \
-H "Content-Type: application/json" \
-d '{"message": "Show my tasks", "thread_id": "user-123"}'Response:
data: π Tasks (2):
data:
data: [9a8cca01] β Gym @ 6 PM
data: [f3b2c456] β Call Mom @ 3 PM
data:
data: You have 2 tasks pending.
data: [DONE]
curl -X POST http://localhost:8000/chat \
-H "Content-Type: application/json" \
-d '{"message": "Complete gym", "thread_id": "user-123"}'Response:
data: π Awesome! Marked 'Gym' as complete!
data: [DONE]
AI-Assistant-Task-Manager-Backend/
βββ src/
β βββ agent.py # LangChain agent + tools
β βββ api.py # FastAPI routes
β βββ api/
β βββ health.py # Health check endpoint
βββ tests/
β βββ test_agent.py # Unit tests
βββ .env # Environment variables (create this)
βββ pyproject.toml # Project dependencies
βββ uv.lock # Locked dependencies
βββ README.md # This file
- FastAPI - Modern, fast web framework
- LangChain - AI agent orchestration framework
- LangGraph - Agent workflow management
- Groq - Ultra-fast LLM inference (model:
openai/gpt-oss-120b) - Pydantic - Data validation
- Server-Sent Events (SSE) - Real-time streaming
- uvicorn - ASGI server
- uv - Fast Python package manager
Edit src/api.py to add allowed origins:
app.add_middleware(
CORSMiddleware,
allow_origins=[
"http://localhost:5173", # Vite dev server
"https://tasky22.vercel.app", # Production frontend
"https://your-domain.com" # Your domain
],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)Edit src/agent.py:
# Current model
llm = ChatGroq(model="openai/gpt-oss-120b")
# Other Groq models
llm = ChatGroq(model="llama-3.1-70b-versatile")
llm = ChatGroq(model="mixtral-8x7b-32768")Once the server is running, visit:
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
- Frontend Repository: AI-Assistant-Task-Manager-Frontend
β If you like this project, give it a star on GitHub!