Skip to content

Register tools as a single tool.v2 action (match Genkit Dart and JS v2) #183

Todo

Description

@pavelgj

Genkit Dart (genkit-dart#350) and Genkit JS v2 (in progress) register every tool as a single tool.v2 action. Python still registers two actions per tool, like JS v1:

  • /tool/<name>: the Tool itself. await tool(x) returns whatever the function returned.
  • /tool.v2/<name>: the companion wire_action, which returns the MultipartToolResponse envelope.

See Registry._store_locked and Tool.wire_action in _core/_registry.py and _core/_tool.py.

Proposal

Do it the way Dart does: one action per tool, of kind tool.v2.

  • The registry stores only /tool.v2/<name>. Drop the wire_action companion and the /tool/<name> entry.
  • The tool action returns the envelope, so await tool(x) returns a MultipartToolResponse[T]. A plain return value from the function still becomes output.
  • Tool lookup resolves tool.v2. Keep resolving /tool/<name> only as a fallback for actions registered by other code.
  • Spans get subtype tool.v2. Any instrumentation that matches on tool (for example, the GenAI execute_tool spans) should match tool.v2.
  • Leave the user-facing @ai.tool / define_tool API as it is.

Open cross-SDK item

Where the declared output schema (the T in MultipartToolResponse[T]) lives:

  • Python and Go: metadata.originalOutputSchema, with the envelope as the manifest's outputSchema.
  • Dart: the manifest's outputSchema is the declared schema.

The Dev UI only reads the manifest's outputSchema. Whatever JS v2 settles on, we should line Python up with it.

Related

MultipartToolResponse.output is optional in Python, Go and the wire schema, and JS v2 keeps it optional. Dart currently requires it and may move to optional later.

Activity

  1. pavelgj commented on Nov 30, 2026

    @pavelgj
    MemberAuthor

    JS v2 landed on the Dart approach for the open item (genkit-ai/genkit#7368): the action manifest's outputSchema and the ToolDefinition sent to models are the declared schema (the T), not the MultipartToolResponse envelope. The tool wrapper validates the envelope and parses output against T itself. So for Python that means:

    • advertise the declared schema as the manifest's outputSchema, and drop metadata.originalOutputSchema with the envelope-as-outputSchema setup;
    • keep output optional (JS v2 does too).

    Related JS v2 changes Python will probably want too (Dart's equivalent is tracked in genkit-ai/genkit-dart#770, Go's in genkit-ai/genkit#7395):

  2. genkit-bot commented on Dec 3, 2026

    @genkit-bot

    Triage: P2 · L · implement: Confirmed dual /tool and /tool.v2 registration with originalOutputSchema on main; maintainer specified single tool.v2 action returning MultipartToolResponse with declared outputSchema.

    Area: python

    Root cause: Tool.__init__ in packages/genkit/src/genkit/_core/_tool.py registers both /tool/<name> and a companion /tool.v2/<name> wire_action (via Registry._store_locked) using metadata['originalOutputSchema'], returns raw values on await tool(x), and lookup_tool, resolve_tool, and ToolApproval prefer or emit ActionKind.TOOL.

    Plan:

    • Make Tool a single ActionKind.TOOL_V2 action returning MultipartToolResponse[T] with output_schema advertising declared T; drop wire_action, ORIGINAL_OUTPUT_SCHEMA_KEY, and dual registration, and update lookup, genkit-mcp, and ToolApproval to prefer or emit tool.v2 (falling back to tool).
    • Reproduce before the fix using reflection_test.py and tool_response_contract_test.py, which currently observe dual /tool/ and /tool.v2/ entries, originalOutputSchema, and raw direct returns.
    • Update affected unit and typecheck tests and verify with uv run --no-sync pytest packages/genkit/tests packages/genkit-mcp/tests packages/genkit-middleware/tests packages/genkit-otel/tests packages/genkit-google-cloud/tests.
    Details

    Code pointers and scope (maintainer-directed by issue author and comment):

    • packages/genkit/src/genkit/_core/_tool.py: Build Tool with kind=ActionKind.TOOL_V2, wrap plain returns into MultipartToolResponse[T], validate the envelope and parse output against declared T (keeping output optional), set self.output_schema directly to model_schema_from_return_annotation(...), remove _wire_action, wire_action, ORIGINAL_OUTPUT_SCHEMA_KEY, and model_output_schema (update Tool generic base to Action[InputT, MultipartToolResponse[OutputT], ChunkT, None] and overloads in _core/_tool.py, _ai/_tools.py, and _ai/_aio.py so -> MultipartToolResponse[T] does not double-wrap).
    • packages/genkit/src/genkit/_core/_registry.py: Remove wire_action companion storage from _store_locked and update list_actions comment. Verify _resolve_dap_qualified_action and expand_wildcard_tools when DAP 'tool' buckets return Tool instances with kind=ActionKind.TOOL_V2.
    • packages/genkit/src/genkit/_ai/_aio.py: Update Genkit.lookup_tool to resolve ActionKind.TOOL_V2 first and fall back to ActionKind.TOOL.
    • packages/genkit/src/genkit/_ai/_generate.py: Update resolve_tool to prefer ActionKind.TOOL_V2 then fall back to ActionKind.TOOL; update register_tools to check ActionKind.TOOL_V2; simplify to_tool_definition to read tool.output_schema directly without ORIGINAL_OUTPUT_SCHEMA_KEY.
    • packages/genkit-mcp/src/genkit_mcp/_tools.py and _client.py: Set handle.output_schema directly in mcp_tools_to_handles instead of handle.model_output_schema.
    • packages/genkit-middleware/src/genkit_middleware/_tool_approval.py: Emit action_type=str(ActionKind.TOOL_V2) on interrupt spans.
    • packages/genkit-otel/src/genkit_otel/_genai_instrumentation.py: Already matches kind in ('tool', 'tool.v2') for execute_tool spans; update comment if needed.
    • packages/genkit-google-cloud/src/genkit_google_cloud/_telemetry/_adjusting_exporter.py: Check span handling and tests (adjusting_exporter_test.py, cloud_spans_test.py) for tool.v2 subtype.
    • Tests to update (~20 files across packages/genkit/tests/, packages/genkit-mcp/tests/, packages/genkit-middleware/tests/, packages/genkit-google-cloud/tests/), including tool_response_contract_test.py, tool_multipart_test.py, flow_tool_shapes_contract_test.py, dynamic_tools_generate_test.py, reflection_test.py, lookup_test.py, _tools_test.py, mcp_client_test.py, mcp_host_test.py, and trace_data_encoder_test.py.
    • Out of scope (noted as separate related JS v2 follow-ups in the maintainer comment): supports.toolResponseContent fallback middleware and MCP client toolResponseMode.
    • Duplicate check: search_github_issues in genkit-ai/genkit-python returned only Register tools as a single tool.v2 action (match Genkit Dart and JS v2) #183.

    Opened #279 (run d86e2563-ccb7-43a3-acf4-1ef99746c9c7, Cloud Run logs, Dashboard)

  3. removed their assignment
    on Dec 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions