Give `FileSystem` tools registered tool kinds and typed call parts

Merged
DO
1mo ago
+593-9

Part of #9398. Step 4 of the plan on #9410: FileSystem registers tool kinds for its tools, using the mechanism #9710 added, so other capabilities can recognize them without comparing tool names. #9410 will then mark its reader tools as superseded by READ_FILE_KIND.

  • Every tool in FILE_SYSTEM_TOOL_NAMES declares a ToolKind in the file_system namespace (the one FileSystem's capability events already use), named after the tool: file_system.read_file, file_system.write_file, file_system.edit_file, file_system.list_directory, file_system.search_files, file_system.find_files, file_system.create_directory, file_system.file_info, file_system.list_files, file_system.grep. They are set through add_function(tool_kind=...), so the kind is on the ToolDefinition whatever name or prefix the tool ends up with.
  • Each kind declares its argument shape as a TypedDict (ReadFileArgs, ...), which _check_tool_kinds checks against the tool's parameters, including the content_hashes=False variants without expected_hash. Calls are promoted to typed call parts (ReadFileCallPart, ...).
  • Only read_file gets a typed return part, ReadFileReturnPart. Other capabilities look for its result in history (#9410's readers, DeduplicateFileReads). The other tools return text written for the model, and the capability events already carry their outcomes as structured data. The read kind declares no content shape: its result is str | list[str | BinaryContent], and ToolKind(content=...) takes type[T], which a union doesn't satisfy (pyright rejects it). So ReadFileReturnPart is unparameterized and its typed_content is untyped.
  • Kinds, args types and part classes are exported from pydantic_ai_harness.filesystem. The README, docs page and harness skill reference are updated.

Kind ids are stored in histories, so the names need to be settled before merge. I used the tool names for consistency, not short verbs like file_system.read.

Not in this PR: the name-keyed consumers listed in #9410 (ACP presentation and AcpFileSystemToolset's read_file/write_file, DeduplicateFileReads, CLAI speculative mode and tool rendering, RepoContext's traversal names) can move to these kinds in follow-ups.

Checklist

  • No breaking changes in accordance with the version policy. Calls to these tools are now ToolCallPart subclasses and carry a tool_kind. isinstance(part, ToolCallPart) still holds, and histories that lack the kind still load.
  • Any permitted compatibility impact has a label, warning, migration, release note, and exact API-check waiver.
  • PR title is fit for the release changelog.

šŸ¤– Generated with Claude Code