Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a significant refactor of the tool interrupt and resume mechanism within the Genkit Python SDK. Key changes include replacing the generic tool_responses parameter with more explicit resume_respond, resume_restart, and resume_metadata options in the generate and prompt execution APIs. A new Interrupt exception has been added for tools to signal pauses, complemented by helper functions like respond_to_interrupt and restart_interrupted_tool for resuming execution. Additionally, the ExecutablePrompt API was updated to accept configuration options as keyword arguments rather than a single opts dictionary. The Google AI plugin was also updated to handle scalar tool inputs for Gemini and to correctly report the finish_reason in streaming responses. I have no feedback to provide as there are no review comments to assess.
py/plugins/google-genai/src/genkit/plugins/google_genai/models/gemini.py
Outdated
Show resolved
Hide resolved
| metadata: dict[str, object] | None = None, | ||
| span_metadata: dict[str, SpanAttributeValue] | None = None, | ||
| *, | ||
| output_schema: type[BaseModel] | dict[str, object] | None = None, |
There was a problem hiding this comment.
Only allow input_schema override, not output_schema (?)
| import tempfile | ||
| from pathlib import Path | ||
| from typing import Any | ||
| from typing import Any, cast |
There was a problem hiding this comment.
is cast used in this file?
| metadata: dict[str, object] | None = None, | ||
| span_metadata: dict[str, SpanAttributeValue] | None = None, | ||
| *, | ||
| output_schema: type[BaseModel] | dict[str, object] | None = None, |
There was a problem hiding this comment.
not sure why this was added
| ai, *_ = setup_test() | ||
|
|
||
| my_prompt = ai.define_prompt(**prompt) | ||
| my_prompt = ai.define_prompt( |
Adds restart support in the Python SDK and other improvements.
Tools (or wrapped tools) can raise
Interrupt, which stops the current generation turn and surfaces the pendingToolRequestPartwith interrupt metadata.Now, The execution flow is paused, giving the caller the option to either respond, and restart the tool execution with replaced input and resumed metadata.
See samples for update usage.
Core Changes
interrupthelper off of ToolRunContext. Now youraise Interruptto trigger interruptions.define_interruptprimitive, which provides the default Interrupt tool, with the option to provide a input schema to constrain the model call.tool_responsehelper torespond_to_interrupt, and addedrestart_interrupted_toolto support the restart use case.tool_fn_wrapper.Related Changes
optsargument; thosePromptGenerationOptionsare flat kwargs now.