Progress

Level 05 · Agentic

AI Agents

An agent is a program where the model chooses the next step and can call tools you wrote, instead of answering once and stopping. This level teaches that loop: how a plan changes after a result, how tools are described, how a shared plug named MCP connects a tool server, how memory is stored, when to split work across agents, and how a graph keeps state. An AI engineer needs this because many systems look something up or change a file, and because a fixed list of steps is often the safer design.

Assumes You can already search your own notes or documents and use the matching passage to answer a question in code. · 22 study sessions · 10 modules

0 of 89 lessons0%

Ship it

Capstone: Build a Production-Style Agent

You will build one agent: a program where the model chooses the next step and can call tools you wrote, instead of answering once and stopping. Pick one of three builds and finish that one. A research desk plans a question, gathers notes, and writes. A tool server exposes a real file or table, and an agent calls it. A code agent writes a script and runs it in a locked-down folder.

You are done when one recorded task shows the model deciding after a tool result, the saved state printed on screen, a stop rule that fires, and one action that waits until you approve it. Use a stub model or any free chat window. Do not buy a key to finish.

  1. 1. Choosing a substantial project

    1. Open a note named spec.txt and pick one build: research desk, tool server plus agent, or code runner.
    2. Write the person it helps, the input they type, and the sentence that means done.

    3. Write two side effects the agent must not perform alone, such as deleting a file or sending a message.

    4. Done when spec.txt has those four pieces and you have not started the loop yet.

  2. 2. Planner → Researcher → Analyst → Writer

    1. If you did not pick the research desk, write "not this build" in this step's note and move on.
    2. Open research_roles.txt and write four instruction paragraphs: planner, researcher, analyst, and writer.

    3. Give the researcher the only retrieval tool. Give the writer no retrieval tool.

    4. State that each role receives the previous artifact, not the full transcript.

    5. Done when all four paragraphs exist and only the researcher is allowed to look things up.

  3. 3. Dynamic planning, state & retries

    1. If this is not the research desk, write "not this build" and stop this step.
    2. Open desk_state.py and type a dict with a plan list and a notes list.

    3. When a fake source contradicts a plan item, mark that item canceled and add a replacement.

    4. Stamp each note with a source id. Have the writer function refuse to cite an id that is not in notes.

    5. Done when a run prints a canceled item and a refusal for a made-up source id.

  4. 4. A server plus an agent that uses it

    1. If you did not pick the server build, write "not this build" and move on.
    2. Create a real backend: a SQLite file, a folder of text files, or a tiny local HTTP response from Python's standard library.

    3. Expose at least two tools, such as list_items and read_item, that read that backend.

    4. Type an agent loop that must call both tools before it answers. If you ever listen on the network, require a token.

    5. Done when a printed trace shows both tool names and the answer text came from the backend, not from a hard-coded sentence.

  5. 5. Plan → write → run → inspect → fix

    1. If you did not pick the code build, write "not this build" and move on.
    2. Open code_agent.py. The agent restates the task, writes a script into a temp folder, and runs it as a separate process with a timeout.

    3. Read standard output or the error, change the script once, and run it again.

    4. Do not call exec in the parent process. Stop after two tries.

    5. Done when the terminal shows the script's printed result and a bad snippet cannot run a third time.

  6. 6. Capstone requirements

    1. Open checks.txt and copy the remaining requirement titles as a checklist for the build you picked.
    2. For each line, leave a blank where you will paste a file name or a log line.

    3. If a requirement cannot fit the domain you picked, change the domain now rather than deleting the requirement.

    4. Done when every later requirement has a blank line waiting, and none are marked skipped.

  7. 7. At least three useful tools

    1. In your project, register at least three tools the task actually needs. Each needs a name, a one-line description, and a dict of required fields.
    2. Reject a call in code when a required field is missing.

    3. Make at least one tool read a real file, a local HTTP response, or a database, not a hard-coded string.

    4. Run one task that uses two different tools and save the printed trace.

    5. Done when the trace shows two tool names and a third tool exists in the registry even if this task did not need it.

  8. 8. Multi-step autonomous execution

    1. Use a stub model, or paste the current trace into any free chat window and ask only for the next tool name or the word final.
    2. After each tool result, choose the next action from that result. Do not hard-code the three actions in order.

    3. Save a trace with at least three decide-then-act cycles before the final answer.

    4. Done when the trace shows three choices and you can point at a line where the second choice used the first result.

  9. 9. Explicit state

    1. Put the plan, tool results, and any ids on one dict or one object your loop passes every turn.
    2. Do not leave those facts only inside a paragraph in the transcript.

    3. Print the state after the second step of a real run.

    4. Done when the printed state shows a plan or a tool result that is not only buried in a message string.

  10. 10. Stopping conditions

    1. Stop the loop on a final answer, on a maximum step count, and on a repeated tool call with the same arguments.
    2. Print which condition fired.

    3. Point a stub at the loop that always requests the same tool and arguments.

    4. Done when that stub run prints a halt reason and exits, instead of running on.

  11. 11. Failure recovery

    1. Teach one tool to fail once with a retryable error, then succeed when the argument changes.
    2. On a retryable error, change the argument or switch tools once.

    3. On a permanent error, stop and attach the error payload. Do not let the exception kill the process.

    4. Done when one demo shows a failure followed by success, or a clean escalation object, and the process exits on purpose.

  12. 12. Logs & progress visibility

    1. After each step, print a line with a timestamp, the tool name, and a short result.
    2. Keep secrets and raw arguments behind a debug flag that defaults to off.

    3. Run the demo and read those lines in the terminal.

    4. Done when you can narrate the run from the progress lines without opening a debugger.

  13. 13. A human approval point

    1. Pick one consequential action, such as write, delete, or send, and pause before it.
    2. Continue only when an approve flag is set by your code or by a typed yes, not by the model text.

    3. Run once with no and once with yes.

    4. Done when no performs zero side effects and yes performs the action once.

  14. 14. One framework, explained from first principles

    1. Keep the finished agent in one style: a hand-written loop or one library. Do not mix three frameworks.
    2. Open explain.txt and write what is read, what action is chosen, what is stored, and what stops the run.

    3. Next to each sentence, name the object in your code, such as a dict, a node, a tool schema, or a handoff.

    4. Done when a reader can match each sentence to a name in the source without marketing adjectives.