LangChain Agent

Learn how to use LangChain tools and utilities with PraisonAI agents.

python
from praisonaiagents import Agent
from langchain_community.tools import WikipediaQueryRun

agent = Agent(
    name="LangChain Agent",
    instructions="Answer using LangChain community tools.",
    tools=[WikipediaQueryRun()],
)
agent.start("Give a short overview of reinforcement learning from Wikipedia")

The user requests external knowledge; the agent queries LangChain tools and returns a summary.

Diagram

Input

Agent

Tool

Output

Diagram
LangChain AgentAgentUserLangChain AgentAgentUserRequestProcess requestResultResponse

Quick Start

Code

  1. Install Package

    First, install the required packages:

    bash
    pip install praisonaiagents langchain-community wikipedia youtube-search
  2. Set API Key

    Set your OpenAI API key as an environment variable in your terminal:

    bash
    export OPENAI_API_KEY=your_api_key_here
  3. Create a file

    Create a new file app.py with the basic setup:

    Single Tool
    from praisonaiagents import Agent
    from langchain_community.utilities import WikipediaAPIWrapper
    
    wiki_agent = Agent(
        instructions="You are a wikipedia research Agent",
        tools=[WikipediaAPIWrapper]
    )
    
    wiki_agent.start("Research 'Artificial Intelligence' on Wikipedia")
    Multiple Tools
    from praisonaiagents import Agent, AgentTeam
    from langchain_community.utilities import WikipediaAPIWrapper
    from langchain_community.tools import YouTubeSearchTool
    
    youtube_agent = Agent(
        instructions="Search for information about 'AI advancements' on YouTube",
        tools=[YouTubeSearchTool]
    )
    
    wiki_agent = Agent(
        instructions="Research 'Artificial Intelligence' on Wikipedia",
        tools=[WikipediaAPIWrapper]
    )
    
    agents = AgentTeam(agents=[youtube_agent, wiki_agent])
    agents.start()
  4. Start Agents

    Type this in your terminal to run your agents:

    bash
    python app.py

No Code

  1. Install Package

    (Upcoming Feature) Install the PraisonAI package:

    bash
    pip install "praisonai"
  2. Set API Key

    Set your OpenAI API key as an environment variable in your terminal:

    bash
    export OPENAI_API_KEY=your_api_key_here
  3. Create a file

    Create a new file agents.yaml with the basic setup:

    yaml
    framework: praisonai
    process: sequential
    agents:  # Canonical: use 'agents' instead of 'roles'
      researcher:
        name: SearchAgent
        role: Research Assistant
        goal: Search for information from multiple sources
        instructions:  # Canonical: use 'instructions' instead of 'backstory' I am an AI assistant that can search YouTube and Wikipedia.
        tools:
          - youtube_search
          - wikipedia
        tasks:
          search_task:
            name: search_task
            description: Search for information about 'AI advancements' on both YouTube and Wikipedia
            expected_output: Combined information from YouTube videos and Wikipedia articles
  4. Start Agents

    Type this in your terminal to run your agents:

    bash
    praisonai agents.yaml

Understanding LangChain Integration

What is LangChain Integration?

LangChain integration enables agents to: – Use LangChain’s extensive tool ecosystem – Access various data sources and APIs – Leverage pre-built utilities and wrappers – Combine multiple tools in a single agent – Extend agent capabilities with community tools

Features

LangChain Tools with Wrappers

Example Wrapper Usage

bash
pip install langchain-community google-search-results
export SERPAPI_API_KEY=your_api_key_here
export OPENAI_API_KEY=your_api_key_here
python
from praisonaiagents import Agent, AgentTeam
from langchain_community.utilities import SerpAPIWrapper

data_agent = Agent(instructions="Search about AI job trends in 2025", tools=[SerpAPIWrapper])
editor_agent = Agent(instructions="Write a blog article")

agents = AgentTeam(agents=[data_agent, editor_agent])
agents.start()

Example without Wrapper Usage

bash
pip install langchain-community 
export BRAVE_SEARCH_API=your_api_key_here
export OPENAI_API_KEY=your_api_key_here
python
from praisonaiagents import Agent, AgentTeam
from langchain_community.tools import BraveSearch
import os

def search_brave(query: str):
    """Searches using BraveSearch and returns results."""
    api_key = os.environ['BRAVE_SEARCH_API']
    tool = BraveSearch.from_api_key(api_key=api_key, search_kwargs={"count": 3})
    return tool.run(query)

data_agent = Agent(instructions="Search about AI job trends in 2025", tools=[search_brave])
editor_agent = Agent(instructions="Write a blog article")
agents = AgentTeam(agents=[data_agent, editor_agent])
agents.start()

Next Steps

With More Detailed Instructions

Code

  1. Install Package

    First, install the required packages:

    bash
    pip install praisonaiagents langchain-community wikipedia
  2. Set API Key

    Set your OpenAI API key as an environment variable in your terminal:

    bash
    export OPENAI_API_KEY=your_api_key_here
  3. Create a file

    Create a new file app.py with the basic setup:

    Single Tool
    from praisonaiagents import Agent, Task, AgentTeam
    from langchain_community.utilities import WikipediaAPIWrapper
    
    # Create an agent with Wikipedia tool
    agent = Agent(
        name="WikiAgent",
        role="Research Assistant",
        goal="Search Wikipedia for accurate information",
        backstory="I am an AI assistant specialized in Wikipedia research",
        tools=[WikipediaAPIWrapper],
        reflection=False
    )
    
    # Create a research task
    task = Task(
        name="wiki_search",
        description="Research 'Artificial Intelligence' on Wikipedia",
        expected_output="Comprehensive information from Wikipedia articles",
        agent=agent
    )
    
    # Create and start the workflow
    agents = AgentTeam(
        agents=[agent],
        tasks=[task]
    )
    
    agents.start()
    Multiple Tools
    from praisonaiagents import Agent, Task, AgentTeam
    from langchain_community.tools import YouTubeSearchTool
    from langchain_community.utilities import WikipediaAPIWrapper
    
    # Create YouTube search agent
    agent = Agent(
        name="SearchAgent",
        role="Research Assistant",
        goal="Search for information from YouTube",
        backstory="I am an AI assistant that can search YouTube for relevant videos.",
        tools=[YouTubeSearchTool],
        reflection=False
    )
    
    # Create Wikipedia research agent
    agent2 = Agent(
        name="WikiAgent",
        role="Research Assistant",
        goal="Search for information from Wikipedia",
        backstory="I am an AI assistant that can search Wikipedia for accurate information.",
        tools=[WikipediaAPIWrapper],
        reflection=False
    )
    
    # Create YouTube search task
    task = Task(
        name="search_task",
        description="Search for information about 'AI advancements' on YouTube",
        expected_output="Relevant information from YouTube videos",
        agent=agent
    )
    
    # Create Wikipedia research task
    task2 = Task(
        name="wiki_task",
        description="Search for information about 'AI advancements' on Wikipedia",
        expected_output="Comprehensive information from Wikipedia articles",
        agent=agent2
    )
    
    # Create and start the workflow
    agents = AgentTeam(
        agents=[agent, agent2],
        tasks=[task, task2]
    )
    
    agents.start()
  4. Start Agents

    Type this in your terminal to run your agents:

    bash
    python app.py

No Code

  1. Install Package

    (Upcoming Feature) Install the PraisonAI package:

    bash
    pip install "praisonai"
  2. Set API Key

    Set your OpenAI API key as an environment variable in your terminal:

    bash
    export OPENAI_API_KEY=your_api_key_here
  3. Create a file

    Create a new file agents.yaml with the basic setup:

    yaml
    framework: praisonai
    process: sequential
    agents:  # Canonical: use 'agents' instead of 'roles'
      researcher:
        name: SearchAgent
        role: Research Assistant
        goal: Search for information from multiple sources
        instructions:  # Canonical: use 'instructions' instead of 'backstory' I am an AI assistant that can search YouTube and Wikipedia.
        tools:
          - youtube_search
          - wikipedia
        tasks:
          search_task:
            name: search_task
            description: Search for information about 'AI advancements' on both YouTube and Wikipedia
            expected_output: Combined information from YouTube videos and Wikipedia articles
  4. Start Agents

    Type this in your terminal to run your agents:

    bash
    praisonai agents.yaml

Best Practices

Prefer wrapper utilities over raw tools

Pass LangChain *Wrapper utilities (e.g. WikipediaAPIWrapper, SerpAPIWrapper) directly in the tools=[...] list. PraisonAI auto-detects callable tools and generates a schema from the signature, so wrappers work without extra glue code. Reach for a plain Python function only when a tool needs API-key setup that a wrapper does not expose.

Wrap non-standard tools in a function

Some LangChain tools require constructor arguments (like an API key) before they can run. Wrap those in a small typed function so the agent gets a clean schema:

python
from langchain_community.tools import BraveSearch
import os

def search_brave(query: str):
    """Search the web with BraveSearch."""
    tool = BraveSearch.from_api_key(api_key=os.environ["BRAVE_SEARCH_API"], search_kwargs={"count": 3})
    return tool.run(query)
Write clear docstrings and type hints

PraisonAI builds the tool schema from each function’s signature and docstring. Add a one-line docstring and annotate every parameter (query: str) so the agent knows when and how to call the tool.

Install only the tools you need

LangChain community tools pull in their own dependencies (wikipedia, youtube-search, google-search-results). Install just the extras a page uses and set the matching API keys before running, so agents fail fast on config rather than mid-run.


Related