# How does an AI read a file?

Silent picture master · 10:00 · 24 fps. Each row begins on its visual cue. Record at a conversational pace and leave the remaining beat for viewers to read.

The Python excerpts come from the project. The terminal reconstruction runs the actual scripts against local replay responses. The IDs in the film are illustrative. The three-word reply is from the earlier rehearsal.

## 00:00 to 00:30 · How does an AI read a file?

| Time | Picture cue | Suggested narration |
| --- | --- | --- |
| 00:00 | A writing workshop begins with a packing list. | What should I bring to a writing workshop? I’d trust a language model to suggest a few things worth packing. |
| 00:10 | The room assignment is a different kind of question. | Now imagine I’m standing in the hallway. I have my notebook. Which door should I walk through for today’s Trailnotes workshop? |
| 00:20 | The organizer keeps the answer in workshop.txt. | The organizer wrote the answer in a file on my laptop. Let’s build the piece of a coding agent that can check it. |

## 00:30 to 01:00 · A question the model can answer

| Time | Picture cue | Suggested narration |
| --- | --- | --- |
| 00:30 | Training gives the model patterns it can use to write. | A language model learns patterns from text and code during training and uses those patterns, together with your input, to generate a response. |
| 00:40 | Send the question through the Responses API. | For a question about packing, that goes a long way. People bring drafts to workshops because they want somebody to read them. |
| 00:50 | The packing advice comes from a general question. | In our earlier rehearsal the model suggested bringing a draft, something for taking notes, and a question for the readers. |

## 01:00 to 01:30 · Make one request

| Time | Picture cue | Suggested narration |
| --- | --- | --- |
| 01:00 | curl sends a request to the Responses endpoint. | Here’s how that question gets to the model. Curl is a little program that sends a request to a web address. |
| 01:10 | The key stays in an environment variable. | The address belongs to OpenAI’s Responses API. The authorization line reads a key from a variable in the terminal. |
| 01:20 | The first request contains a user question. | The body names the model and gives it the question. We can send that first request with just a user message. |

## 01:30 to 02:00 · Give the app a voice

| Time | Picture cue | Suggested narration |
| --- | --- | --- |
| 01:30 | The user wants a packing list. | A system prompt is an instruction our program supplies to tell the model how to respond. Let’s add exactly one. |
| 01:40 | The developer message sets the reply length. | We’ll put it in a message with the developer role. The app says, “Answer in exactly three words.” The user’s question stays the same. |
| 01:50 | Three words from the earlier rehearsal. | Our rehearsal reply was “Draft, notebook, pen.” Count them. We changed the length of the reply without giving the model any new workshop facts. |

## 02:00 to 02:30 · Move the request into Python

| Time | Picture cue | Suggested narration |
| --- | --- | --- |
| 02:00 | The request lives inside chat.py. | I’d like to type questions into a little program. In chat.py, this block does the same job as our request from the terminal. |
| 02:10 | model selects the model. input carries the messages. | Look at the two names inside the parentheses. Model selects the model. Input carries the messages that we want it to see. |
| 02:20 | Return the answer text to the caller. | Python receives a response object. The last line picks out the answer text so we can print it for the person asking. |

## 02:30 to 03:00 · Keep the keyboard prompt open

| Time | Picture cue | Suggested narration |
| --- | --- | --- |
| 02:30 | Read one question at the keyboard. | Here’s the part that makes the program feel like chat. It waits at You, reads one line and removes extra spaces. |
| 02:40 | An empty line exits. A question runs chat(). | An empty line exits. Otherwise it sends the question through the little function we just saw and prints the answer. |
| 02:50 | The next line starts another request. | Then we’re back at the keyboard. Every line starts a fresh request here. Let’s use that next line for the room question. |

## 03:00 to 03:30 · Ask for a fact on the laptop

| Time | Picture cue | Suggested narration |
| --- | --- | --- |
| 03:00 | The question asks for a particular booking. | Which room is today’s Trailnotes workshop in? Imagine you’re the model. The program gave you its instructions and that question. |
| 03:10 | Look at what the app actually sent. | The organizer’s note is still on my laptop. Which piece of the request would tell you what word was written there this morning? |
| 03:20 | The model asks to see the organizer’s note. | In the rehearsal the model asked for the organizer’s note. That’s a reasonable answer, but I’d like the program to look it up. |

## 03:30 to 04:00 · Offer one tool

| Time | Picture cue | Suggested narration |
| --- | --- | --- |
| 03:30 | Describe the one available function. | We’ll give the model a menu with a single item. Its name is read workshop note. The description says whose note it reads. |
| 03:40 | The description explains what the tool can retrieve. | This is the tool declaration in agent.py. The model receives this description with the question, so it knows what it can ask for. |
| 03:50 | An empty set of properties means no arguments to supply. | The tool takes no arguments. Our Python program already knows which file to open. Asking for the tool is a separate step from running it. |

## 04:00 to 04:30 · Let the model choose

| Time | Picture cue | Suggested narration |
| --- | --- | --- |
| 04:00 | Should the model read a file for packing advice? | Offering the tool gives the model a choice. Think about the packing question again. Does it need a room booking to answer that? |
| 04:10 | The packing question takes the direct path. | For a general question the model can reply immediately. In the direct path, our program simply passes those words back to the reader. |
| 04:20 | The room question can trigger a read. | For the specific room question, our instruction points it to the organizer’s note. It can send a request to run the function instead. |

## 04:30 to 05:00 · Follow one lap

| Time | Picture cue | Suggested narration |
| --- | --- | --- |
| 04:30 | The question travels from the person to the model. | Here’s that choice in motion. We send the question to the model. Watch the dot follow the route for the room question. |
| 04:40 | The model requests a read. Python performs it. | The model requests the tool. Python takes over, opens the file and gets back the sentence the organizer wrote. |
| 04:50 | The result goes to the model, then the answer goes to the person. | Python sends the result back to the model. The next response can answer the person who asked. Now let’s build that lap in code. |

## 05:00 to 05:30 · Build the request inside the loop

| Time | Picture cue | Suggested narration |
| --- | --- | --- |
| 05:00 | Start with the instructions and the question. | In agent.py we start a list called context. The first two entries are our workshop instructions and the question from the user. |
| 05:10 | Add the tool to the request. | Inside a loop we make a Responses request using that list. Notice the new line that offers the workshop note tool. |
| 05:20 | At most three requests, one tool call at a time. | We ask for one tool call at a time. This demo allows up to three requests so there’s a clear stopping point. |

## 05:30 to 06:00 · Read the model’s decision

| Time | Picture cue | Suggested narration |
| --- | --- | --- |
| 05:30 | Inspect the output items for a function call. | The API gives us a list of output items. This line collects the ones whose type is function call. There can also be text. |
| 05:40 | With no tool call, return the text. | If that collection is empty, the answer is already here. Return the response text and we’re done with this question. |
| 05:50 | With a tool call, check which function was requested. | Otherwise, take the call and check its name. The model asked for the note. Python can now run the function we provided. |

## 06:00 to 06:30 · Open the note in Python

| Time | Picture cue | Suggested narration |
| --- | --- | --- |
| 06:00 | The location of the note is defined by the program. | The path in chat.py points from these scripts to demo_project and then to workshop.txt. That’s where the organizer saved the room. |
| 06:10 | Python opens the note and reads its contents. | Here’s the actual file read in agent.py. The word open is Python opening the file on this computer so it can read text. |
| 06:20 | The function returns the text to the Python loop. | The reader limits the amount it reads and returns the contents. At this point Python has the sentence. We still have to send it back. |

## 06:30 to 07:00 · Pack the result for the return trip

| Time | Picture cue | Suggested narration |
| --- | --- | --- |
| 06:30 | Keep the model’s output in the running context. | Back in the loop, Python reads the note. It also keeps the model’s earlier output, including its request to call the tool. |
| 06:40 | Add the tool result to the next request. | Next it adds an item with the type function call output. The output field holds the text Python just read from the file. |
| 06:50 | Use the identifier from the model’s own call. | Look closely at call ID. Python copies that value from the model’s call. The API can match this result to the request that produced it. |

## 07:00 to 07:30 · Match the two ends

| Time | Picture cue | Suggested narration |
| --- | --- | --- |
| 07:00 | Read the identifier on the model’s request. | Imagine two slips of paper. One asks for the organizer’s note. The other carries the answer. Follow the identifier printed on both. |
| 07:10 | Find that same identifier on Python’s result. | On the first slip, the model supplied a call ID. On the second, Python returns that very same ID beside the file contents. |
| 07:20 | The next request carries both sides of the exchange. | The loop sends the updated list through the API again. This time the model has evidence it can quote. Let’s watch the terminal. |

## 07:30 to 08:00 · Read the first room answer

| Time | Picture cue | Suggested narration |
| --- | --- | --- |
| 07:30 | The model requested read_workshop_note(). | This terminal sequence replays the earlier rehearsal with local responses. The Python program really runs. The call IDs shown here are examples. |
| 07:40 | The Python result carries the matching ID and the file text. | On the model line it asks for the note. On the Python line the same ID comes back with a sentence naming the Garden Room. |
| 07:50 | The model answers from the returned note. | Read the last line. That’s the model’s answer to our original question. Keep the question in mind while we change one thing. |

## 08:00 to 08:30 · Move the workshop

| Time | Picture cue | Suggested narration |
| --- | --- | --- |
| 08:00 | Select the room in the organizer’s note. | Here’s a disposable copy of the organizer’s actual file. Select just the room name. What would happen if the organizer moved the workshop? |
| 08:10 | Replace the room name and save. | Replace Garden Room with Map Room. Save the note. We’ve given the program a new fact by editing an ordinary text file. |
| 08:20 | Predict the next answer before the rerun. | Take a moment and predict the final answer. The next command runs the same agent with the same question and the same model. |

## 08:30 to 09:00 · Ask exactly the same question

| Time | Picture cue | Suggested narration |
| --- | --- | --- |
| 08:30 | A fresh run produces a new call ID. | We start a fresh run. The model requests the note again, and this new call has its own identifier. |
| 08:40 | The new tool result names the Map Room. | Follow that identifier down one line. Python has opened the saved file. This time its result contains the words Map Room. |
| 08:50 | The last terminal line is the answer. | The final reply says today’s Trailnotes workshop is in the Map Room. You can point to the exact line where that information came in. |

## 09:00 to 09:30 · Compare what entered each request

| Time | Picture cue | Suggested narration |
| --- | --- | --- |
| 09:00 | First run: the Garden Room note. | Put the two runs side by side. First the organizer’s sentence said Garden Room. Later it said Map Room. |
| 09:10 | Second run: the updated Map Room note. | The model had the same question both times. You can trace each answer back through its own call ID to the corresponding file read. |
| 09:20 | Each answer follows the evidence from its own run. | That’s a test you can run yourself. Pick another room name, save the file, and predict what the next execution will print. |

## 09:30 to 10:00 · Take it back to coding

| Time | Picture cue | Suggested narration |
| --- | --- | --- |
| 09:30 | A source file can supply evidence in the same way. | A workshop note is one small example. A coding agent can ask for a source file to learn what a function actually does. |
| 09:40 | The program brings the text back to the model. | The model chooses when to ask. Python performs the read and returns the text. Then the model uses that text in its reply. |
| 09:50 | The workshop is in the Map Room. | So, which door should we walk through? We can answer from the organizer’s latest note. Today’s Trailnotes workshop is in the Map Room. |
