feat(py): integrate DAP into generate call, expand wildcards#5075
feat(py): integrate DAP into generate call, expand wildcards#5075huangjeff5 wants to merge 3 commits intojh-dap-pr1from
Conversation
…enerate integration
There was a problem hiding this comment.
Code Review
This pull request introduces a child registry pattern to Genkit, allowing for ephemeral, scoped registries that delegate lookups to a parent. It also adds support for expanding wildcard tool names (e.g., provider:tool/*) via dynamic action providers within the generate loop. I have reviewed the implementation and provided feedback regarding potential performance optimizations for wildcard name checking and registry traversal.
I am having trouble creating individual review comments. Click here to see my feedback.
py/packages/genkit/src/genkit/_ai/_generate.py (73)
The condition ':' not in name or not name.endswith('*') is slightly inefficient because ':' not in name is checked for every iteration, even if the name is a simple tool name. Consider checking for the wildcard suffix first, as it is more specific.
py/packages/genkit/src/genkit/_core/_registry.py (619-622)
The loop for parent_meta in await self._parent.list_actions(allowed_kinds): is called inside list_actions. If the registry hierarchy is deep, this could lead to redundant recursive calls. Consider if caching or a different traversal strategy is needed for performance.
Summary
_generate_actioncreates aneffective_registry(child of the root registry) at the start of each generate call. Tool resolution and resource lookup use this child so DAP-resolved tools are scoped to the call and do not pollute the root registry.expand_wildcard_tools()expands patterns such asprovider:tool/*andprovider:tool/prefix*into concrete tool names viaDynamicActionProvider.list_action_metadata. Expansion runs before parameter resolution so the model receives a fullToolDefinitionlist.resolve_tool_requestsreceiveseffective_registryso execution uses the child’s resolved action cache.