Skip to content

chore(py): Add Tool type, update generate call signature, remove dynamic-tools#5063

Merged
huangjeff5 merged 8 commits into
mainfrom
jh-tool-refactor
Apr 7, 2026
Merged

chore(py): Add Tool type, update generate call signature, remove dynamic-tools#5063
huangjeff5 merged 8 commits into
mainfrom
jh-tool-refactor

Conversation

@huangjeff5
Copy link
Copy Markdown
Contributor

@huangjeff5 huangjeff5 commented Apr 3, 2026

Summary

  • Adds a first-class Tool type from define_tool / @ai.tool
  • lets generate / prompts take tools as registry names (str) or Tool instances
  • Allow custom override for define_tool's input_schema. This is used to support define_interrupt (followup PR). Normally input_schema is inferred from the tool function, but in define_interrupt, the Interrupt tool fn is Any (since it needs to be dynamic), while allowing the user to provide an input schema to constrain the model when it chooses to call the interrupt tool.
  • Removed dynamic tools for now. It's not ready.
  • This PR is a pre-req for Tool respond/restart and Dynamic Tools features.

@github-actions github-actions Bot added docs Improvements or additions to documentation python Python config refactor labels Apr 3, 2026
Comment thread py/packages/genkit/src/genkit/_ai/_tools.py Outdated
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 tool handling within the Genkit AI package, introducing a dedicated Tool class and updating various interfaces to support a Sequence[str | Tool] type for tools. It also removes the dynamic_tool method and its associated sample code. Several critical issues were identified in the review: the resolve_tool function is imported but not defined in the provided changes, and there are multiple instances where a TypedDict (PromptGenerateOptions) is incorrectly accessed using dot notation, which will lead to runtime errors. Furthermore, the newly added unwrap_wrapped_scalar_tool_input_if_needed helper is currently unused and should be integrated into the tool execution wrapper to correctly handle wrapped payloads from model providers like Gemini.

Comment thread py/packages/genkit/src/genkit/_ai/_prompt.py
Comment thread py/packages/genkit/src/genkit/_ai/_tools.py
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 Outdated
@huangjeff5 huangjeff5 changed the title chore(py): Refactor tools chore(py): Tool handles, str | Tool in generate, remove dynamic-tools Apr 3, 2026
@huangjeff5 huangjeff5 changed the title chore(py): Tool handles, str | Tool in generate, remove dynamic-tools chore(py): Add Tool type, update generate call signature, remove dynamic-tools Apr 3, 2026
Comment thread py/packages/genkit/src/genkit/_ai/_aio.py Outdated
@huangjeff5 huangjeff5 requested review from apascal07 and pavelgj April 3, 2026 18:21
@huangjeff5 huangjeff5 marked this pull request as ready for review April 3, 2026 18:21
@huangjeff5 huangjeff5 enabled auto-merge (squash) April 7, 2026 18:50
@huangjeff5 huangjeff5 merged commit 8ff5d8e into main Apr 7, 2026
19 checks passed
@huangjeff5 huangjeff5 deleted the jh-tool-refactor branch April 7, 2026 19:02
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