liveBook · Manning

File reading and writing

As explained in Build an AI Agent (From Scratch)

File reading is a tool capability that retrieves content from files available to an agent.

File reading gives an agent access to information that is unavailable in model training data. When a user attaches a spreadsheet or document, the agent must retrieve the file rather than guess from prior knowledge. section 2.4.3

The minimal implementation adds a file-reading tool to the agent loop. For a small file, the tool reads the complete contents and places them in the model context, allowing the model to answer questions about the data. section 5.1.1 section 1.5.6

Use file reading when:

  • The question depends on an attached spreadsheet or document. section 2.4.3
  • The file is small enough for its complete contents to fit in the context window. section 5.1.1
  • The agent needs an external capability alongside web search or calculation. section 2.4.3

Finding the highest-sales month

Given a CSV file and the question “What month had the highest sales in this data?”, the agent reads the file, places its contents in context, and uses that information to answer. section 5.1.1

Table 2.2 Required capabilities for unsolvable problems

Missing capability

Count

Web search and web page access

11

File reading

6

Compare file reading with web access as a missing capability in unsolvable benchmark problems. section 2.4.3

How Build an AI Agent (From Scratch) covers it

How deep it goes
Explains whole-file loading for small CSVs and stops short of detailed parsing or large-file retrieval strategies.
Examples
Uses attached spreadsheets, documents, and a CSV sales question asking which month had the highest sales.
What it assumes
Assumes an agent loop and tool invocation while establishing attached-file access as a missing capability.
What you can do after
Apply it via a file-reading tool that loads a small attached file into the agent’s context.
How it connects
Connects file reading to tool use, agent loops, web search, calculation, and retrieval-augmented generation.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build an AI Agent (From Scratch). The section links point to the parts of the book it draws on.