किसी चैटबोट में बाहरी टूल जोड़ना

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

Dilini K. Sumanapala, PhD

Founder & AI Engineer, Genverv, Ltd.

LangGraph के साथ एक्सटर्नल टूल्स

  बीच में माइक्रोचिप ग्राफ़िक वाला डेस्कटॉप मॉनिटर, जिसके केंद्र में "API" लिखा है.

     

  • चैटबोट्स के लिए API टूल

     
    • समाचार
    • डेटाबेस
    • सोशल मीडिया
    • आदि
LangChain के साथ Agentic Systems डिज़ाइन करना

एक Wikipedia टूल जोड़ना

लोग बड़ी किताबों पर बैठे पढ़ रहे हैं.

  विकिपीडिया आइकन.

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

एक Wikipedia टूल जोड़ना

# Modules for building a Wikipedia tool
from langchain_community.utilities import WikipediaAPIWrapper
from langchain_community.tools import WikipediaQueryRun


# Initialize Wikipedia API wrapper to fetch top 1 result api_wrapper = WikipediaAPIWrapper(top_k_results=1)
# Create a Wikipedia query tool using the API wrapper wikipedia_tool = WikipediaQueryRun(api_wrapper=api_wrapper)
tools = [wikipedia_tool]
LangChain के साथ Agentic Systems डिज़ाइन करना

एक Wikipedia टूल जोड़ना

# Bind the Wikipedia tool to 
# the language model
llm_with_tools = llm.bind_tools(tools)


# Modify chatbot function to # respond with Wikipedia def chatbot(state: State): return {"messages": [llm_with_tools.invoke( state["messages"])]}

   

  • टूल्स बाइंड करें

 

  • चैटबोट नोड अपडेट करें

  • Wikipedia सक्षम करें

  • LLM टूल कॉल तय करता है

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

अन्य API टूल्स

  बीच में माइक्रोचिप ग्राफ़िक वाला डेस्कटॉप मॉनिटर, जिसके केंद्र में "API" लिखा है.

   

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

टूल नोड्स जोड़ना

# Modules for adding tool conditions 
# and nodes
from langgraph.prebuilt import 
ToolNode, tools_condition


# Add chatbot node to the graph graph_builder.add_node("chatbot", chatbot)

चैटबोट नोड.

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

टूल नोड्स जोड़ना

# Modules for adding tool conditions 
# and nodes
from langgraph.prebuilt import 
ToolNode, tools_condition

# Add chatbot node to the graph
graph_builder.add_node("chatbot",
                       chatbot)


# Create a ToolNode to handle tool calls # and add it to the graph tool_node = ToolNode(tools=[wikipedia_tool]) graph_builder.add_node("tools", tool_node)

चैटबोट और टूल नोड्स.

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

टूल नोड्स जोड़ना

# Set up a condition to direct from chatbot 
# to tool or end node
graph_builder.add_conditional_edges(
             "chatbot", tools_condition)



चैटबोट के साथ END और टूल नोड्स, जिनसे डैश्ड लाइनों द्वारा conditional edges दिखाए गए हैं.

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

टूल नोड्स जोड़ना

# Set up a condition to direct from chatbot 
# to tool or end node
graph_builder.add_conditional_edges(
             "chatbot", tools_condition)



# Connect tools back to chatbot and # add START and END nodes graph_builder.add_edge("tools", "chatbot") graph_builder.add_edge(START, "chatbot") graph_builder.add_edge("chatbot", END)

पूरा चैटबोट डायग्राम: चैटबोट नोड टूल्स और END नोड से जुड़ा है, ऊपर START नोड है.

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

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

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

Preparing Video For Download...