A LangGraph-based AI agent that analyzes text documents by classifying them, extracting entities, and generating summaries.
This project is based on the tutorial "Your First AI Agent: Simpler Than You Think" by Nir Diamant.
Original Tutorial Resources:
- Tutorial Repository: agents-towards-production (8K+ ⭐)
- Author: Nir Diamant
- Tutorial Date: February 2025
This project is based on the tutorial "Your First AI Agent: Simpler Than You Think" by Nir Diamant.
Learning Approach:
- Following tutorial with AI-assisted implementation (Claude)
- Focus: Understanding agent architecture, LangGraph workflows, and LLM integration
- Status: Learning project demonstrating AI agent fundamentals
Original Tutorial Resources:
- Tutorial Repository: agents-towards-production (8K+ ⭐)
- Author: Nir Diamant
Technical Updates Made:
- Updated imports for current LangChain version (
langchain_core) - Adapted setup for macOS development environment
- Added comprehensive documentation
This agent demonstrates core AI agent concepts including:
- State management - Maintains context throughout analysis
- Modular capabilities - Three specialized analysis nodes
- Graph-based workflow - Coordinated processing pipeline
- LLM integration - OpenAI GPT-4o-mini for intelligent processing
Input Text → Classification → Entity Extraction → Summarization → Results
The agent processes text through three sequential nodes:
- Classification Node: Categorizes text (News, Blog, Research, Other)
- Entity Extraction Node: Identifies people, organizations, locations
- Summarization Node: Creates concise one-sentence summary
- Python 3.8+
- OpenAI API key (Get one here)
- Clone the repository
git clone https://github.com/YOUR_USERNAME/ai-text-analysis-agent.git
cd ai-text-analysis-agent- Create virtual environment
python3 -m venv agent_env
source agent_env/bin/activate # On Windows: agent_env\Scripts\activate- Install dependencies
pip install -r requirements.txt- Set up environment variables
cp .env.example .env
# Edit .env and add your OpenAI API key- Run the agent
python text_analysis_agent.pylanggraph- Graph-based agent workflow frameworklangchain- LLM orchestrationlangchain-openai- OpenAI integrationpython-dotenv- Environment variable management
sample_text = """
OpenAI has announced the GPT-4 model, which exhibits
human-level performance on various professional benchmarks...
"""
state_input = {"text": sample_text}
result = app.invoke(state_input)
print("Classification:", result["classification"])
print("Entities:", result["entities"])
print("Summary:", result["summary"])Output:
Classification: News
Entities: ['OpenAI', 'GPT-4', 'GPT-3']
Summary: OpenAI's upcoming GPT-4 model is a multimodal AI
that aims for human-level performance...
Uses TypedDict to maintain structured state across nodes:
text: Original input textclassification: Document categoryentities: Extracted named entitiessummary: Generated summary
Each node is a pure function that:
- Receives current state
- Processes using LLM with specific prompt
- Returns updated state dict
LangGraph StateGraph coordinates execution:
- Sequential edge connections
- Automatic state merging
- Deterministic execution (temperature=0)
- Model: GPT-4o-mini
- Average latency: ~3-5 seconds per analysis
- Cost: ~$0.003-$0.005 per analysis
- Add sentiment analysis node
- Implement conditional routing based on classification
- Add web search capability for fact-checking
- Support batch processing
- Add conversational memory
- Create REST API endpoint
- Deploy as web service
Contributions welcome! Please feel free to submit a Pull Request.
MIT License - See LICENSE file for details.
Adaugo Akaluso
- AI/Systems & Automation Designer
- GitHub: @adaakal
- LinkedIn: https://www.linkedin.com/in/adaugo-akaluso
- Built with LangGraph by LangChain
- Original tutorial by Nir Diamant
- Tutorial: "Your First AI Agent: Simpler Than You Think"
- OpenAI for GPT-4o-mini API
Learning AI Agent Development? Check out the original tutorial and Nir's repository with 25+ agent tutorials.