Rewrite the user's words into search terms, search, and decide whether the result is good enough to answer from.
AI · intermediate · 7 min · 26 steps · free
DOCS = {'refund': 'Refunds are free for 30 days.', 'shipping': 'We ship to India in 5 days.'}
def search_docs(query):
for key, text in DOCS.items():
if key in query:
return text
return None
def agent(question):
query = question.lower().replace('money back', 'refund')
found = search_docs(query)
if found is None:
return "I couldn't find that in our documents."
return f'{found} (from our documents)'
print(agent('Can I get my money back?'))
print(agent('Do you have stores in Paris?'))DOCS is created and points to a new dict: {refund: 'Refunds are free for 30 days.', shipping: 'We ship to India in 5 days.'}.search_docs(). Its body does not run yet: it runs each time the function is called.agent(). Its body does not run yet: it runs each time the function is called.agent(), with question = 'Can I get my money back?'. It gets its own names.search_docs(), with query = 'can i get my refund?'. It gets its own names.key is created with the value 'refund'. text is created with the value 'Refunds are free for 30 days.'.text.search_docs() has finished, so its names are gone. The value it returned, 'Refunds are free for 30 days.', is stored in found.found is None is false, so the block under it is skipped.agent() has finished, so its names are gone. It prints Refunds are free for 30 days. (from our documents).agent(), with question = 'Do you have stores in Paris?'. It gets its own names.query is created with the value 'do you have stores in paris?'.search_docs(), with query = 'do you have stores in paris?'. It gets its own names.key is created with the value 'refund'. text is created with the value 'Refunds are free for 30 days.'.key in query is false, so the block under it is skipped.key changes from 'refund' to 'shipping'. text changes from 'Refunds are free for 30 days.' to 'We ship to India in 5 days.'.key in query is false, so the block under it is skipped.for key, text in DOCS.items().None.found is None is true, so the block under it runs."I couldn't find that in our documents.".agent() has finished, so its names are gone. It prints I couldn't find that in our documents..Answer: Documents say "refund"
Answer: Agentic can search again or differently
← Planning: Breaking a Goal into Steps · Routing to Specialist Agents →