Building AI Agents with LangChain and LangGraph: Part 1 › Initializing the Language Model
Building AI Agents with LangChain and LangGraph: Part 1 › Initializing the Language ModelOne section · Sections in this article3 / 8 ↓
Reading tools Definitions & inline links
Toggle tooltip visibility. Hover over underlined terms for instant definitions.
Article links
Make inline references clickable
The init_chat_model function provides a unified interface for working with different language model providers. Here we're using Google's Vertex AI with the Gemini 2.0 Flash model, which offers a good balance of speed and capability for agentic tasks.
The temperature=0 setting ensures deterministic outputs, which is important for reliable tool usage.
Note: While temperature=0 aims for more deterministic outputs, LLMs often end up being non-deterministic due to various factors. For a deeper understanding of this topic, see Why LLMs Are Not Deterministic.
result = llm.invoke("Hello, are you there?")
print(type(result))
Markdown(result.content)<class 'langchain_core.messages.ai.AIMessage'>
Yes, I am here. How can I help you today?
Let's test our model with a simple interaction to ensure it's working correctly. The response comes back as an AIMessage object, which is LangChain's standard format for model outputs.
@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}"
type(draft_customer_reply)langchain_core.tools.structured.StructuredTool