Ask for a plan first, then run each step and record its result and status, like a to-do list the agent works through.
AI · intermediate · 6 min · 24 steps · free
RESULTS = {'find flights': '3 flights found', 'pick cheapest': 'AI-123, 4200 rupees', 'book it': 'booked AI-123'}
# Stands in for asking the model to break a goal into steps.
def plan(goal):
return ['find flights', 'pick cheapest', 'book it']
# Stands in for calling the right tool for each step.
def execute(task):
return RESULTS[task]
goal = 'book the cheapest flight to Goa'
tasks = [{'task': t, 'status': 'todo'} for t in plan(goal)]
for item in tasks:
item['result'] = execute(item['task'])
item['status'] = 'done'
print(tasks[-1]['result'])RESULTS is created and points to a new dict: {find flights: '3 flights found', pick cheapest: 'AI-123, 4200 rupees', book it: 'booked AI-123'}.plan(). Its body does not run yet: it runs each time the function is called.execute(). Its body does not run yet: it runs each time the function is called.goal is created with the value 'book the cheapest flight to Goa'.['find flights', 'pick cheapest', 'book it'].item is created and points to a new dict: {task: 'find flights', status: 'todo'}.execute(), with task = 'find flights'. It gets its own names.RESULTS[task].status in the dict that item points to changes from 'todo' to 'done'.item now points to a different dict: {task: 'pick cheapest', status: 'todo'}.execute(), with task = 'pick cheapest'. It gets its own names.RESULTS[task].execute() has finished, so its names are gone. A new key result with the value 'AI-123, 4200 rupees' is added to the dict that item points to.status in the dict that item points to changes from 'todo' to 'done'.execute(), with task = 'book it'. It gets its own names.RESULTS[task].execute() has finished, so its names are gone. A new key result with the value 'booked AI-123' is added to the dict that item points to.status in the dict that item points to changes from 'todo' to 'done'.for item in tasks.Answer: Long goals need ordered steps
Answer: Re-plan
← Agent Memory · Agentic RAG: Rewrite, Search, Decide →