Skip to content

Conversation

@yesudeep
Copy link
Contributor

No description provided.

@yesudeep yesudeep requested a review from MengqinShen December 20, 2025 22:18
@github-actions github-actions bot added feature New feature or request python Python config labels Dec 20, 2025
@yesudeep yesudeep marked this pull request as draft December 20, 2025 22:19
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @yesudeep, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the Genkit Python SDK by introducing a robust resource management system. It allows developers to define and register various types of resources, identified by URIs or URI templates, which can then be resolved and processed within Genkit flows. This feature provides a standardized way to handle external or dynamic content, improving the framework's flexibility and extensibility for AI applications.

Highlights

  • New Resource Management API: Introduced a new API for defining and managing 'resources' within Genkit, allowing for addressable content or data processing units identified by URIs or URI templates.
  • Python ai.define_resource Support: Added the ai.define_resource method to the Python Genkit SDK, mirroring the functionality available in the JavaScript SDK for registering resource actions.
  • URI Template Matching: Implemented logic for matching resource requests against URI templates (e.g., my://resource/{id}), enabling dynamic resource resolution.
  • Dependency Update: Added uritemplate as a new dependency to handle URI template parsing and matching.
  • Enhanced Registry Functionality: The core registry now supports registering pre-configured Action instances, facilitating the integration of dynamic resources.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
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 adds support for defining resources in Python, a key feature for managing addressable content. The implementation is comprehensive, including registration, dynamic resources, and matching logic. I've identified a few areas for improvement in the new resource.py file. Key suggestions include using the uritemplate library for robust URI template matching, removing dead and commented-out code, and clarifying some complex logic. The addition of tests is great and covers the new functionality well.

Comment on lines +274 to +282
except Exception as e:
raise e

# Since p.metadata is a dict in Pydantic RootModel for Metadata usually, assuming it's accessible.
# Part -> ResourcePart | etc. ResourcePart has resource: Resource1.
# But the JS code puts it in metadata.resource.
# In Python typing.py, Metadata is RootModel[dict[str, Any]].

if 'resource' in p_metadata:
if 'parent' not in p_metadata['resource']:
p_metadata['resource']['parent'] = {'uri': input_data.uri}
if opts.get('template'):
p_metadata['resource']['parent']['template'] = opts.get('template')
else:
p_metadata['resource'] = {'uri': input_data.uri}
if opts.get('template'):
p_metadata['resource']['template'] = opts.get('template')

Copy link
Contributor

Choose a reason for hiding this comment

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

high

This block contains a redundant try...except that just re-raises the exception. More importantly, it's followed by a block of dead code (lines 277-291). This entire section should be removed, and the try block can be unwrapped.

Comment on lines 335 to 354
if template_opt:
# Naive implementation of template matching
# Converts {variable} to ([^/]+)
pattern_str = re.escape(template_opt).replace(r'\{', '{').replace(r'\}', '}')
# Handle simple variables {var}
pattern_str = re.sub(r'\{[^}]+\}', r'([^/]+)', pattern_str)
# Ensure full match
pattern = re.compile(f'^{pattern_str}$')

return lambda input: pattern.match(input.uri) is not None
Copy link
Contributor

Choose a reason for hiding this comment

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

high

The uritemplate library was added as a dependency, but create_matcher uses a naive regex-based implementation for URI templates. This implementation is limited and doesn't fully support the RFC6570 specification mentioned in the docstring. Using the uritemplate library would provide a more robust and compliant solution.

Suggested change
if template_opt:
# Naive implementation of template matching
# Converts {variable} to ([^/]+)
pattern_str = re.escape(template_opt).replace(r'\{', '{').replace(r'\}', '}')
# Handle simple variables {var}
pattern_str = re.sub(r'\{[^}]+\}', r'([^/]+)', pattern_str)
# Ensure full match
pattern = re.compile(f'^{pattern_str}$')
return lambda input: pattern.match(input.uri) is not None
if template_opt:
template = uritemplate.URITemplate(template_opt)
return lambda input: template.match(input.uri) is not None

p_metadata['resource']['template'] = opts.get('template')

return parts

Copy link
Contributor

Choose a reason for hiding this comment

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

medium

This return statement is unreachable because the try block on line 227 will always either return a value or the except block will raise an exception. This line should be removed.

@yesudeep yesudeep force-pushed the yesudeep/feat/amused-team branch from e9c7d65 to 51aa9f4 Compare December 20, 2025 22:35
@yesudeep yesudeep removed the request for review from MengqinShen December 20, 2025 22:37
@yesudeep yesudeep force-pushed the yesudeep/feat/amused-team branch from 51aa9f4 to fb47e1e Compare December 20, 2025 22:42
@yesudeep yesudeep force-pushed the yesudeep/feat/amused-team branch from fb47e1e to 27a1ad0 Compare December 20, 2025 22:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

config feature New feature or request python Python

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

1 participant