Skip to content

< all problems116 · Level 04, Tool Calling

Return a Search Reply That Fits the Context

medium · implement · Tool Calling

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.

  1. Match records whose title contains query (case-insensitive), whose status equals status, and whose updated date is on or after since (ISO strings). A filter of None is off. Order the matches newest updated first, ties by id ascending.
  2. Concise results are {"title", "status", "customer", "updated"}, where customer is the name NAMES (provided) gives for the record's customer_id: no ids. Detailed results are the whole record plus customer and assignee, the names for customer_id and assignee_id.
  3. A page starts at offset cursor (a string; None means 0) and holds up to page_size matches.
  4. The reply is {"results", "total", "next_cursor"}. total counts every match. next_cursor is the offset of the first match after this reply's results, as a string, or None when there is none. When next_cursor is set, add "note": "Showing {n} of {total} results. Add a status or since filter to narrow it.", with n the number of results in this reply.
  5. The cap. While reply_tokens(reply) (provided) is over max_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.