Build the agent
Read · 1 of 2
The brief
You're building the college help-desk agent. It has a small handbook (six documents) and two tools: search(query) returns the ids of the best matching documents, and read(doc_id) returns one document's text.
The stand-in model searches first, reads the top hit, and answers with the sentence that best fits the question plus a citation like [d1]. If search finds nothing, it says so instead of guessing.
You write the parts that make it work: retrieval (module 6), the tools with error handling (module 3), and the loop with a turn limit (module 4). Every module you've done is in here.
Read this lesson as text
Retrieval as a tool, a reading tool, the loop, and citations.
The brief
You're building the college help-desk agent. It has a small handbook (six documents) and two tools: search(query) returns the ids of the best matching documents, and read(doc_id) returns one document's text.
The stand-in model searches first, reads the top hit, and answers with the sentence that best fits the question plus a citation like [d1]. If search finds nothing, it says so instead of guessing.
You write the parts that make it work: retrieval (module 6), the tools with error handling (module 3), and the loop with a turn limit (module 4). Every module you've done is in here.
Exercise: The help-desk agent
Input: a student's question.
search(query): score every document by cosine similarity of word counts (lower-cased, .,?! stripped, words in STOP ignored), and return the ids of the top 2 with a score above 0, best first, joined by commas (empty text if none).
read(doc_id): the document's text; raise an error for an unknown id.
Run the agent loop (at most 6 model calls). Log each tool call as search: <result> or read: <doc_id>, then print the final answer.