Začněte nyníZačněte zdarma

Smarter Agents: Validate and Retry

You've written a validation function to check that a real estate agent's responses include enough detail. Now it's time to use that function in an agent.

If the response is too short, your check_answer_length() function will raise an exception, and the agent will automatically retry with a better, more complete answer based on your feedback.

Note we're using verbosity_level=2 to have visibility on the agent's thought process and actions.

Toto cvičení je součástí kurzu

AI Agents with Hugging Face smolagents

Zobrazit kurz

Pokyny k cvičení

  • Add check_answer_length to the final_answer_checks list when creating the agent.
  • Run the agent with a simple prompt to trigger a response.

Interaktivní cvičení na vyzkoušení si v praxi

Vyzkoušejte si toto cvičení dokončením tohoto ukázkového kódu.

real_estate_agent = CodeAgent(
    tools=[],
    model=model,
    # Create the agent with answer length validation
    final_answer_checks=[____],
    verbosity_level=2
)

# Run the agent with a short prompt
response = real_estate_agent.run("Suggest a neigborhood for a couple moving to Austin.")
print(response)
Upravit a spustit kód