A sophisticated multi-agent system built with LangChain and LangGraph that intelligently processes news queries using an orchestrated workflow of specialized agents.
The system consists of 5 main components orchestrated via LangGraph:
User Query
β
βββββββββββββββββββββββββββββββββββββββββββ
β Orchestrator Agent β
β (LangGraph Workflow) β
βββββββββββββββββββββββββββββββββββββββββββ
β β β β
ββββββββ ββββββββ ββββββββ ββββββββ
βSearchβ β β RAG β β βAnalyzeβ β βSummaryβ
βAgent β βAgent β β Agent β β Agent β
ββββββββ ββββββββ ββββββββ ββββββββ
-
News Search Agent (
news_search_agent.py)- Searches for news using the Valyu API
- Structures results into
NewsArticleobjects - Uses tool-calling to interact with external APIs
-
RAG Agent (
rag_agent.py)- Stores news articles in ChromaDB vector store
- Retrieves relevant historical articles
- Manages embeddings and similarity search
- Persists data for long-term memory
-
Analysis Agent (
analysis_agent.py)- Analyzes both new and historical articles
- Identifies key topics and themes
- Selects most relevant articles
- Assesses sentiment and credibility
-
Summary Agent (
summary_agent.py)- Generates comprehensive summaries
- Structures output with markdown
- Provides context and implications
- Creates both detailed and brief summaries
-
Orchestrator Agent (
orchestrator.py)- Coordinates all agents using LangGraph
- Manages state flow between agents
- Handles errors gracefully
- Provides workflow visualization
- Python 3.10+
- OpenAI API key (for LLM and embeddings)
- Valyu API key (for news search)
- Clone the repository and navigate to the project:
cd lock_in_hack- Create and activate a virtual environment:
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate- Install dependencies:
pip install -r requirements.txt- Set up environment variables:
cp .env.example .env
# Edit .env with your API keysRequired environment variables:
OPENAI_API_KEY=sk-...
VALYU_API_KEY=...
Run the default example:
python run_agent.pyEdit run_agent.py to add your own queries:
queries = [
"What are the latest developments in AI?",
"Tell me about recent climate change news",
]from agents.orchestrator import build_agent
# Initialize the orchestrator
orchestrator = build_agent()
# Process a query
result = orchestrator.process_query("What's happening with cryptocurrency?")
# Access results
print(result["summary"])
print(result["analysis"])# Get RAG statistics
stats = orchestrator.get_rag_stats()
print(f"Total articles stored: {stats['total_documents']}")
# Direct RAG access
from agents.rag_agent import RAGAgent
rag = RAGAgent()
articles = rag.retrieve_articles("AI news", k=5)lock_in_hack/
βββ agents/
β βββ __init__.py
β βββ news_search_agent.py # News search functionality
β βββ rag_agent.py # Vector store management
β βββ analysis_agent.py # Article analysis
β βββ summary_agent.py # Summary generation
β βββ orchestrator.py # LangGraph orchestration
βββ models/
β βββ __init__.py
β βββ schemas.py # Pydantic data models
βββ tools/
β βββ agent_tools.py # LangChain tools (Valyu search)
βββ config/
β βββ llm_setup.py # LLM configuration
β βββ BedrockProxyLLM.py # Custom Bedrock LLM
βββ utils/
β βββ __init__.py
β βββ logger.py # Logging configuration
βββ storage/
β βββ chroma_db/ # Vector store persistence
βββ .env.example # Environment template
βββ requirements.txt # Python dependencies
βββ run_agent.py # Main entry point
βββ README.md # This file
-
Modular Architecture
- Separation of concerns
- Each agent has a single responsibility
- Easy to extend and modify
-
Type Safety
- Pydantic models for data validation
- Type hints throughout
- Runtime validation
-
Error Handling
- Graceful degradation
- Comprehensive logging
- Error tracking in state
-
State Management
- Centralized
AgentStatemodel - Immutable state transitions
- Full audit trail
- Centralized
-
Configuration Management
- Environment-based configuration
- Multiple LLM provider support
- Flexible deployment options
-
Persistent Storage
- ChromaDB for vector storage
- Automatic persistence
- Efficient similarity search
-
LangGraph Orchestration
- Clear workflow definition
- Easy to visualize
- Deterministic execution
The system supports multiple LLM providers:
OpenAI (default):
from config.llm_setup import get_llm_openai
llm = get_llm_openai()OpenRouter (for Claude):
from config.llm_setup import get_llm_openrouter
llm = get_llm_openrouter()AWS Bedrock:
from config.BedrockProxyLLM import BedrockProxyLLM
llm = BedrockProxyLLM()Change the vector store by modifying RAGAgent:
# Use FAISS instead of ChromaDB
from langchain_community.vectorstores import FAISS
# In rag_agent.py, replace Chroma with FAISSclass NewsArticle(BaseModel):
title: str
url: str
content: str
source: str = "valyu"
timestamp: datetime
query: Optional[str]
relevance_score: Optional[float]class AgentState(BaseModel):
user_query: str
search_results: List[NewsArticle]
rag_results: List[NewsArticle]
analysis: Optional[str]
summary: Optional[str]
next_agent: Optional[str]
completed_agents: List[str]
metadata: Dict[str, Any]- Add caching for LLM responses
- Implement streaming for real-time results
- Add web UI with Streamlit/Gradio
- Support for more news sources
- Multi-language support
- Performance metrics dashboard
- LangChain for the agent framework
- LangGraph for orchestration
- Valyu for news search API
- OpenAI for LLM capabilities