How to Create a Multi-Agent System with LangGraph, CrewAI and LlamaIndex
Learn how to create a multi-agent system with LangGraph, CrewAI and LlamaIndex.


If you're building autonomous agents for data extraction, reasoning, or task automation, and you're looking to scale them intelligently β this tutorial is for you.
In this post, you'll learn how to integrate LangGraph, LlamaIndex, and CrewAI into a seamless multi-agent system that's modular, memory-aware, and built for complex workflows. This integration unlocks dynamic agent orchestration, tool usage, and semantic memory at scale. For a simpler approach without frameworks, check out our guide on building multi-agent systems from scratch.
π§ Why Multi-Agent Systems?
Multi-agent systems are AI architectures composed of independent agents that:
- Specialize in different tasks (e.g., reasoning, data extraction, summarization)
- Communicate with each other in a structured flow
- Act autonomously or cooperatively to solve complex problems
When combined with LangGraph's graph-based orchestration, LlamaIndex's semantic memory and retrieval, and CrewAI's task delegation and personas, you get a production-ready AI system that can:
β
Ingest knowledge
β
Route intelligently between agents
β
Act on structured/unstructured data
β
Generate human-like outputs
Learn more about AI Agent Web Scraping and building intelligent agents with ScrapeGraph for practical applications.
π§° Stack Overview
Tool | Role |
---|---|
LangGraph | Graph-based control flow for agents |
LlamaIndex | Long-term memory & retrieval-augmented generation |
CrewAI | Define agent roles, tasks, tools, and collaboration |
LangChain | LLM wrappers, tools, and memory integration |
ScrapeGraphAI | (Optional) Agent-powered web data pipelines |
π§ Prerequisites
bashpip install langgraph crewai llama-index langchain openai scrapegraph-py
Make sure you have an LLM set up (like OpenAI or Ollama).
1. π Create CrewAI Agents
pythonfrom crewai import Agent, Task, Crew researcher = Agent( role="Researcher", goal="Collect and summarize the latest market trends", backstory="An expert at scraping and summarizing complex data", ) analyst = Agent( role="Analyst", goal="Draw insights from summarized content", backstory="A strategic thinker who uses structured data to generate recommendations", )
2. π§ Load LlamaIndex for Context Memory
pythonfrom llama_index import VectorStoreIndex, SimpleDirectoryReader documents = SimpleDirectoryReader("data/").load_data() index = VectorStoreIndex.from_documents(documents) query_engine = index.as_query_engine()
You can plug this query engine into your agents to give them RAG capabilities.
3. πΈοΈ Design the LangGraph Flow
pythonfrom langgraph.graph import StateGraph def collect_data(state): content = researcher.run("Scrape AI trends from the web") return {**state, "content": content} def analyze_data(state): summary = query_engine.query(state["content"]) insights = analyst.run(f"Analyze the summary: {summary}") return {"output": insights} workflow = StateGraph(dict) workflow.add_node("Scrape", collect_data) workflow.add_node("Analyze", analyze_data) workflow.set_entry_point("Scrape") workflow.add_edge("Scrape", "Analyze") workflow.set_finish_point("Analyze") graph = workflow.compile() result = graph.invoke({}) print(result["output"])
β‘ Bonus: Add Dynamic Agent Routing
pythondef router(state): if "financial" in state.get("input", "").lower(): return "FinanceAgent" return "GeneralAgent" workflow.add_node("Router", router) workflow.add_node("FinanceAgent", analyze_data) workflow.add_node("GeneralAgent", collect_data) workflow.add_conditional_edges("Router", { "FinanceAgent": "Analyze", "GeneralAgent": "Scrape" })
π Real-Time Use Case: Web Data Extraction with ScrapeGraphAI
ScrapeGraphAI is the perfect pairing here β you can use it as a tool for your agents. Learn more about our JavaScript SDK and Python integration for building powerful data collection agents.
Ready to Scale Your Data Collection?
Join thousands of businesses using ScrapeGrapAI to automate their web scraping needs. Start your journey today with our powerful API.
π οΈ How to Add ScrapeGraphAI as a Tool in Your Python Agents
You can also use the official ScrapeGraphAI Python client to interact with the ScrapeGraph API directly:
pythonfrom scrapegraph_py import Client from scrapegraph_py.logger import sgai_logger # Set logging level to INFO sgai_logger.set_logging(level="INFO") # Initialize the client with your API key (keep your key secret!) sgai_client = Client(api_key="sgai-XXXX-XXXX-XXXX-XXXXXXXXXXXX") try: # Make a SmartScraper request response = sgai_client.smartscraper( website_url="https://example.com", user_prompt="Extract webpage information" ) # Print the response data print(f"Request ID: {response['request_id']}") print(f"Result: {response['result']}") # Optional: print reference URLs if available if response.get('reference_urls'): print("Reference URLs:") for url in response['reference_urls']: print(f" - {url}") finally: # Close the client session sgai_client.close()
Note: Replace
with your actual ScrapeGraphAI API key, and never expose your API key publicly.text"sgai-XXXX-XXXX-XXXX-XXXXXXXXXXXX"
π Applications
- Financial trend analysis - See our guide on Stock Analysis with AI Agents
- Research assistants - Learn about LinkedIn Lead Generation with AI agents
- Autonomous agents for scraping and summarization - Check out our AI Agent Web Scraping guide
- Business intelligence pipelines
- Scientific Q&A systems
π― SEO Takeaways
- Use LangGraph for orchestration
- Use CrewAI for multi-agent collaboration
- Use LlamaIndex for contextual memory and document search
- Use ScrapeGraphAI for autonomous data extraction
π Conclusion
By integrating LangGraph + CrewAI + LlamaIndex, you're no longer building simple chatbots β you're engineering intelligent, collaborative, task-driven agents. For more agent-related content, explore our guides on building agents without frameworks and AI Agent Web Scraping.
This is the future of AI infrastructure.
π Ready to build?
Start your agent system today at scrapegraph.ai
β or ask me below to generate a GitHub-ready template π
β Frequently Asked Questions (FAQs)
What is LangGraph used for?
LangGraph is a framework for defining stateful AI workflows as graphs. It enables complex reasoning paths, branching logic, and persistent memory flows between agents.
What is the difference between CrewAI and LangGraph?
- CrewAI manages agent definitions, tasks, and interactions.
- LangGraph handles the orchestration and flow between those agents, allowing dynamic routing and state transitions.
Using both together provides a flexible and powerful system for building AI agents that collaborate and reason over multiple steps.
How does LlamaIndex improve my agents?
LlamaIndex provides long-term memory and context-aware retrieval, allowing agents to access large corpora of documents and use relevant context in real-time. Perfect for RAG-based systems.
Can I use this for web scraping?
Yes! You can integrate ScrapeGraphAI as an agent tool or standalone service to autonomously scrape, structure, and query data from the web.
Is this production ready?
Yes β with proper error handling and LLM token/latency optimization, this stack can be used in production to power intelligent assistants, dashboards, search agents, and more.
Related Resources
Want to learn more about multi-agent systems and AI orchestration? Explore these guides:
- Web Scraping 101 - Master the basics of web scraping
- AI Agent Web Scraping - Learn about AI-powered scraping
- Mastering ScrapeGraphAI - Deep dive into our scraping platform
- Building Intelligent Agents - Create powerful AI agents
- LlamaIndex Integration) - Learn about advanced data processing
- Pre-AI to Post-AI Scraping - See how AI has transformed scraping
- Structured Output - Learn about data formatting
- Data Innovation - Discover innovative AI solutions
- Full Stack Development - Build complete AI systems