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
feat(py/genkit): add multipart tool support (tool.v2)
Add support for multipart tools that can return both structured
output and rich content parts, matching the JS SDK defineTool
with multipart: true.
Changes:
- Add TOOL_V2 enum value to ActionKind
- Add multipart kwarg to @ai.tool() decorator
- When multipart=True, register as tool.v2 with metadata
type=tool.v2 and tool.multipart=True
- When multipart=False (default), register both tool and tool.v2
(v2 wraps output in {output: result}) for discoverability
- Update resolve_tool() and resolve_parameters() to look up
both tool and tool.v2 kinds
Includes 6 new tests covering registration, metadata,
execution, and v2 wrapper behavior.
| `defineTool({multipart:true})` | ✅ Supported. Creates a `MultipartToolAction` of type `tool.v2`. | ❌ Not supported. `define_tool` has no `multipart` parameter. | **G18** |
912
-
| `MultipartToolAction` type | ✅ `tool.ts:107-122` — Action with `tool.v2` type, returns `{output?, content?}`. | ❌ Does not exist. | **G18** |
913
-
| `MultipartToolResponse` type | ✅ `parts.ts` — Schema with `output` and `content` fields. | ⚠️ Type exists in `typing.py:933` but unused in tool definition. | Partial |
914
-
| Auto-registration of `tool.v2` | ✅ Non-multipart tools are also registered as `tool.v2` with wrapped output. | ❌ No dual registration. | **G18** |
911
+
| `defineTool({multipart:true})` | ✅ Supported. Creates a `MultipartToolAction` of type `tool.v2`. | ✅ `.tool(multipart=True)` registers as `tool.v2` with metadata `tool.multipart=True`. | ✅ PR #4513 |
912
+
| `MultipartToolAction` type | ✅ `tool.ts:107-122` — Action with `tool.v2` type, returns `{output?, content?}`. | ✅ Registered under `ActionKind.TOOL_V2` with appropriate metadata. | ✅ PR #4513 |
913
+
| `MultipartToolResponse` type | ✅ `parts.ts` — Schema with `output` and `content` fields. | ✅ Multipart tool functions return `{output?, content?}` dict. | ✅ PR #4513 |
914
+
| Auto-registration of `tool.v2` | ✅ Non-multipart tools are also registered as `tool.v2` with wrapped output. | ✅ Non-multipart tools register both `tool` and `tool.v2` (v2 wraps output in `{output: result}`). | ✅ PR #4513 |
| G15 | Python | `download_request_media` middleware missing | P2 | `py/packages/genkit/src/genkit/blocks/middleware.py` | URL media transformed to data URI |
1041
1041
| G16 | Python | `simulate_system_prompt` missing | P2 | `py/packages/genkit/src/genkit/blocks/middleware.py` | system message rewritten for unsupported model |
| **P1.1** | **G2** | Add `middleware` storage to `Action` class; implement `action_with_middleware()` wrapper that chains model-level middleware around `action.run()` | `core/action/_action.py` | L | G1, G12, G13, G15, G19 |
1200
1200
| **P1.2** | **G6** | Update `on_trace_start` callback signature to `(trace_id: str, span_id: str)` throughout action system | `core/action/_action.py`, `core/reflection.py`, `core/trace/` | S | G5 |
1201
-
| **P1.3** | **G18** | Add multipart tool support: `define_tool(multipart=True)`, `MultipartToolAction` type `tool.v2`, dual registration for non-multipart tools | `blocks/tools.py`, `blocks/generate.py` | M | — |
1202
-
| **P1.4** | **G20** | Add `context` parameter to `Genkit()` that sets `registry.context` for default action context | `ai/_aio.py`| XS | — |
1203
-
| **P1.5** | **G21** | Add `clientHeader` parameter to `Genkit()` that appends to `GENKIT_CLIENT_HEADER` via `set_client_header()` | `ai/_aio.py`, `core/http_client.py` | XS | G8 |
1201
+
| **P1.3** | **G18** | ~~Add multipart tool support: `define_tool(multipart=True)`, `MultipartToolAction` type `tool.v2`, dual registration for non-multipart tools~~ | `ai/_registry.py`, `core/action/types.py`, `blocks/generate.py` | M | ✅ **Done** (PR #4513) |
1202
+
| **P1.4** | **G20** | ~~Add `context` parameter to `Genkit()` that sets `registry.context` for default action context~~ | `ai/_aio.py`, `core/registry.py`| XS | ✅ **Done** (PR #4512) |
1203
+
| **P1.5** | **G21** | ~~Add `clientHeader` parameter to `Genkit()` that appends to `GENKIT_CLIENT_HEADER` via `set_client_header()`~~ | `ai/_aio.py`, `core/constants.py` | XS | ✅ **Done** (PR #4512) |
1204
1204
1205
1205
**Exit criteria**: All unit tests green for action middleware dispatch, span_id propagation, tool.v2 registration, and constructor parameter propagation.
1206
1206
@@ -1439,8 +1439,8 @@ Milestone ▲ P1 infra ▲ Middleware ▲ Full P1 ▲ Client
1439
1439
|----|:-----:|------|----------|:----------:|
1440
1440
| **PR-1a** | Core | G2 | Add `middleware` list to `Action.__init__()`, implement `action_with_middleware()` dispatch wrapper, unit tests for middleware chaining | — |
1441
1441
| **PR-1b** | Core | G6 | Update `on_trace_start` callback signature to `(trace_id, span_id)` across action system + tracing, update all call sites | — |
0 commit comments