In this guide, you’ll learn how to build a real-time news AI agent using tools from LangChain and Bright Data. When you’re finished with the project, you should be able to answer the following questions.
- What is the LangChain project?
- What are their main offerings?
- What’s the difference between LangChain and LangGraph?
- How does LangChain make it easy to build tools for AI agents?
- How does LangGraph make it easy to orchestrate AI agents?
- How does one build an AI agent using LangChain and LangGraph?
The LangChain project
The LangChain project began in 2022 as a framework for AI tool integration. By April of 2023, LangChain expanded enough to incorporate into its own company. Over the past few years, their offerings have expanded into two core toolsets: LangChain and LangGraph.
- LangChain: Adapters and connectors for plugging AI agents into external software.
- LangGraph: A graph-style orchestration layer for agent loops, state management and persistent AI agent memory.

What is LangChain?
LangChain allows us to write Python functions and wrap them as AI-accessible tools. This was the first revolutionary offering from the LangChain community. With LangChain, any Python code you write can be wrapped as a tool for your AI agents to use.
- Adapters: LangChain offers a variety of adapters so developers can build AI agents from all major providers such as Anthropic, OpenAI, Google, xAI and more.
- Tools: Make any Python function usable for AI agents using the
@tooldecorator. - Data access: Create vector databases so your agents can access external information.
LangChain gives models access to external environments like tools and storage.
What is LangGraph?
LangGraph gives you the power to create an orchestration layer for your AI agents. LangChain gives your agents access to tools. LangGraph helps AI agents use their tools with maximum efficiency and productivity.
- Nodes: Functions that encode logic for AI agents and manage state. This is how the agent understands its tooling.
- Edges: Functions that decide when to execute node functions. Edges help agents use reasoning to understand task progress and which tool to use next.
- Checkpointers: Enable agent memory using either Random Access Memory (RAM) or persistent on-disk storage. This prevents your agents from getting lost mid-task.
- Prebuilt agents: Frameworks like ReAct allow you to create a basic agentic loop and skip the boilerplate.
LangGraph makes it easy to orchestrate AI agents using LangChain-based tooling.
Getting started
Creating a Bright Data API key
You’ll need to sign up for Bright Data’s Search Engine Results Page (SERP) API. Once you’ve got an account, navigate to the dashboard. Your API key will show up in the overview section of your new SERP zone.

Creating an OpenAI API key
Next, you’ll need an account for the OpenAI platform. Once you’ve got an account, go to the API keys tab and create a new key. Click on the Create new secret key button and your new key should pop up.

Once you’ve got keys, you’re ready to begin building your AI agent.
Installing dependencies
Next, we’ll install some dependencies. Each of these packages helps us piece together the agent. langchain-openai allows us to integrate with OpenAI models easily. langchain-brightdata gives us the connectors required for Bright Data’s tooling. langchain and langgraph give us access to the base LangChain ecosystem for AI agent orchestration.
These tools are frequently updated with breaking changes. If you’ve already got them installed, add the --upgrade flag to each command.
Install LangChain
pip install langchain
Install LangChain’s OpenAI package
pip install langchain-openai
Install the Bright Data toolset
pip install langchain-brightdata
Install LangGraph
pip install langgraph
Building the agent
Initialize the client
Creating our client instance is pretty straightforward. You can either pass your OpenAI API key into ChatOpenAI() or you can set it as an environment variable. This creates an API client instance for interacting with OpenAI’s models. We used gpt-5 but you’re welcome to use any of their models — performance will vary based on your choice of model.
Passing your API key into ChatOpenAI
client = ChatOpenAI(
api_key="sk-proj-your-openai-api-key",
model="gpt-5")
If you have an environment variable set
client = ChatOpenAI(model="gpt-5")
Bright Data SERP tool
Here, we set up our SERP tool. The only required parameter is your Bright Data API key. The rest of our keyword arguments are used to customize results.
search_engine="google": Tell Bright Data which search engine to use.results_count=30: We want 30 results per page.parse_results=True: Bright Data parses our results to input structured data for our AI agent.device="mobile": We want results from a mobile device, this is the most common user.
#bright data api key
API_TOKEN = "your-bright-data-api-key"
#create the serp tool
serp_tool = BrightDataSERP(
bright_data_api_key=API_TOKEN,
search_engine="google",
results_count=30,
parse_results=True,
device="mobile"
)
The SERP tool allows us to call Bright Data’s SERP API.
Wrapping SERP as a LangChain tool
Using the @tool decorator, we write another function which simply calls serp_tool and pipes its output back to the model. This function should have a description for your AI agent to read. We return a simple JSON payload in string format so the AI agent can read the output.
@tool
def brightdata_search(query: str) -> str:
"""
Run a Bright Data SERP news search.
Args:
query: What to search for (e.g., "best electric vehicles").
Returns:
A JSON string of parsed SERP results (keep it compact).
"""
payload = {"query": query}
results = serp_tool.invoke(payload)
return json.dumps(results, ensure_ascii=False)
Creating the AI agent
Creating our agent is both expressive and powerful. We use MemorySaver() to use our system RAM for agent memory. create_react_agent() takes in several arguments to build the full agent.
model=client: Use the client we created earlier as our agent.prompt=...: Give the agent a prompt with some basic information about its purpose.tools=[brightdata_search]: Pass our tools into the agent as a list. Here, we have one but your list can hold any number of tools.checkpointer=checkpointer: Use ourMemorySaver()instance to hold the AI agent’s memory.
#create a checkpointer to hold agent memory
checkpointer = MemorySaver()
#create the actual agent
agent = create_react_agent(
model=client,
prompt=
"""
You are a news agent. Using the SERP tool, find the top five headlines requested by the user.
""",
tools=[brightdata_search],
checkpointer=checkpointer
)
Invoking the AI agent
Now, we get to the actual runtime. Here, we create a user_input variable to hold our actual user prompt. config creates a thread_id so our agent can keep track of its task. We then pass these into agent.invoke() to run the news retrieval AI agent. Finally, we print the AI agent’s output to the terminal.
#actual prompt from the user
user_input = """Can you give me local news for Southeast Michigan as of today? If a source yields no news context,"
i.e. 'General News' with no actual headlines, ignore it."""
#memory configuration
config = {"configurable": {"thread_id": "news agent"}}
#get and print the results
result = agent.invoke({"messages": user_input}, config=config)
print(result["messages"][-1].content)
Putting everything together
Full code example
Below, we take the pieces used above and put them all into a working program. First, we create our client and our SERP tool. Then, we wrap the function using @tool and create our checkpointer to hold the agent memory. Finally, we pass everything into create_react_agent() and call our agent with our memory configuration. Make sure to swap out the placeholder API keys with your own.
from langgraph.checkpoint.memory import MemorySaver
from langchain_openai import ChatOpenAI
from langchain_brightdata import BrightDataSERP
from langchain.tools import tool
from langgraph.prebuilt import create_react_agent
import json
#create an openai chat instance
client = ChatOpenAI(
api_key="sk-proj-your-openai-api-key",
model="gpt-5")
#bright data api key
API_TOKEN = "your-bright-data-api-key"
#create the serp tool
serp_tool = BrightDataSERP(
bright_data_api_key=API_TOKEN,
search_engine="google",
results_count=30,
parse_results=True,
device="mobile"
)
#wrap it as a langchain tool
@tool
def brightdata_search(query: str) -> str:
"""
Run a Bright Data SERP news search.
Args:
query: What to search for (e.g., "best electric vehicles").
Returns:
A JSON string of parsed SERP results (keep it compact).
"""
payload = {"query": query}
results = serp_tool.invoke(payload)
return json.dumps(results, ensure_ascii=False)
#create a checkpointer to hold agent memory
checkpointer = MemorySaver()
#create the actual agent
agent = create_react_agent(
model=client,
prompt=
"""
You are a news agent. Using the SERP tool, find the top five headlines requested by the user.
""",
tools=[brightdata_search],
checkpointer=checkpointer
)
#actual prompt from the user
user_input = """Can you give me local news for Southeast Michigan as of today? If a source yields no news context,"
i.e. 'General News' with no actual headlines, ignore it."""
#memory configuration
config = {"configurable": {"thread_id": "news agent"}}
#get and print the results
result = agent.invoke({"messages": user_input}, config=config)
print(result["messages"][-1].content)
The output
Here is our output from the AI agent. It found five separate news stories and linked to each of them for the user to read. Our AI agent is working as expected.
Here are five fresh local headlines for Southeast Michigan (today/last 24 hours):
- Suspect shot by Roseville police after ramming patrol vehicle, approaching officers with knife � FOX 2 Detroit (today) https://www.fox2detroit.com/news
- Counterfeit $100 bills under investigation in Oakland County � CBS Detroit (1 hour ago) https://www.cbsnews.com/detroit/news/counterfeit-100-bills-under-investigation-in-oakland-county/
- 1 dead, multiple hurt after car hits hay wagon in Southeast Michigan � Patch (4 hours ago) https://patch.com/michigan/across-mi/1-dead-multiple-hurt-after-car-hits-hay-wagon-southeast-mi-sheriff
- Oakland University student under investigation for allegedly threatening GOP candidate � Detroit Free Press (21 hours ago) https://www.freep.com/story/news/local/michigan/oakland/2025/10/12/oakland-university-investigating-student-alleged-threats-gop-candidate-mike-stenger/86660650007/
- Macomb County woman injured in fatal hay tractor crash � Macomb Daily (1 day ago) https://www.macombdaily.com/2025/10/12/macomb-county-woman-injured-in-fatal-hay-tractor-crash/
Conclusion
LangChain makes it simple and intuitive to build tools for AI agents. LangGraph provides a comprehensive framework to orchestrate these AI agents. You can build everything from news agents to AI trading agents, AI agents with autonomous search capabilities can unlock the power of real-time web data for your agentic AI system.who needs help, n8n workflows can help you turn your idea into something tangible — quickly.