Agents in LangChain

Designing Agentic Systems with LangChain

Dilini K. Sumanapala, PhD

Founder & AI Engineer, Genverv Ltd.

Meet your instructor

    Picture of course instructor.

   

  • Dilini K. Sumanapala, PhD

  • AI Engineer

  • Cognitive Neuroscience

  • Natural Language Applications

  • Founder, Genverv Ltd.

Designing Agentic Systems with LangChain

An overview of agents and tools

Icon of a robot representing an agent

 

  • Agents

    Autonomous systems that make decisions and take actions
  • Tools

    Functions agents use to perform specific tasks
    • Data query
    • Research reports
    • Data analysis
Designing Agentic Systems with LangChain

Basic concepts

Head of chatbot

   

  • LLMs (e.g., ChatGPT)

  • Prompts

  • Tools

  • API

  • LangChain

    • Building AI agents
Designing Agentic Systems with LangChain

Course overview

    Icon of tools, Wikipedia, and a puzzle of a human face.

   

  • Math problems

  • Switch between tools and LLMs

Designing Agentic Systems with LangChain

Diagram of a brain and a speech bubble with query and reasoning.

Designing Agentic Systems with LangChain

Diagram of a brain, action cogs, and a speech bubble with query and reasoning, action and response.

Designing Agentic Systems with LangChain

Diagram of a brain and cogs with a speech bubble representing the components of a ReAct agent, with the ReAct label added underneath.

Designing Agentic Systems with LangChain

Improving response accuracy

    Screenshot of an inaccurate math response from an earlier ChatGPT conversation. Correct answer of "483" added to the bottom of the image.

   

  • Coding

  • Math

1 https://community.openai.com/t/chatgpt-simple-math-calculation-mistake/62780
Designing Agentic Systems with LangChain

Breaking up problems

  Diagram of mathematical operators.

 

Order of Math Operations

1. Parentheses

2. Exponents

3. Multiplication/Division

4. Addition/Subtraction

Designing Agentic Systems with LangChain

Expanding agents with LangGraph

      Diagram of a generic flowchart on the left with LangGraph logo on the right.

Designing Agentic Systems with LangChain

Graph structures

    Diagram of a flowchart with three different document icons underneath representing outcome of "edges".

     

Nodes

  • Query the Database

  • Return the Document

     

Edges

Rules connecting nodes

Designing Agentic Systems with LangChain

Create a ReAct agent

# Module imports

from langchain_core.tools import tool
from langchain_openai import ChatOpenAI
from langgraph.prebuilt import create_react_agent
import math
# LLM Setup model = ChatOpenAI(openai_api_key="<OPENAI_API_TOKEN">, model="gpt-4o-mini")
Designing Agentic Systems with LangChain

Create a ReAct agent

# Create the agent
agent = create_react_agent(model, tools)


# Create a query query = "What is (2+8) multiplied by 9?"
# Invoke the agent and print the response response = agent.invoke({"messages": [("human", query)]})
# Print the agent's response print(response['messages'][-1].content)
<script.py> output:
    The result of (2 + 8) multiplied by 9 is 90.
Designing Agentic Systems with LangChain

Let's practice!

Designing Agentic Systems with LangChain

Preparing Video For Download...