14 Prompting agents I: giving context
The same principle of attaching data and domain knowledge applies when the question is “which statistical method?” — we’ll come to that in Section 3. It applies just as strongly once you’re running a multi-step agent — arguably more so, because an agent that’s missing context won’t just give you a mediocre answer, it’ll go and implement a mediocre answer across several files. The broader literature on prompt engineering makes the same case for supplying context deliberately rather than hoping the model infers it (Chen et al. 2025).
14.1 Attaching data summaries
Large datasets can be awkward to attach directly — they eat up the context window. Some agents (Copilot’s agent mode included) will automatically truncate a large data frame if you attach it, but it’s more reliable to ask the agent to generate its own summary first:
Write a script that creates a smaller version of the benthic data that has only the first six rows of data
Then attach that small summary (or the metadata readme) to your actual analysis prompt.
14.2 Attaching domain knowledge
If you’re emulating a specific paper or method, convert it to markdown and attach it — a webpage tool like Jina Reader works well for this. Package vignettes and stats tutorial blogs are also good sources; keep a running list handy for when you need them.
Be careful with anything you didn’t write yourself before attaching it to an agent session — check it doesn’t contain hidden instructions. More on why in Section 4.
14.3 Writing a metadata summary with the agent itself
You can get the agent to help write this context, rather than writing it all yourself:
Write a summary of the meta-data for this database in a new markdown file [attach the csv]
Read over what it produces and correct anything wrong before you rely on it — an inaccurate metadata file is worse than none, because it’ll confidently mislead every subsequent agent session that reads it.
Ask an agent to write a metadata markdown file summarising fish-coral-cover-sites.csv, then check it against the real metadata readme. Note anything it got wrong or left out.