A research agent is a loop with three tools and two things that must not live in the prompt: the budget that stops it, and the check that every citation points at a page it actually read. Put those in the prompt and they are suggestions. Put them in code and the agent is something you can leave running.
The loop, and where the budget goes
The loop itself is small. Every agent is the same loop: call the model with the conversation and the tool definitions, if it asks for a tool run it, append the result, repeat until it answers or you stop it.
# agent.py
MAX_STEPS = 8 # model turns






