เริ่มต้นใช้งานเริ่มต้นใช้งานได้ฟรี

การผสาน custom tools เข้ากับ agents

เมื่อมีเครื่องมือพร้อมแล้ว ก็ถึงเวลาตั้งค่า agentic workflow กัน! เราจะใช้ ReAct agent อีกครั้ง ซึ่งจะวิเคราะห์ขั้นตอนที่ควรดำเนินการ แล้วเลือกเครื่องมือโดยอิงจากบริบทและคำอธิบายของเครื่องมือแต่ละชิ้น มีการกำหนด llm ที่ใช้โมเดล gpt-4o-mini ของ OpenAI ไว้ให้แล้ว

แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร

การพัฒนาแอปพลิเคชัน LLM ด้วย LangChain

ดูคอร์ส

คำแนะนำการฝึกหัด

  • สร้าง ReAct agent โดยใช้ create_react_agent() พร้อมระบุ llm และ list ที่มี retrieve_customer_info เป็นเครื่องมือ
  • เรียกใช้ agent ด้วย agent.invoke() บน input ที่กำหนดให้
  • แสดงผลเนื้อหาจากข้อความสุดท้าย

แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ

ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์

@tool
def retrieve_customer_info(name: str) -> str:
    """Retrieve customer information based on their name."""
    customer_info = customers[customers['name'] == name]
    return customer_info.to_string()

# Create a ReAct agent
agent = create_react_agent(____, [____])

# Invoke the agent on the input
messages = agent.____({"messages": [("human", "Create a summary of our customer: Peak Performance Co.")]})
print(messages['messages'][-1].____)
แก้ไขและรันโค้ด