Shaping what tools return to an agent

Ask an agent to summarize a thread, and the thread read is most of what lands in its context. Here is one comment as our Comms read used to return it:

{
  "creator_id": "101",
  "creator_name": "Hermione Granger",
  "posted_at": "2026-11-24T09:12:00.000Z",
  "content": "Quidditch practice moves to Thursday.",
  "content_truncated": false,
  "content_offset": 0,
  "content_length": 37,
  "attachments": [],
  "attachments_truncated": false,
  "deleted": false,
  "reference": {
    "product": "comms",
    "kind": "comment",
    "object_id": "Cm8kQ",
    "workspace_id": "1",
    "channel_id": "Ch3pX",
    "thread_id": "Th7wR",
    "url": "https://comms.todoist.com/1/ch/Ch3pX/t/Th7wR/c/Cm8kQ"
  }
}

The sentence the model needs is one line out of twenty. Multiply that by every comment of a long thread and the context fills with flags that are false, empty lists and IDs the model never uses. Nothing breaks. The run just carries more tokens, and the text that matters is harder to find.

What the articles argue

Anthropic’s Writing effective tools for agents makes three points that apply here. A tool should return high-signal information, not every technical field the backend has. Agents work better with identifiers they can read than with long cryptic ones: replacing long cryptic IDs with meaningful names, or with simple numbered IDs, reduced hallucinated values. And an error should tell the agent what to do next, not just that something failed.

Effective context engineering for AI agents gives the reason. Context is finite, and the model’s recall degrades as it fills, so the goal is the “smallest possible set of high-signal tokens”. It also notes that once a tool result has been used, it often doesn’t need to stay in context.

Agent Core is the service behind the @todoist agent in Todoist, Comms and Automations. None of the changes below started from these articles. They started from answers that went wrong or runs that were too heavy, and the articles describe what we ended up doing.

Return what the model uses

I measured where the bytes came from in our live evaluation. The Comms reads were 98% of the bytes all tools returned, and the message text was only about 15% of that. The rest was metadata.

In agent-core#571, the four Comms reads stopped returning it. The same comment now looks like this:

{
  "id": "Cm8kQ",
  "creator_id": "101",
  "creator_name": "Hermione Granger",
  "posted_at": "2026-11-24T09:12:00.000Z",
  "content": "Quidditch practice moves to Thursday.",
  "deleted": false,
  "reference": { "url": "https://comms.todoist.com/1/ch/Ch3pX/t/Th7wR/c/Cm8kQ" }
}

A flag appears only when it is true. Attachments appear only when there are some. Offsets appear only on a piece of a longer message, where the model needs them to join the pieces. reference keeps only the url, because that is what the answer cites.

Two details mattered more than the trimming. First, the item gained an id. It used to live only in reference.object_id, while the tool description told the model to join pieces by ID. Second, the service itself still needs the IDs we removed: to record which sources an answer used and to check them again before reusing saved history. Those were already returned beside the result, outside the text the model reads, so nothing lost a field.

Identifiers the model can copy

A Comms search result carries a source the model passes to the thread read. It used to be a signed value several hundred characters long. The model copies it from one tool call to the next, and sometimes it doesn’t copy it exactly. The failed reads we traced were each one character off (CfeF1Gmna… for CfeG1Gmna…). The check refused them, correctly, but the model only saw “The tool call failed safely”, so it gave up on the thread.

Here is the call before the change, with the source as the PR shows it, trimmed, and what the read answered when the model miscopied one character:

comms.load_thread {"source": "eyJ0eXBlIjoic291cmNl…"}
→ The tool call failed safely.

That error names no argument and suggests no next step. The run had found the thread and could not open it.

In agent-core#135, I replaced that value with an 8-character handle. Agent Core keeps what the handle points to for the run. The same read now looks like this:

comms.load_thread {"source": "a3f2c1d4"}

The tests replay the miscopy: they change the first character of a handle a search gave, and the read answers:

That source is not from a result of this run. Use the exact source of a result, or get the results again.

The error passes through because it is fixed text that says how to correct the call. The other common refusal works the same way: a thread read with no source, in a session with no current thread, now returns “This session has no current thread. Pass the source of a thread search result.” Other product errors keep a fixed generic message, most often “The tool call failed safely.”

The same facts in every read

Asked what to pick up next, the agent once presented tasks owned by someone else as unassigned, and low-priority tasks under a high priority heading. The cause was in the tool results. Each Todoist read returned text with different facts: one listed priority and assignee but no section, another section and assignee but no priority, a third neither assignee nor due date. A task assigned to nobody was a line without an assignee, so the model read a missing word as a fact. And the task search leaves out other people’s tasks by default without saying so.

Here is a test task as todoist.fetch_object returned it before the change, quoted in the PR:

Found task: Draft the release notes • id=6X7rM8997g3RQmw2 • priority=p2 • project=6Jf8VQXxpwv56VR2

The task sits in a section, is assigned to the asker and is due on November 27. The line says none of it, and nothing in it tells the model those facts exist.

In agent-core#457, every read that returns full tasks now gives each one as the same record. The same task, trimmed:

{
  "title": "Draft the release notes",
  "priority": "p2",
  "section": "Waiting",
  "assignee_user_id": "101",
  "assignee_name": "Hermione Granger",
  "assigned_to_asker": true,
  "due": { "date": "2026-11-27", "recurring": false, "text": null },
  "description": "For the November release."
}

Its subtask, “Proofread the release notes”, is assigned to nobody, in no section and has no date. Its record says so:

{
  "section": null,
  "assignee_user_id": null,
  "assignee_name": null,
  "assigned_to_asker": false,
  "due": null
}

A null says the task has none. The test checks that a task list, a date search, the completed tasks, a project overview, a fetched task and the task a run was started on all give these two records, apart from the description and the typed date text, which only a read of one task returns, so the model no longer joins reads to describe one task.

Next to the records, left_out says what the read did not return. Its test puts three tasks in a project: one unassigned, one the asker’s, one another person’s. The default call keeps two:

todoist.find_tasks {"projectId": "6Jf8VQXxpwv56VQ7", "limit": 100}
→ tasks: the unassigned one and the asker's
→ "left_out": { "assigned_to_others": true, … }

With "responsibleUserFiltering": "all", the read no longer keeps only those two, and assigned_to_others is false. A task missing from the list is no longer taken for a task that doesn’t exist.

Don’t return the same thing twice

The agent often searches several times in a row with close queries, and each search brought back threads it had already been given. In agent-core#564, a search returns each thread once per run. A later search leaves the thread out and lists it in already_returned, with a source to read it again. The source is there because the model may no longer hold the earlier result, which is the case the context engineering article describes.

The test runs two searches in one run. The first matches one thread. Comms matches two for the second, the first one again and a new one:

comms.search_content {"query": "decision"}
→ results: first-thread

comms.search_content {"query": "decision on the pilot"}

The second result, trimmed:

{
  "query": "decision on the pilot",
  "results": [{ "thread_id": "second-thread", "source": "…" }],
  "already_returned": [{ "thread_id": "first-thread", "source": "…" }],
  "read": { "complete": true, "results_returned": 1 }
}

Only the new thread comes back as a result. The source next to first-thread is the one the first search gave. When a later search matches another comment of a thread already returned, already_returned carries a new source for that comment. In that test, results is empty and reading the thread with the new source returns the comment that matched, “The later answer.”

What we measured

For agent-core#571, we played the same 35 evaluation cases once on the main branch and once on the change. The change used 7.8% fewer prompt tokens, and about 19% fewer on a chat read. Main passed 35 of 35, the change 33 of 35, and both failures passed 3 times out of 3 on both sides when replayed.

For agent-core#135, the full evaluation set made 105 runs, 43 of which read a thread found by search. None failed outright. Two cases that missed their expectations already missed them before the change. A third missed once in three runs, then once in six on a rerun, with the same reads as its passing runs.

For the other two, the evaluation set didn’t cover them. It runs without the Todoist tools, so agent-core#457 was checked with tests and one read against the Todoist API. agent-core#564 has no live-model check.

What I’d tell someone doing the same

  1. Measure before trimming.
  2. List who reads each field before removing it. The model is only one reader. Our source records, saved history and evaluation checks read the same results. The checks read only the URL we kept.
  3. A short handle fixes copying only where you use it. Continuation cursors are still signed values the model copies, so a typo there is still possible. The failures we traced were all in source, so that is where I started.
  4. Lean is not always smaller. The task records made Todoist results larger: the text the Todoist tools return stays, because it carries paging, and the records sit next to it. The instructions grew by about 310 characters. What we cut there was ambiguity, not bytes.