Return a Search Reply That Fits the Context
An agent's search tool that returns every field of 240 tickets fills the context the agent needed for its next step. Implement search_tickets(records, query="", status=None, since=None, response_format="concise", cursor=None, page_size=10, max_tokens=400), which returns the tool's reply as a dict.
- Match records whose
titlecontainsquery(case-insensitive), whosestatusequalsstatus, and whoseupdateddate is on or aftersince(ISO strings). A filter ofNoneis off. Order the matches newestupdatedfirst, ties byidascending. - Concise results are
{"title", "status", "customer", "updated"}, wherecustomeris the nameNAMES(provided) gives for the record'scustomer_id: no ids. Detailed results are the whole record pluscustomerandassignee, the names forcustomer_idandassignee_id. - A page starts at offset
cursor(a string;Nonemeans 0) and holds up topage_sizematches. - The reply is
{"results", "total", "next_cursor"}.totalcounts every match.next_cursoris the offset of the first match after this reply's results, as a string, orNonewhen there is none. Whennext_cursoris set, add"note": "Showing {n} of {total} results. Add a status or since filter to narrow it.", withnthe number of results in this reply. - The cap. While
reply_tokens(reply)(provided) is overmax_tokens, drop the last result and rebuild the reply, but always keep the first result, even when it alone is over the cap.
The catch. After the cap drops results, next_cursor points at the first one dropped, not at the next page. A cursor of cursor + page_size skips them, and a model that pages through every result never sees them.