Skip to content

Adaakal/ai-text-analysis-agent

Repository files navigation

AI Text Analysis Agent

Python LangGraph License

A LangGraph-based AI agent that analyzes text documents by classifying them, extracting entities, and generating summaries.

📚 Attribution

This project is based on the tutorial "Your First AI Agent: Simpler Than You Think" by Nir Diamant.

Original Tutorial Resources:

📚 Attribution & Learning Journey

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:

Technical Updates Made:

  • Updated imports for current LangChain version (langchain_core)
  • Adapted setup for macOS development environment
  • Added comprehensive documentation

🎯 Overview

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

🏗️ Architecture

Input Text → Classification → Entity Extraction → Summarization → Results

The agent processes text through three sequential nodes:

  1. Classification Node: Categorizes text (News, Blog, Research, Other)
  2. Entity Extraction Node: Identifies people, organizations, locations
  3. Summarization Node: Creates concise one-sentence summary

🚀 Quick Start

Prerequisites

Installation

  1. Clone the repository
git clone https://github.com/YOUR_USERNAME/ai-text-analysis-agent.git
cd ai-text-analysis-agent
  1. Create virtual environment
python3 -m venv agent_env
source agent_env/bin/activate  # On Windows: agent_env\Scripts\activate
  1. Install dependencies
pip install -r requirements.txt
  1. Set up environment variables
cp .env.example .env
# Edit .env and add your OpenAI API key
  1. Run the agent
python text_analysis_agent.py

📦 Dependencies

  • langgraph - Graph-based agent workflow framework
  • langchain - LLM orchestration
  • langchain-openai - OpenAI integration
  • python-dotenv - Environment variable management

💡 Usage Example

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...

🛠️ Technical Implementation

State Management

Uses TypedDict to maintain structured state across nodes:

  • text: Original input text
  • classification: Document category
  • entities: Extracted named entities
  • summary: Generated summary

Node Functions

Each node is a pure function that:

  • Receives current state
  • Processes using LLM with specific prompt
  • Returns updated state dict

Graph Workflow

LangGraph StateGraph coordinates execution:

  • Sequential edge connections
  • Automatic state merging
  • Deterministic execution (temperature=0)

📊 Performance

  • Model: GPT-4o-mini
  • Average latency: ~3-5 seconds per analysis
  • Cost: ~$0.003-$0.005 per analysis

🔮 Roadmap

  • 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

🤝 Contributing

Contributions welcome! Please feel free to submit a Pull Request.

📄 License

MIT License - See LICENSE file for details.

👤 Author

Adaugo Akaluso

🙏 Acknowledgments


Learning AI Agent Development? Check out the original tutorial and Nir's repository with 25+ agent tutorials.


About

LangGraph-based AI agent for text analysis. Learning project - tutorial implementation with proper attribution.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages