Skip to content

feat(py): add tool restarts and refactor Interrupts#5069

Merged
huangjeff5 merged 11 commits intomainfrom
jh-interrupts-refactor
Apr 30, 2026
Merged

feat(py): add tool restarts and refactor Interrupts#5069
huangjeff5 merged 11 commits intomainfrom
jh-interrupts-refactor

Conversation

@huangjeff5
Copy link
Copy Markdown
Contributor

@huangjeff5 huangjeff5 commented Apr 7, 2026

  • refactor Interrupt, now you use raise Interrupt instead of ctx.Interrupt(); this way there is clearer separation and you only pass ctx when needed.
  • add define_interrupt.
  • add Tool.restart / run_tool_after_restart to support restart flow.
  • extend generate loop and executable prompts to support resume/restart.
  • Added samples to show usage (probably easiest to start there).

@github-actions github-actions Bot added docs Improvements or additions to documentation python Python refactor labels Apr 7, 2026
Comment thread py/packages/genkit/src/genkit/_ai/_generate.py Outdated
Comment thread py/packages/genkit/src/genkit/_ai/_generate.py Outdated
Comment thread py/packages/genkit/src/genkit/_ai/_generate.py
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the tool interrupt and resume mechanism, replacing the specific ToolInterruptError with a more general Interrupt exception and introducing flat keyword options for resuming generation (resume_respond, resume_restart, and resume_metadata). Key additions include a restart method on the Tool class to facilitate re-running tools with modified inputs, a define_interrupt helper for explicit human-in-the-loop checkpoints, and updated logic in the generation loop to handle pending outputs and resumed contexts. Feedback focuses on maintaining consistent error types by using GenkitError instead of ValueError and fixing Markdown formatting issues in the sample documentation.

Comment thread py/packages/genkit/src/genkit/_ai/_generate.py Outdated
Comment thread py/samples/tool-interrupts/README.md Outdated
Comment thread py/packages/genkit/src/genkit/_core/_action.py Outdated
Comment thread py/packages/genkit/tests/genkit/ai/generate_test.py
Comment thread py/packages/genkit/tests/genkit/ai/prompt_test.py Outdated
Comment thread py/packages/genkit/tests/genkit/ai/prompt_test.py Outdated
Comment thread py/packages/genkit/src/genkit/_ai/_prompt.py Outdated
Comment thread py/packages/genkit/src/genkit/_ai/_prompt.py Outdated
Comment thread py/packages/genkit/src/genkit/_ai/_prompt.py Outdated
Comment thread py/packages/genkit/src/genkit/_ai/_generate.py Outdated
Comment thread py/packages/genkit/src/genkit/_ai/_prompt.py Outdated
Comment thread py/packages/genkit/src/genkit/_ai/_prompt.py Outdated
Comment thread py/packages/genkit/src/genkit/_ai/_prompt.py Outdated
Comment thread py/packages/genkit/src/genkit/_ai/_tools.py
Comment thread py/packages/genkit/src/genkit/_ai/_tools.py Outdated
Comment thread py/packages/genkit/tests/genkit/ai/prompt_test.py Outdated
Comment thread py/packages/genkit/tests/genkit/ai/prompt_test.py Outdated
Comment thread py/packages/genkit/tests/genkit/ai/prompt_test.py Outdated
Comment thread py/packages/genkit/src/genkit/_ai/_prompt.py Outdated
Comment thread py/packages/genkit/src/genkit/_ai/_prompt.py Outdated
Comment thread py/packages/genkit/src/genkit/_ai/_prompt.py
@github-actions github-actions Bot added the config label Apr 8, 2026
@huangjeff5 huangjeff5 marked this pull request as ready for review April 8, 2026 03:05
@huangjeff5 huangjeff5 requested a review from pavelgj April 8, 2026 03:05
Comment thread py/samples/tool-interrupts/src/approval_example.py Outdated
@huangjeff5 huangjeff5 requested a review from pavelgj April 21, 2026 13:43
@huangjeff5 huangjeff5 merged commit 09d5b5b into main Apr 30, 2026
19 checks passed
@huangjeff5 huangjeff5 deleted the jh-interrupts-refactor branch April 30, 2026 20:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

config docs Improvements or additions to documentation python Python refactor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants