कस्टम टूल बनाना

LangChain के साथ Agentic Systems डिज़ाइन करना

Dilini K. Sumanapala, PhD

Founder & AI Engineer, Genverv, Ltd.

स्क्वेयर फुटेज निकालना

स्टूडियो अपार्टमेंट की आयताकार फ्लोर प्लान

LangChain के साथ Agentic Systems डिज़ाइन करना

स्क्वेयर फुटेज निकालना

स्टूडियो अपार्टमेंट की आयताकार फ्लोर प्लान, लंबाई और चौड़ाई क्रमशः "side a" और "side b" से चिह्नित।

LangChain के साथ Agentic Systems डिज़ाइन करना

मैथ टूल बनाना

LangChain का आंतरिक क्वेरी हैंडलिंग

"What is the area of a rectangle with 
sides 5 and 7?"

input = " 5, 7"

     

  • नैचुरल लैंग्वेज इनपुट

         
  • संख्यात्मक मान स्ट्रिंग के रूप में निकालें

LangChain के साथ Agentic Systems डिज़ाइन करना

मैथ टूल बनाना

अपना टूल फंक्शन परिभाषित करें

@tool

def rectangle_area(input: str) -> float:
"""Calculates the area of a rectangle given the lengths of sides a and b."""
sides = input.split(',')
a = float(sides[0].strip()) b = float(sides[1].strip())
return a * b

 

  • @tool डेकोरेटर उपयोग करें
  • फंक्शन का नाम दें
  • एक docstring बनाएँ
  • इनपुट को .split() से बाँटें
  • .strip() से whitespace हटाकर float में बदलें
  • a और b को गुणा करें और उत्तर लौटाएँ
LangChain के साथ Agentic Systems डिज़ाइन करना

टूल्स और क्वेरी सेटअप

# Define the tools that the agent can access
tools = [rectangle_area]

# Create a query using natural language query = "What is the area of a rectangle with sides 5 and 7?"
# Pass in the hypotenuse length tool and invoke the agent app = create_react_agent(model, tools)
LangChain के साथ Agentic Systems डिज़ाइन करना

टूल्स और क्वेरी सेटअप

# एजेंट चलाएँ और प्रतिक्रिया प्रिंट करें
response = app.invoke({"messages": [("human", query)]})
print(response['messages'][-1].content)
The area of the rectangle with sides 5 and 7 is 35 square units.
LangChain के साथ Agentic Systems डिज़ाइन करना

प्री-बिल्ट और कस्टम टूल्स

    टूल्स का आइकन

 

LangChain के साथ Agentic Systems डिज़ाइन करना

अभ्यास करते हैं!

LangChain के साथ Agentic Systems डिज़ाइन करना

Preparing Video For Download...