An agent that searches
It decides what to look up, and when it has enough.
Instead of retrieving once up front, give the agent a search tool. It can search, read, and search again with a better query.
- model calls
- 1
- tool calls
- 0
- tokens in
- 118
- tokens out
- 23
- time
- 2.0s
Task I paid cash on delivery for headphones and opened them 3 days ago. They're faulty. What can I do, and when do I get my money?
Model call 1. It read 118 tokens and wrote 23. It asked for a tool, so it isn't done.
search_help({"query":"faulty return cash on delivery refund timeline"})
stop_reason: tool_use
Context window
118 tokens sent
- Your messages32
- Tool definitions55
- System prompt31
0.01% of the 10,48,576-token window. Every call sends all of it again.
Context window118 tokens sent
- System prompt31
- Tool definitions55
- Your messages32
Three searches and a mostly right answer, with one real slip: it says faulty replacements must be requested within 7 days. The help centre never says that; the 7 days is for returns. Retrieval narrows mistakes. It doesn't end them.
How do you catch slips like that before customers do?
Now write the retrieval half yourself, on real embeddings of the help centre.
Sign in to run your code. It's free.
Fix the bug
DOC_VECTORS are real embeddings of QuickCart's 8 help-centre sections; QUESTION_VECTORS embed these questions: 0: “I bought headphones 9 days ago and opened them. Can I return them?” 1: “I paid cash on delivery. When will my refund come?” 2: “My cart is Rs 250 and I'm a Plus member. Is delivery free?”
Input: a question number and k. Print the k most similar sections, best first, as id score with the cosine similarity to 3 decimals.
▸ Runs first: set-up code (4 lines). Open to read it.
1DOC_IDS = ["returns","refunds","damaged","delivery","cancel","plus","cod","student"]2DOC_VECTORS = [[0.01343,0.11169,-0.02195,-0.04553,-0.30773,0.10865,0.04541,-0.04893,0.05818,-0.2952,0.03822,-0.12388,0.06716,0.0195,-0.17842,0.11554,0.18779,-0.05048,0.00544,-0.00174,-0.17849,0.06107,0.03774,-0.03837,-0.07642,-0.05283,-0.07995,-0.05451,0.0208,0.74386,-0.0577,-0.25497],[0.03589,0.09006,0.045,-0.02614,-0.15266,0.11708,0.02097,-0.07271,0.02666,-0.35414,-0.03727,-0.0487,0.07815,-0.08337,-0.14485,0.10628,0.24252,-0.15216,0.01682,-0.06118,-0.08247,0.02646,0.04036,-0.01983,-0.09999,0.01052,-0.03976,0.04477,-0.04327,0.80586,0.02155,-0.09474],[0.00216,-0.01464,-0.02136,-0.1192,-0.24313,0.13417,-0.01639,0.03025,-0.0418,-0.37301,0.09378,-0.01823,0.18222,0.01976,-0.01411,-0.01765,0.11795,-0.0958,-0.06342,-0.05969,-0.12059,0.0287,-0.00837,-0.01883,-0.15821,0.00668,0.00625,0.12088,0.03116,0.79014,-0.02529,-0.1029],[-0.02253,0.15179,-0.04763,-0.12479,-0.03218,0.04459,0.05401,-0.06378,0.01514,-0.35671,0.01011,0.06487,0.03749,-0.17759,-0.09,0.03409,-0.01825,-0.20474,-0.05353,0.00253,0.03355,-0.05156,0.07389,-0.03396,-0.01975,0.04166,-0.08287,-0.04948,-0.24281,0.78895,0.05241,-0.15332],[0.00714,0.03194,0.05486,-0.16552,-0.08623,0.18229,0.03546,0.01695,-0.00334,-0.37501,0.00148,-0.12381,-0.04573,-0.02112,-0.00441,-0.06561,0.08342,-0.05334,-0.09213,0.04779,-0.02346,0.02053,0.02858,-0.06039,-0.20573,-0.06512,-0.03005,0.03194,0.01095,0.82659,-0.06598,0.03528],[-0.14266,0.19716,0.07005,0.0528,-0.00484,-0.0508,-0.06198,-0.00586,0.07425,-0.3095,-0.09562,0.0259,-0.00838,-0.17383,0.02515,0.07248,-0.00547,-0.26483,-0.09463,-0.14388,-0.00288,-0.02145,0.10668,0.01057,-0.15929,-0.04494,-0.05953,-0.07101,-0.21973,0.75704,-0.03115,-0.09586],[-0.0569,0.1291,0.00009,0.00171,-0.08762,0.02395,0.01391,0.07773,-0.07662,-0.33193,-0.05356,0.04908,-0.01172,-0.16019,-0.09508,-0.0485,0.03027,-0.16085,-0.03825,-0.01756,-0.03496,-0.09491,-0.12309,-0.14878,-0.16939,0.1181,-0.05357,0.00721,-0.20497,0.79955,-0.0433,-0.04784],[-0.05588,0.05993,0.09622,-0.03904,-0.10641,0.00447,-0.01167,-0.10779,-0.03999,-0.22183,0.01737,-0.14658,0.09842,-0.08321,-0.08816,0.01824,-0.07553,-0.2709,-0.03955,-0.01046,0.07561,-0.07098,0.0092,0.03591,0.05245,0.0459,0.01875,-0.12468,-0.13979,0.83458,0.01325,-0.17948]]3QUESTIONS = ["I bought headphones 9 days ago and opened them. Can I return them?","I paid cash on delivery. When will my refund come?","My cart is Rs 250 and I'm a Plus member. Is delivery free?"]4QUESTION_VECTORS = [[0.0435,-0.02923,-0.08856,-0.08893,-0.11312,0.01847,0.06905,0.06601,0.02419,-0.3083,-0.05278,-0.08758,-0.01526,-0.09804,-0.04356,0.09143,0.1677,-0.0808,0.05904,-0.00783,-0.11459,0.17761,0.01947,0.08692,-0.03501,-0.06436,-0.16525,-0.00152,-0.06491,0.80899,-0.17808,-0.13845],[-0.0095,0.12628,0.01927,-0.06922,-0.07158,0.00545,0.02412,0.14117,0.04924,-0.3942,-0.08629,0.00171,-0.06247,-0.00339,0.02867,0.14461,0.15046,-0.04685,0.01818,-0.12048,-0.11619,0.04872,-0.00633,-0.02983,-0.17879,0.06958,-0.17282,0.01964,0.05666,0.79471,-0.05501,-0.02958],[0.04905,0.11622,-0.03945,-0.17821,-0.08071,0.0957,-0.06091,-0.10657,0.04656,-0.32617,0.05489,-0.14225,0.08318,-0.20348,-0.00105,0.10728,0.02036,-0.19137,-0.04707,-0.10261,-0.15358,-0.08039,0.01358,0.03755,-0.07798,-0.12258,-0.17669,-0.01532,-0.20108,0.74134,-0.03433,-0.05673]]