Let's put the agent pieces together. Build an agent for Riverside Books with the three shop tools, a short system prompt, and memory, then hold a two turn conversation. Pause, and try it first.
Here's one solution. The agent gets the three tools, a system prompt, and an in memory checkpointer. A small helper sends a message on one thread. First, the customer asks about The Hobbit. Then they ask, who wrote it, without saying the title again. Run it. The agent remembers which book they mean, and calls the author tool.
shop_agent.pypython
from langchain.agents import create_agentfrom langgraph.checkpoint.memory import InMemorySaverfrom shop_tools import check_stock, get_price, get_authoragent = create_agent( "google_genai:gemini-flash-lite-latest", tools=[check_stock, get_price, get_author], system_prompt="You are Riverside Books' assistant. One short sentence per answer.", checkpointer=InMemorySaver(),)cfg = {"configurable": {"thread_id": "shop-1"}}def say(text): out = agent.invoke({"messages": [{"role": "user", "content": text}]}, cfg) print("You:", text, "\nBot:", out["messages"][-1].text)say("How much is The Hobbit?")say("And who wrote it?")
Output
You: How much is The Hobbit?
Bot: The Hobbit costs £8.99.
You: And who wrote it?
Bot: The Hobbit was written by J.R.R. Tolkien.
Also uses shop_tools.py
from langchain.tools import toolBOOKS = { "The Hobbit": {"stock": 7, "price": 8.99, "author": "J.R.R. Tolkien"}, "Dune": {"stock": 3, "price": 9.99, "author": "Frank Herbert"}, "Circe": {"stock": 0, "price": 10.99, "author": "Madeline Miller"},}@tooldef check_stock(title: str) -> int: """Copies of a book in stock at Riverside Books.""" return BOOKS.get(title, {}).get("stock", 0)@tooldef get_price(title: str) -> float: """Price of a book in pounds.""" return BOOKS.get(title, {}).get("price", 0.0)@tooldef get_author(title: str) -> str: """Author of a book.""" return BOOKS.get(title, {}).get("author", "unknown")
This short program has the core of a real assistant. Tools for live data. A system prompt for tone and rules. And memory, so follow up questions like, who wrote it, just work. In the project section, we'll add documents, guardrails, and tests.