When an agent reads a document for you, something has to name that document. The obvious choice is the identifier the database or the provider already uses: an attachment’s UUID, or a SharePoint drive id and item id. A tool returns it, the model passes it back to the next tool, and the work continues.
In Summa the model never handles those identifiers. Every file, passage and Microsoft 365 item a tool shows it gets a short label that only means something inside one run — att1_c3 for a passage, doc1 for a whole document, ms3 for a live Microsoft file. The real identifiers stay on the server. This essay explains why, and what that one decision ended up carrying.
What goes wrong with real identifiers
Suppose a tool hands the model 3f2a…c91 for a contract PDF. From then on that string is just text in the model’s context, and text can come from anywhere. The model can copy an identifier from an earlier turn. It can lift one from a document it was asked to summarise, where someone planted it. It can make one up. Each of these reaches the next tool looking the same as a legitimate one.
So every tool that accepts an identifier now has to answer, alone, “may this person, in this conversation, touch this object?” Miss that check once and the agent is a confused deputy: it holds the user’s authority and spends it on whatever the text in front of it names.
Citations have the same problem. If the model writes the source behind a footnote — a URL, a file name, “page 17” — the footnote is a claim like any other sentence it writes. It can be wrong, and the reader has no way to tell.
Labels instead of identifiers
The fix is to make the model’s vocabulary small and give it meaning only on the server. When search_attachments returns a passage, it mints a label and keeps the mapping:
ctx.state.attachment_ref_counter += 1
ref = f"att{ctx.state.attachment_ref_counter}_c{chunk.chunk_index}"
ctx.state.attachment_refs[ref] = (chunk.attachment_id, chunk.chunk_index)
Whole documents get docN, and live Microsoft 365 files, folders, sites and lists share one msN namespace. Their drive, item, site and list ids are stored in a tenant-isolated table, never in the model’s context. A label is stable within a run: the same file found by search and then seen again in its folder keeps the same label.
Tools that act on resources resolve labels through a ResourceResolver, which the code describes as “Resources a run may use, supplied only by backend preparation”. Its resolve method looks a string up among the opaque references this run was given, and nothing else — in the code’s words, “raw provider ids do not work.” A string the run was never given doesn’t resolve. It doesn’t get as far as a permission check, because there is nothing for one to check.
That failure needs to be useful to the model too. An unknown reference raises UnknownResourceRef, which tells the model which labels it can use, by label and file name: “Pass one of these refs, not a file name.” The model gets back on track without ever being shown an identifier.
A citation is a lookup, not a claim
The model cites by writing a marker such as [[cite:att1_c3]]. Before the answer reaches the reader, the runtime replaces each valid marker with a number and removes the rest. A marker is valid only if its label is in one of the run’s own source tables: web results it fetched, passages and documents it read, live resources it found. A label from another conversation, an invented one, or a malformed marker simply disappears rather than reaching the reader as raw [[cite:…]] text.
What the reader sees behind [n] comes from the stored row, not from the model. The function that builds it says so directly:
Built from the run’s own source tables rather than from anything the model wrote: the model supplies a ref and nothing else, so a citation can never point somewhere it invented.
For a document passage, the position shown — a page, a section, a character range — is the locator recorded when the file was split into passages, “never a page number the model typed.” The preview behind the chip is capped at 400 characters, and the citation drawer reads the full text live, under a fresh authorisation check.
Not everything the run found can be cited. A SharePoint site or a folder is somewhere to look, not something that supports a claim, so only Microsoft files and lists are citable. The design note puts it in five words: a place is not evidence.
Streaming without showing the machinery
Answers stream token by token, so a marker often arrives in pieces: [[cite in one delta, :ws1_p0 in the next, ]] after that. Emitting each piece as it came would show the reader stray brackets that then disappear.
The streaming layer holds back any tail that could still grow into a marker. That tail is matched by PARTIAL_CITATION_MARKER, a regular expression anchored at the end of the buffered text that accepts every prefix of [[cite:ref]]. Text before the tail is released normally. The tail waits for the next delta. One of the tests feeds exactly that sequence: the first two deltas emit nothing, and the third emits As shown [1] it works.
There is one deliberate gap. If the model stops in the middle of a marker, the held tail is flushed as literal text at the end. We prefer showing a few stray characters to silently swallowing whatever the model wrote last.
Surviving a pause
Labels live in the run’s scratch memory, which is rebuilt every time the agent loop starts. That turned out to matter when a run pauses to ask the user a clarifying question. The resumed turn replays the same transcript, so the model still reads [att1_c3] in its own history while nothing behind it resolves.
The code records what that cost before it was fixed. Citations to anything found before the question “silently dropped at finalisation — the answer was right and its footnote simply never appeared.” Asking to widen one of those passages came back unknown_reference, wasting a tool call and a second search.
The labels now go into the run’s checkpoint, which exists for exactly this: what a paused turn needs to continue. Only identity is stored — which file, which passage — and the label counters, so new labels continue rather than restart. The citation snapshot itself is rebuilt from the database rows on resume. Storing the passage text instead would have put every passage the run read into a JSON column, and let the snapshot drift from the row it claims to quote.
Access is checked again, not assumed. A file’s permissions can change while a question waits for an answer, so on resume every restored label goes back through may_read_attachment. Anything it now refuses is dropped, “exactly as if the search had never found it.” The same happens to a file that was deleted, or re-processed into different passages, while the question waited.
Files found mid-run: a new resolver, not a wider one
Preparation resolves what the user attached before the model takes its first turn. But an agent that searches Microsoft 365 mid-conversation finds files nobody attached, and the spreadsheet and presentation tools that could act on one accept a resource reference and nothing else. Without a way in, a workbook the agent found itself could never be read or edited.
The resolver gains those files through including, which returns a new resolver rather than changing the existing one:
prepared = {opaque for opaque, _ in self.opaque_refs}
extra_refs = tuple((opaque, resource) for opaque, (resource, _) in discovered.items() if opaque not in prepared)
extra_grants = tuple(
ResourceGrant(kind=resource.resource_type, ref=opaque, operations=operations)
for opaque, (resource, operations) in discovered.items()
if opaque not in prepared
)
return replace(
self,
grants=self.grants + extra_grants,
resources=self.resources + tuple(resource for _, resource in extra_refs),
opaque_refs=self.opaque_refs + extra_refs,
)
The docstring gives the reason: the resolver “is the run’s authorisation record, and something that can be widened in place is not one.” Discovered entries are only ever appended. They carry the operations the provider allowed when the file was found. A discovery that collides with a prepared label is dropped, never merged, so it can’t re-scope a grant that preparation already decided. A test covers exactly this case: an impostor under the label resource_1 asking for read and write leaves the original resource and its read-only grant unchanged.
Only files are added this way. A folder, site or list is a place to look, not a document to act on.
A synced file is not an open file
Company knowledge can include SharePoint drives that an administrator syncs into the workspace, so their passages sit in the same index as uploaded files. Being synced doesn’t make a file readable by everyone in the workspace. Before any SharePoint-backed passage is returned, may_read_attachment asks Microsoft again, with the reader’s own delegated account, whether they may open that item.
Live Microsoft access works the same way. An msN label means “the backend discovered this,” never “the model owns access to this.” Before a labelled file is read, the tool checks with Graph again — Graph evaluates the caller’s current delegated permission on the item, so the answer is Microsoft’s rather than a cached one of ours. The citation drawer re-checks access before offering the link out to Microsoft 365.
What it costs
- Extra round trips. Every SharePoint-backed read is preceded by an access check against Microsoft. Within a single search the result is cached per file, but it is still a network call on the reading path.
- Labels don’t travel.
att1_c3means nothing in the next conversation. An agent that wants the same passage again has to find it again. - Lost footnotes are silent. When a resumed run drops a label because access was withdrawn or the file changed, the claim stays in the answer and its citation doesn’t appear. That is the correct outcome for authorisation, but the reader isn’t told why.
- More moving parts. Every new kind of source needs its own label scheme, source table, citation view and restore path. Each of those is a place to make a mistake, which is why the restore code ignores malformed checkpoint entries instead of trusting them.
What we would generalise
- Give the model handles, not keys. If an identifier would work outside the run, it shouldn’t be in the model’s context. A label that resolves only against server-side state turns “is this allowed?” into “was this issued?”, which is a much easier question to get right.
- Render provenance from data. Let the model choose which source supports a claim. Never let it write what the source is. URLs, titles and page numbers should come from rows.
- Make the authorisation record immutable. When a run needs more scope, build a new object that is the old one plus clearly bounded additions, and make collisions lose.
- Store identity, re-derive the rest, re-check access. Anything that outlives a pause should be the smallest reference that can be re-validated, not a copy of what it pointed to.
- Treat the provider as the authority. Syncing or indexing a document gives you a copy. It doesn’t give you the right to show it to someone the source system would refuse.