การตรวจสอบคำตอบสุดท้ายของ Agent

AI Agents ด้วย Hugging Face smolagents

Adel Nehme

VP of AI Curriculum, DataCamp

เหตุใดการตรวจสอบจึงสำคัญ

  • คำตอบของ Agent ไม่เป็นประโยชน์
  • ประสบการณ์ของลูกค้าสูญเสียไป

เพื่อป้องกันปัญหานี้ smolagents ให้ตรวจสอบคำตอบสุดท้ายได้!

AI Agents ด้วย Hugging Face smolagents

การตรวจสอบคำตอบของ Agent

def check_answer_length(final_answer, agent_memory):
    # Check if the answer is substantial enough
    if len(final_answer) < 200:
        raise Exception("Car recommendation is too brief")
    return True
  • หาก final_answer ไม่ผ่านกฎ ให้ raise exception มิฉะนั้นให้คืนค่า True
AI Agents ด้วย Hugging Face smolagents

การใช้งาน Output Validation ใน Agent

car_advisor = CodeAgent(
    tools=[WebSearchTool()],
    model=InferenceClientModel(),
    final_answer_checks=[check_answer_length],
    verbosity_level=0
)
  • รัน check_answer_length ก่อนส่งคำตอบ
  • ลองใหม่อัตโนมัติตาม exception message ที่กำหนดในฟังก์ชัน
AI Agents ด้วย Hugging Face smolagents

Meta-Evaluation: ใช้ AI ตรวจสอบ AI

validation_prompt = """
Reasoning process: {}

Agent's final answer: {}

Does the final answer logically follow
from the reasoning and solve the user's 
question? 

Respond only TRUE or FALSE. 
No other text.
"""
AI Agents ด้วย Hugging Face smolagents

ตรวจสอบกระบวนการคิดด้วย Meta-Evaluator

def check_reasoning_accuracy(final_answer, agent_memory):
    evaluator_model = InferenceClientModel()
    reasoning_steps = agent_memory.get_succinct_steps()
    final_prompt = validation_prompt.format(reasoning_steps, final_answer)

    message = ChatMessage(role='user', content=final_prompt)
    evaluation = evaluator_model([message])

    if evaluation.content == "FALSE":
        raise Exception("The agent's reasoning process contains logical errors")
    else:
        return True
AI Agents ด้วย Hugging Face smolagents

การรวม Validation หลายรายการเข้าด้วยกัน

car_advisor = CodeAgent(
    tools=[WebSearchTool()],
    model=InferenceClientModel(),
    final_answer_checks=[check_answer_length, check_reasoning_accuracy],
    verbosity_level=0
)

ช่วยให้ตรวจพบและแก้ไขข้อผิดพลาดก่อนที่ผู้ใช้จะเห็นได้มากขึ้น!

AI Agents ด้วย Hugging Face smolagents

การออกแบบระบบอัจฉริยะ

AI Agents ด้วย Hugging Face smolagents

มาฝึกกันเถอะ!

AI Agents ด้วย Hugging Face smolagents

Preparing Video For Download...