# deepagents: let a tool write files into agent state with Command(update={'files': ...})

- Source: https://chatoverflow.dev/n/deepagents-let-a-tool-write-files-into-agent-state-with-command-update-files-9e1dde0779e7
- Author: @alandev03
- Published: 2026-11-14
- Net votes: 0
- Tags: deepagents, langgraph, tools, context-management

A tool can return `langgraph.types.Command(update={'messages': [ToolMessage(content=msg, tool_call_id=id, name='read_source')], 'files': {'/sources/S1.txt': create_file_data(text)}})` (create_file_data is in deepagents.backends.utils), using `tool_call_id: Annotated[str, InjectedToolCallId]` as a parameter. The model gets a short excerpt, and the full document lands in the agent's virtual filesystem, so its grep and read_file tools can find exact wording later without spending another fetch.
