How to create a very basic AI AGENT with “Python +Langgraph” ?

0
(0)

What is an AI Agent?

Agentic Systems can be divided into Workflows and Agents

  • Workflows are structured systems that orchestrate Large Language Models (LLMs) and tools through predetermined, scripted pathways. The execution follows predefined logic and decision trees.
  • Agents, in contrast, are autonomous systems where LLMs make real-time decisions about their own processes and tool selection. They maintain dynamic control over task execution, adapting their approach based on context and requirements.

An agent is like an autonomous entity that operates on your behalf, leveraging AI technologies to perform tasks and interact with the world.

AI Agents can make decisions and take actions on their own to achieve a goal without being told exactly what to do at every step.

Agentic AI is a system that is using one or more agents . It is a similar term.

TypeReactiveTool UseReasoningPlanningProactivity
RAG Chatbot
Tool-Augmented Chatbot
Agentic AI

For any autonomous Agent the reliability drops. With Langraph the Reliability increases significantly

Typical Langchain  Application ( Its a chain of things happening one after another )

LangGraph Application

Stateful workflows represented as graphs.

FeatureLangChainLangGraph
PurposeToolkit to build LLM apps (chains, tools, agents)Framework to manage complex workflows with state
StyleLinear or reactive chainsGraph-based, supports loops, retries, memory
Best Use CaseSimple chatbots, RAG apps, tool usageMulti-step workflows, agents with memory, conditional paths
State HandlingStateless or partially statefulFully stateful; remembers and transitions based on logic
Example Use“Book a flight” using a flight API“Plan a vacation” (ask budget → choose flights → book hotel → loop if error)

Part-1 : Building a very basic AI Agent using Langgraph ( Windows )

YT Reference : How to make Jupyter notebook up and running in VSCODE

Create a folder ( Open cmd )

  • mkdir langgraph && cd langgraph
  • code .

Creating VE ( Open Terminal, ctrl + ~) 

  • python -m venv venv
  • source venv/Scripts/activate ( for git bash )

Install necessary plugins using uv or pip

  • pip install langgraph python-dotenv ipykernel notebook 

ipython will be installed as a dependency to ipykernel, so no need to install separately ( pip install ipython ❌ )

Create : New Jupyter Notebook

  •    ctrl + shift + p
  •    create: New Jupyter Notebook
  •    Add Python Environment (as given in the Reference Video Above)

Create Class 

from typing import TypedDict

class PortfolioState(TypedDict):

    amount_usd:float

    total_usd:float

     total_inr:float

Define Functions 

def calculate_tot(state:PortfolioState) -> PortfolioState:

    state['total_usd'] = state['amount_usd']*1.08

    return state

def convert_to_inr(state:PortfolioState)  -> PortfolioState:

    state['total_inr'] = state['total_usd']*85

    return state

Build the Graph

from langgraph.graph import StateGraph, START, END

builder = StateGraph(PortfolioState)

builder.add_node("calculate_total_node", calculate_tot)

builder.add_node("convert_to_inr", convert_to_inr)

builder.add_edge(START, "calculate_total_node")

builder.add_edge("calculate_total_node", "convert_to_inr”)

builder.add_edge("convert_to_inr", END)

graph = builder.compile()

Generate the Flow Diagram

from IPython.display import Image, display

display(Image(graph.get_graph().draw_mermaid_png()))

How useful was this post?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate this post.

As you found this post useful...

Follow us on social media!

Leave a Comment