Skip to content

Simple Bot Agent

Updated
17 Sept 2026
1 min read
0 sections
Page 16 of 18
Langgraph

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
python
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)
python
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
python
graph = StateGraph(AgentState)

graph.add_node('process', process)
graph.add_edge(START, 'process')
graph.add_edge('process', END)

app = graph.compile()
simple bot agent
simple bot agent

User Prompt

python
user_input = '''Hello, who are you?'''

result = app.invoke({"messages": [HumanMessage(content=user_input)]})

print(result['messages'][-1].content)
powershell
OUTPUT:

"I'm an artificial intelligence model known as Llama. Llama stands for Large Language Model Meta AI."

User Input

python
user_input = input("Enter: ")

result = app.invoke({"messages": [HumanMessage(content=user_input)]})

print(result["messages"][-1].content)
powershell
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."