Build a multi-tool NLP agent that classifies sentiment, extracts entities and keywords, summarizes content, and detects emotion. Each task runs through a focused LLM prompt, orchestrated by a small agent graph that streams per-task progress over Server-Sent Events.
Start learning at learnwithparam.com. Regional pricing available with discounts of up to 60%.
- Design a multi-task NLP agent with one focused prompt per task
- Orchestrate sequential tool calls with an optional LangGraph StateGraph
- Stream per-task progress back to the client with Server-Sent Events
- Parse structured JSON safely from flexible LLM responses
- Shape clean Pydantic response models from heterogeneous task outputs
- FastAPI - High-performance async Python web framework
- Server-Sent Events - Real-time per-task progress streaming
- LangGraph (optional) - Small StateGraph for the agent pipeline, with a plain-async fallback
- LLM Provider Pattern - OpenRouter default, plus Fireworks, Gemini, OpenAI
- Pydantic - Validation for request body and task-specific result shapes
- Docker - Containerized development
- Python 3.11+
- uv (installed automatically by
make setup) - An API key from any supported LLM provider (OpenRouter has a free tier)
# One command to set up and run
make dev
# Or step by step:
make setup # Create .env and install dependencies
# Edit .env with your API key
make run # Start the FastAPI servermake build # Build the Docker image
make up # Start the container
make logs # View logs
make down # Stop the containerOnce running, open http://localhost:8000/docs for the interactive Swagger UI.
curl -X POST http://localhost:8000/sentiment/analyze \
-H "Content-Type: application/json" \
-d '{
"text": "I absolutely love this new coffee shop! The barista was amazing.",
"tasks": ["sentiment", "entities", "summary"]
}'For streaming per-task progress:
curl -N -X POST http://localhost:8000/sentiment/analyze/stream \
-H "Content-Type: application/json" \
-d '{"text":"Great product, terrible support.","tasks":["sentiment","emotion","summary"]}'Work through these incrementally to build the full application:
- The First Verdict - Wire a single
classify_sentimentprompt end to end - The Structured Result - Make the model emit strict JSON and parse it safely
- The Task Registry - Add entity, keyword, summary, and emotion tasks behind one interface
- The Agent Graph - Sequence the task calls through a LangGraph StateGraph
- The Streaming UI - Push per-task progress events over SSE
- The Selective Caller - Let the client pick a subset of tasks per request
- The Resilient Pipeline - Keep going when one task fails, surface errors per task
- The Router Upgrade - Route long text to summary-first, short text to sentiment-first (bonus)
make help Show all available commands
make setup Initial setup (create .env, install deps)
make dev Setup and run (one command!)
make run Start FastAPI server
make build Build Docker image
make up Start container
make down Stop container
make clean Remove venv and cache
- Start the course: learnwithparam.com/courses/sentiment-classification-llms
- AI Bootcamp for Software Engineers: learnwithparam.com/ai-bootcamp
- All courses: learnwithparam.com/courses