Skip to content

< all projects26 steps · medium · Rebuild

Build a research agent that writes a cited report

You will have built a research agent, one function at a time, and watched a real model answer a question from a pile of company notes with a report whose every sentence cites a source: 6 functions that index and search the notes, 4 that turn the question into sub-questions, 5 that run researchers in parallel under a budget and merge what they found, 6 that write and parse a report with numbered citations, 3 that check every citation and every quote, and 2 that run the loop and fix what the check rejects. Each step is a few lines with its own tests, and the earlier functions are provided to the later ones. The notes are handed to you, and so is `model`, with one method, `chat(messages, tools, system, max_tokens)`. It is real: the steps that call it check what it did (the plan has the right shape, a quote is really in the note, every sentence ends in a citation) and spend a little of your credits. The point of the project is the shape around the calls. The planner proposes and the budget disposes. A researcher may cite only what it was shown, and a quote it invents is dropped in code. The writer sees findings, not notes. The checker holds the report to a rule a model cannot talk its way around: either the words are in the note or they are not. When every step has passed, the six files assemble into one agent, and you can ask it a question, live, and read the report it writes with its sources.

Start: Cut a word to its stemSign in to run steps and keep your progress.
  1. Part 01 · 6 steps

    Find the notes

    A keyword index over the corpus, and the search the researchers use.

    1. 01Cut a word to its stemnext
    2. 02Turn text into search terms
    3. 03Build the index
    4. 04Score the notes for a query
    5. 05Show where it matched
    6. 06Search
  2. Part 02 · 4 steps

    Plan the research

    A real model splits the question into sub-questions you can trust.

    1. 07Read the text out of a reply
    2. 08Read a list the model wrote
    3. 09Drop the near-duplicates
    4. 10Plan with a real model
  3. Part 03 · 5 steps

    Researchers

    Workers that read notes and return findings with quotes, in parallel, under a budget.

    1. 11Read a researcher's findings
    2. 12Brief a researcher
    3. 13One researcher, on a real model
    4. 14Researchers in parallel, under a budget
    5. 15Merge what came back
  4. Part 04 · 6 steps

    Write it up

    A report with numbered citations, parsed and renumbered.

    1. 16Number the sources
    2. 17Brief the writer
    3. 18Split the report into sentences
    4. 19Read the citations in a sentence
    5. 20Renumber by first use
    6. 21Draft the report on a real model
  5. Part 05 · 3 steps

    Check it

    Every sentence has a source, and every quote is really in the note.

    1. 22Find the sentences with no source
    2. 23Is the quote really there?
    3. 24Grade the report
  6. Part 06 · 2 steps

    The loop

    One pass that plans, researches, writes, fixes and stops.

    1. 25Send the bad sentences back
    2. 26The whole agent