एजेंट के Final Answer का वैलिडेशन

Hugging Face smolagents के साथ AI Agents

Adel Nehme

VP of AI Curriculum, DataCamp

वैलिडेशन क्यों ज़रूरी है

  • एजेंट का उत्तर उपयोगी नहीं था
  • कस्टमर का अनुभव बिगड़ गया

इसे टालने के लिए, smolagents आपको final answers वैलिडेट करने देता है!

Hugging Face smolagents के साथ AI Agents

एजेंट के जवाबों का वैलिडेशन

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 नियम पर खरा नहीं उतरता, तो exception उठाएँ. वरना True लौटाएँ.
Hugging Face smolagents के साथ AI Agents

अपने एजेंट में Output Validation का उपयोग

car_advisor = CodeAgent(
    tools=[WebSearchTool()],
    model=InferenceClientModel(),
    final_answer_checks=[check_answer_length],
    verbosity_level=0
)
  • जवाब देने से पहले check_answer_length वैलिडेशन चलाएँ.
  • फ़ंक्शन में दी गई exception message के आधार पर ऑटो-रीट्राई करें.
Hugging Face smolagents के साथ AI Agents

मेटा-इवैल्यूएशन: 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.
"""
Hugging Face smolagents के साथ AI Agents

मेटा-इवैलुएटर से रीजनिंग का वैलिडेशन

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
Hugging Face smolagents के साथ AI Agents

मल्टीपल वैलिडेशन्स को जोड़ना

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

यूज़र तक पहुँचने से पहले त्रुटियाँ पकड़ने और ठीक करने की संभावना बढ़ती है!

Hugging Face smolagents के साथ AI Agents

इंटेलीजेंट सिस्टम डिज़ाइन करना

Hugging Face smolagents के साथ AI Agents

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

Hugging Face smolagents के साथ AI Agents

Preparing Video For Download...