๐Ÿš€
๐Ÿ•ธ๏ธ LangGraph
7. Simple Bot Agent
AI

Simple Bot Agent ๐Ÿค–

1. Define state structure with a list of Human Message objects.

Mar 202510 min read

Simple Bot Agent ๐Ÿค–

Objectives โœ…
  1. Define state structure with a list of Human Message objects.
  2. Initialize a GPT-4o model using LangChain's ChatOpenAI
  3. Sending and handling different types of messages
  4. Building and compiling the graph of the Agent
from typing import TypedDict, List
from langchain_core.messages import HumanMessage
from langchain_ollama import OllamaLLM
from langgraph.graph import StateGraph, START, END
 
class AgentState(TypedDict):
    messages: List[HumanMessage]
 
ollama_model = "llama3.1:8b"
 
llm = OllamaLLM(temperature=0.8, model=ollama_model)
def process(state: AgentState) -> AgentState:
    # Extract the content from the last HumanMessage
    prompt = state["messages"][-1].content
    response = llm(prompt)
    state["messages"].append(HumanMessage(content=response))
    return state
graph = StateGraph(AgentState)
 
graph.add_node('process', process)
graph.add_edge(START, 'process')
graph.add_edge('process', END)
 
app = graph.compile()
 

"simple bot agent"

User Prompt

user_input = '''Hello, who are you?'''
 
result = app.invoke({"messages": [HumanMessage(content=user_input)]})
 
print(result['messages'][-1].content)
OUTPUT:
 
"I'm an artificial intelligence model known as Llama. Llama stands for Large Language Model Meta AI."

User Input

user_input = input("Enter: ")
 
result = app.invoke({"messages": [HumanMessage(content=user_input)]})
 
print(result["messages"][-1].content)
OUTPUT:
 
"It seems like you're referencing the famous painting, "The Blue Boy," by Thomas Gainsborough. However, it's also possible that you're simply expressing excitement or enthusiasm with a playful twist on "blue boy." If you'd like to discuss art, use "The Blue Boy" as an example of 18th-century English art, or if you have another context in mind for the term, please let me know. I'm here to help clarify or provide information based on your interest."

ยฉ 2026 Driptanil Datta. All rights reserved.

Software Developer & Engineer

Disclaimer:The content provided on this blog is for educational and informational purposes only. While I strive for accuracy, all information is provided "as is" without any warranties of completeness, reliability, or accuracy. Any action you take upon the information found on this website is strictly at your own risk.

Copyright & IP:Certain technical content, interview questions, and datasets are curated from external educational sources to provide a centralized learning resource. Respect for original authorship is maintained; no copyright infringement is intended. All trademarks, logos, and brand names are the property of their respective owners.

System Operational

Built with Love โค๏ธ | Last updated: Mar 16 2026