Skip to content

A1: Read a coding-agent session

At a glance

  • Task: record the requests a real coding agent sends to its model during one short session, force one safe failure, and label what you observed or inferred.
  • Week: 1
  • Weight: 2.5 points
  • Due: Sunday 23:59 in the listed week
  • Hand in: one report.json, the capture summary and the excerpts the report cites. The capture log itself stays private.
  • Done when: all of the following hold. The report names the capture method. From the capture, it gives the number of model requests, the size of the system prompt and the tools grouped by kind. Every behaviour is labelled observed or inferred and points to an excerpt or command output. The forced failure is real and explained. check.py then confirms only the shape of the record.
  • Time: published after a timed pilot; record your prediction and actual time.

Objectives

Explain an agent's system instructions, tools, loop and stopping condition from the requests it actually sent (LO1). Separate a line visible in the capture from an explanation you infer from it.

Prerequisites

Follow the course safety practices:

  • Run the agent in a dedicated directory or container.
  • Keep residency, employer and cloud credentials out of that environment.
  • Keep keys out of repositories, prompts, screenshots and logs.
  • Run injection demonstrations offline against the local machine only.

Use the mature coding-agent seat supplied for the course. Do not run an unknown generated command on a credential-bearing host. Treat the capture log like a file that holds credentials until you have checked it, as the setup page describes.

Record the requests

A transcript shows what the agent chose to display. The request shows what it sent: the system text, the tool definitions and every message so far. The course supplies a small recorder, recorder.py in this folder, to capture it. The recorder uses only Python's standard library. It runs on your own computer, between your agent and the model service. It listens on 127.0.0.1 only. It passes every request and reply through and writes the JSON bodies to a log in a directory you name. It never writes headers, because headers are where a key or sign-in token is normally sent. It also replaces strings that look like keys or tokens, such as sk- keys and Bearer tokens, with [REDACTED]. It refuses to write its log inside a Git repository.

1. Check the recorder. From the course checkout:

python practice/a1/recorder.py selfcheck

Expected output:

PASS: requests and their Authorization header reached the upstream unchanged
PASS: responses reached the agent unchanged
PASS: no request or response header in the log
PASS: planted sk-EXAMPLE and Bearer token replaced by [REDACTED]
PASS: refuses to listen on 0.0.0.0
PASS: refuses a log directory inside a Git repository

Capture: selfcheck.jsonl
Exchanges recorded: 2; requests with messages: 2
seq  method  path                  status  system chars  messages  tools
  1  POST    /v1/chat/completions     200           165         2      3
  2  POST    /v1/chat/completions     200           165         4      3
Credential-like text left: none found
Personal data to leave out of excerpts: none found

Exchange 2: POST /v1/chat/completions
Status: 200
System text: 165 characters in 1 part(s)
Messages: 4 (system 1, user 2, assistant 1)
Tools offered: 3
  read_file    function
  edit_file    function
  run_command  function

The self-check sends two requests written by the course through the recorder. The requests contain a planted sk-EXAMPLE key and Bearer token. They go to a fake model service on 127.0.0.1, and the self-check connects nowhere else. The table and the last block show the summary that you will later run on your own capture. If any line says FAIL, stop and ask for help. Do not record a real session with a recorder that fails.

2. Start the recorder. You need the agent's usual API base URL. Look in the agent's own documentation for a setting that sends model requests to a custom endpoint, gateway or proxy, and for the base URL it uses when that setting is empty. Open a second terminal in the course checkout. Run this command, with https://api.example.com replaced by that base URL:

python practice/a1/recorder.py record --upstream https://api.example.com --log-dir ../a1-capture

../a1-capture is a folder beside the checkout. It is inside your dedicated directory and outside every repository. The recorder prints the path of the new log file and the address to give the agent, http://127.0.0.1:8765, then waits. Leave it running.

3. Point the agent at it. Set the agent's base-URL setting to http://127.0.0.1:8765, with nothing after the port, and leave its sign-in as it is. Start the agent and work through the task. The recorder prints one line per exchange, such as #1 POST /v1/... -> 200. If the agent replies but no line appears, the agent did not use the setting. Stop and use the fallback. When the session ends, press Ctrl+C in the recorder's terminal and remove the setting again.

4. Count from the capture. Replace capture-TIMESTAMP.jsonl with the file name the recorder printed:

python practice/a1/recorder.py summary ../a1-capture/capture-TIMESTAMP.jsonl

The summary prints no message text. It gives one row per exchange. Each row shows the characters of system text, the number of messages and the number of tools in that request. After the table, it scans the log. The requests with messages are the model requests you count. If their rows differ, the agent sent requests for more than one purpose. Choose the request that carries your task, and say why in your explanation. Then list that request's tools. This example lists them for exchange 1:

python practice/a1/recorder.py summary ../a1-capture/capture-TIMESTAMP.jsonl --request 1

Read each tool's description in the log, then group the tools by what they do:

Kind Tools that
read read, list or search files
edit create or change files
run run commands or tests
plan keep a plan or a to-do list
delegate hand work to another agent
web fetch or search web pages
mcp come from an added MCP server
other do anything else; name them in your explanation

Where a tool fits two kinds, choose one and say why. Put both summaries in your submission directory, for example as capture-summary.txt, and cite that file for the counts.

5. Check before you cite. The last two lines of the first summary report any credential-like text and any personal data, such as a home directory path. They also name the exchange that holds it. The recorder cannot recognise every key format, so read each excerpt line by line before you copy it into your submission. Never hand in, upload or screenshot the log itself.

If the agent cannot use the recorder

The agent may have no base-URL setting, refuse a plain http://127.0.0.1 address or send nothing through the recorder. If so, write down what you tried and what happened. Then use one of the options below, in this order. You still run the session with your own agent and keep its visible transcript.

  1. The agent's own log (agent_log). If the agent can write a session record or a debug log that includes its requests, count the requests, measure the system text and list the tools from that file. Say which file you used and what it leaves out. Treat it like the capture log.
  2. A pinned open-source agent (published_source). Read the system prompt and tool definitions of one of the open-source agents pinned in the Week 1 readings. Save the prompt text you read and measure it with wc -m. Count the tool definitions you find and name the files. These files describe that project, not what your session sent. So every claim they support about your own agent is inferred. Give your session's request count if your agent shows it, or null.

Tasks

  1. Predict. Before starting, write how many model requests you expect, and which request, tool call or stop condition you expect to be easy to misread.
  2. Record. Check the recorder, start it and point the agent at it. If that does not work, choose the fallback and write down why.
  3. Generate. Ask the agent to make a tiny, reversible change in a disposable repository. Keep the visible transcript as well as the capture.
  4. Count. From the capture, record the number of model requests, the size of the system prompt and the tools grouped by kind.
  5. Verify. Run the repository check yourself and save its output. Label each behaviour observed or inferred, with an evidence ID.
  6. Force failure. Change one safe input or deny one permission so the agent receives a real failure. Do not fabricate an error. Record the recovery or the reason it stopped, and find the request that carried the failure back to the model.
  7. Revise. After feedback from a peer or the teaching team during the assignment week, correct one label or explanation. In your explanation, record who gave the feedback and the date. If no feedback was available, record the date of your own review instead. Then finish the decision line.

Generation is the change the agent proposes. Verification is your own evidence: your command output, the capture and your inspection of the files. The supplied check.py checks only the shape of the record, so read every cited file yourself.

Deliverables

Copy starter/report.json to report.json in a submission directory of your own outside the course checkout. Include the capture summary, the excerpts the report cites, the forced-failure output, and one AI-use note ID. Keep only lines that matter for the task. Remove keys, personal data and unrelated source code. Do not include the capture log.

The report must include assignment, session_kind: "real", an agent description, a capture record, behaviour rows, a forced-failure record, evidence rows, an explanation and a decision. The capture record holds:

Field in capture What goes in it
method recorder, agent_log or published_source
reason Why the recorder could not capture this agent; needed unless method is recorder
requests The number of model requests, at least 1; null only with published_source
system_prompt_chars The characters of system text in the request you chose
tools total, and by_kind: the kinds above with their counts, which add up to total
evidence The IDs of the evidence rows that hold the summary or excerpt behind these numbers

Run from the course checkout:

python practice/a1/check.py path/to/submission

Grading

The published criteria are:

  • counts and tool kinds that match the cited summary or source;
  • accurate observed/inferred labels;
  • a genuine, reproducible failure, with an honest explanation of the recovery or the stop;
  • evidence that another reader can inspect;
  • a useful revision.

The local check gives public feedback only. It does not assign marks, and it does not prove that the session was real.

AI use rules

Green: the agent may propose the disposable change and help format notes. Yellow: you may ask it to suggest labels, then verify every suggestion yourself. Red: the prediction, tool kinds, observed/inferred labels, failure interpretation and decision must be your own. Attach one AI-use note ID.

Estimated time

Published after a timed pilot. Record your predicted and actual time in the report. Ask for help if you cannot reproduce the safety boundary, the recorder or the failure.

Work record outline

assignment: A1
session_kind: real
agent: TODO
capture: {method: recorder | agent_log | published_source, reason: TODO (unless recorder),
          requests: TODO, system_prompt_chars: TODO,
          tools: {total: TODO, by_kind: {read: TODO, edit: TODO, ...}}, evidence: [TODO]}
evidence: [{id: TODO, path: TODO, observation: TODO}]
behaviours: [{behaviour: TODO, label: observed|inferred, evidence: [TODO]}]
forced_failure: {intervention: TODO, evidence: [TODO], recovery_or_stop: TODO}
prediction: TODO (written before you start)
explanation: TODO
ai_use_note: TODO
predicted_time: TODO
actual_time: TODO
decision: {action: accept | narrow | recheck | stop, because: [evidence ID(s)], next: TODO}

The outline lists the fields of report.json in plain text. starter/report.json holds them as JSON, except prediction, predicted_time and actual_time, which you add yourself. Evidence paths are relative to your submission directory. The check reads a field that still contains the word TODO, or text in angle brackets such as <name>, as unfilled.