Building AI Agents with LangChain and LangGraph: Part 1 › Putting It All Together
Michael BrenndoerferJuly 21, 20251 min read
Building AI Agents with LangChain and LangGraph: Part 1 › Putting It All TogetherOne section · Sections in this article7 / 8 ↓
Sections in this article8
Reading tools Definitions & inline links
Toggle tooltip visibility. Hover over underlined terms for instant definitions.
Article links
Make inline references clickable
Let's create a minimal CLI tool that demonstrates everything we've learned. Save this as reply_agent.py and run it from your terminal:
from langchain.chat_models import init_chat_model
from langchain.tools import tool
@tool
def draft_customer_reply(customer_name: str, request_category: str, reply: str) -> str:
"""Draft a reply to a customer."""
return f"I am drafting a reply to {customer_name} in the category {request_category}.\n Content: {reply}"
def main():
# Initialize model
llm = init_chat_model(
"google_vertexai:gemini-2.0-flash",
temperature=0
)
agent = llm.bind_tools(
[draft_customer_reply],
tool_choice="any", # force using a tool
parallel_tool_calls=False
)
# Get user input
request = input("What message would you like to send? ")
# Get tool call from model
response = agent.invoke(request)
if response.tool_calls:
# Execute the tool
args = response.tool_calls[0]["args"]
result = draft_customer_reply.invoke(args)
print(f"Result: {result}")
else:
print("No reply needed.")
if __name__ == "__main__":
main()Usage: python reply_agent.py then type 'Let John know that his request for a refund has been processed.'
In[74]:
Codeprint("What message would you like to send?")
print("tell frank pacakge is on the way")
print("Result: I am drafting a reply to Marco in the category Package Delivery.")
print("Content: Frank, your package is on the way!")Out[74]:
ConsoleWhat message would you like to send? tell frank pacakge is on the way Result: I am drafting a reply to Marco in the category Package Delivery. Content: Frank, your package is on the way!