You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Register tools as a single tool.v2 action (match Genkit Dart and JS v2) #183
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.
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;
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.
Activity
pavelgj commentedon Nov 30, 2026
JS v2 landed on the Dart approach for the open item (genkit-ai/genkit#7368): the action manifest's
outputSchemaand theToolDefinitionsent to models are the declared schema (theT), not theMultipartToolResponseenvelope. The tool wrapper validates the envelope and parsesoutputagainstTitself. So for Python that means:outputSchema, and dropmetadata.originalOutputSchemawith the envelope-as-outputSchemasetup;outputoptional (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):
supports.toolResponseContent: models that declare it delivertoolResponse.contentthemselves; others get a built-in fallback middleware that folds text intooutputand moves media into a follow-up user message (feat(js/ai): add opt-in foldToolResponseContent generateMiddleware genkit#7370).toolResponseMode('content'by default, plus'structured','raw'and a custom function), replacing the "structuredContentwins, otherwise concatenate text" mapping (feat(js/plugins/mcp)!: replace multipart and rawToolResponses with toolResponseMode genkit#7374).genkit-bot commentedon Dec 3, 2026
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__inpackages/genkit/src/genkit/_core/_tool.pyregisters both/tool/<name>and a companion/tool.v2/<name>wire_action(viaRegistry._store_locked) usingmetadata['originalOutputSchema'], returns raw values onawait tool(x), andlookup_tool,resolve_tool, andToolApprovalprefer or emitActionKind.TOOL.Plan:
Toola singleActionKind.TOOL_V2action returningMultipartToolResponse[T]withoutput_schemaadvertising declaredT; dropwire_action,ORIGINAL_OUTPUT_SCHEMA_KEY, and dual registration, and update lookup,genkit-mcp, andToolApprovalto prefer or emittool.v2(falling back totool).reflection_test.pyandtool_response_contract_test.py, which currently observe dual/tool/and/tool.v2/entries,originalOutputSchema, and raw direct returns.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: BuildToolwithkind=ActionKind.TOOL_V2, wrap plain returns intoMultipartToolResponse[T], validate the envelope and parseoutputagainst declaredT(keepingoutputoptional), setself.output_schemadirectly tomodel_schema_from_return_annotation(...), remove_wire_action,wire_action,ORIGINAL_OUTPUT_SCHEMA_KEY, andmodel_output_schema(updateToolgeneric base toAction[InputT, MultipartToolResponse[OutputT], ChunkT, None]and overloads in_core/_tool.py,_ai/_tools.py, and_ai/_aio.pyso-> MultipartToolResponse[T]does not double-wrap).packages/genkit/src/genkit/_core/_registry.py: Removewire_actioncompanion storage from_store_lockedand updatelist_actionscomment. Verify_resolve_dap_qualified_actionandexpand_wildcard_toolswhen DAP'tool'buckets returnToolinstances withkind=ActionKind.TOOL_V2.packages/genkit/src/genkit/_ai/_aio.py: UpdateGenkit.lookup_toolto resolveActionKind.TOOL_V2first and fall back toActionKind.TOOL.packages/genkit/src/genkit/_ai/_generate.py: Updateresolve_toolto preferActionKind.TOOL_V2then fall back toActionKind.TOOL; updateregister_toolsto checkActionKind.TOOL_V2; simplifyto_tool_definitionto readtool.output_schemadirectly withoutORIGINAL_OUTPUT_SCHEMA_KEY.packages/genkit-mcp/src/genkit_mcp/_tools.pyand_client.py: Sethandle.output_schemadirectly inmcp_tools_to_handlesinstead ofhandle.model_output_schema.packages/genkit-middleware/src/genkit_middleware/_tool_approval.py: Emitaction_type=str(ActionKind.TOOL_V2)on interrupt spans.packages/genkit-otel/src/genkit_otel/_genai_instrumentation.py: Already matcheskind in ('tool', 'tool.v2')forexecute_toolspans; 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) fortool.v2subtype.packages/genkit/tests/,packages/genkit-mcp/tests/,packages/genkit-middleware/tests/,packages/genkit-google-cloud/tests/), includingtool_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, andtrace_data_encoder_test.py.supports.toolResponseContentfallback middleware and MCP clienttoolResponseMode.search_github_issuesingenkit-ai/genkit-pythonreturned 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)