examples/plan_customization/README.md
This example demonstrates advanced usage of the smolagents library, specifically showing how to implement Human-in-the-Loop strategies to:
reset=False preserves the agent's memory between runspython plan_customization.py
def interrupt_after_plan(memory_step, agent):
if isinstance(memory_step, PlanningStep):
# Display plan and get user input
# Modify plan if requested
# Continue or interrupt based on user choice
agent = CodeAgent(
model=InferenceClientModel(),
tools=[DuckDuckGoSearchTool()],
planning_interval=5, # Plan every 5 steps
step_callbacks={PlanningStep: interrupt_after_plan}, # Register callback for PlanningStep
max_steps=10,
verbosity_level=1
)
# First run - may be interrupted
agent.run(task, reset=True)
# Resume with preserved memory
agent.run(task, reset=False) # Keeps all previous steps
============================================================
š¤ AGENT PLAN CREATED
============================================================
1. Search for recent AI developments
2. Analyze the top results
3. Summarize the 3 most significant breakthroughs
4. Include sources for each breakthrough
============================================================
Choose an option:
1. Approve plan
2. Modify plan
3. Cancel
Your choice (1-3):
----------------------------------------
MODIFY PLAN
----------------------------------------
Current plan: [displays current plan]
----------------------------------------
Enter your modified plan (press Enter twice to finish):
The example shows how to inspect the agent's memory:
print(f"Current memory contains {len(agent.memory.steps)} steps:")
for i, step in enumerate(agent.memory.steps):
step_type = type(step).__name__
print(f" {i+1}. {step_type}")
Proper error handling for:
This example teaches:
Perfect for understanding how to build interactive, user-controlled AI agents that can adapt their behavior based on human feedback.