Say More, Agent: Enforcing Answers Length
You're building a real estate assistant that helps users find homes based on their preferences. Sometimes, the agent gives overly brief or vague recommendations, like "You should check out this house in Brooklyn."
To make responses more helpful, you want to validate that each answer contains at least 200 characters. If it's too short, the agent should try again using your error message as guidance.
In this exercise, you'll write a validation function that checks the length of a response.
Este exercício faz parte do curso
AI Agents with Hugging Face smolagents
Instruções do exercício
- Check if the
final_answer
is shorter than 200 characters. If it is, raise an exception with a helpful error message. - If it passes the check, return
True
to mark the answer as valid.
Exercício interativo prático
Experimente este exercício completando este código de exemplo.
def check_answer_length(final_answer, agent_memory):
# Check if answer contains less than 200 characters
if len(str(final_answer)) < ____:
raise Exception("The answer is too short. Please include more details.")
# Return True if check passes
return ____