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 ejercicio forma parte del curso
AI Agents with Hugging Face smolagents
Instrucciones del ejercicio
- 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.
Ejercicio interactivo práctico
Prueba este ejercicio y completa el código de muestra.
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 ____