Building AI Agents with LangChain and LangGraph: Part 1 › Creating Tools for Our Agent
Building AI Agents with LangChain and LangGraph: Part 1 › Creating Tools for Our AgentOne section · Sections in this article4 / 8 ↓
Reading tools Definitions & inline links
Toggle tooltip visibility. Hover over underlined terms for instant definitions.
Article links
Make inline references clickable
Tools are the bridge between language models and external actions. The @tool decorator automatically converts a Python function into a format that language models can understand and invoke.
Our draft_customer_reply function demonstrates the key principles of good tool design:
- Clear purpose: The function does one thing well
- Type annotations: Parameters have explicit types for validation
- Descriptive docstring: Helps the model understand when and how to use the tool
- Return value: Provides feedback about the action taken
In a real application, this would integrate with a CRM, WhatsApp, Telegram, or other type of service or API.
Understanding Tool Schemas
The @tool decorator automatically generates a JSON schema that describes the function's parameters. This schema is what the language model uses to understand how to call the tool correctly.
Let's examine the generated schema to see how our type annotations are converted into a format the model can understand:
print(json.dumps(draft_customer_reply.args, indent=2)){
"customer_name": {
"title": "Customer Name",
"type": "string"
},
"request_category": {
"title": "Request Category",
"type": "string"
},
"reply": {
"title": "Reply",
"type": "string"
}
}