Skip to content

Comments

chore(genkit-tools): update schema and regenerate Python types#4818

Open
MichaelDoyle wants to merge 1 commit intofeat-py-codec-signaturesfrom
chore-genkit-tools-schema
Open

chore(genkit-tools): update schema and regenerate Python types#4818
MichaelDoyle wants to merge 1 commit intofeat-py-codec-signaturesfrom
chore-genkit-tools-schema

Conversation

@MichaelDoyle
Copy link
Member

I'm "pulling forward" the middleware schema, so to speak at the same time. I think that should be "OK". But let me know if not.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @MichaelDoyle, 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 focuses on updating and regenerating the Genkit toolkit's schemas and Python types. The primary goal is to introduce support for middleware and refine existing generation configurations, providing more detailed control and extensibility for model interactions. It also addresses schema restructuring to improve clarity and resolve naming conflicts, ensuring that the type definitions across TypeScript, JSON schema, and Python are consistent and up-to-date with the latest features.

Highlights

  • Middleware and Model Reference Schemas: Introduced new TypeScript schemas and types for MiddlewareDesc, MiddlewareRef, and ModelReference to support middleware functionality and clearer model referencing within the Genkit toolkit. These changes are reflected in genkit-tools/common/src/types/model.ts and the genkit-schema.json.
  • Enhanced Generation Configuration: The GenerationCommonConfig schema has been significantly updated to include more descriptive comments for existing parameters (like temperature, maxOutputTokens, topK, topP, stopSequences) and a new apiKey field. The stopSequences now has a maxItems constraint, and the schema allows additional properties, providing more flexibility. These changes are propagated across TypeScript, JSON schema, and Python types.
  • Updated Generation Action Options: The GenerateActionOptions schema now includes resources and use fields. The resources field allows specifying registered resource names, and the use field enables applying middleware to generation actions, enhancing control and extensibility.
  • Schema Restructuring and Clarity: Refactored part schemas in genkit-tools/common/src/types/parts.ts to resolve naming conflicts and improve clarity. This involved removing the top-level PartSchema and Part exports, introducing TextOrMediaPartSchema, and updating ToolResponse content to use this new type. The PartSchema was redefined in model.ts as a union of all specific part types.
  • Python Type Regeneration: The Python type definitions in py/packages/genkit/src/genkit/core/typing.py have been regenerated to align with the latest TypeScript and JSON schema updates. This includes the new middleware and model reference types, detailed generation configuration fields, and the restructured part types, ensuring consistency across language bindings.

🧠 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.

Changelog
  • genkit-tools/common/src/types/model.ts
    • Removed redundant PartSchema and Part imports and exports.
    • Added MiddlewareDescSchema, MiddlewareRefSchema, and ModelReferenceSchema with their corresponding TypeScript types.
    • Redefined PartSchema and Part as a union of all specific part types within the file.
    • Updated GenerationCommonConfigSchema with detailed descriptions for parameters, added an apiKey field, set maxItems for stopSequences, and enabled passthrough() for additional properties.
    • Added resources and use fields to GenerateActionOptionsSchema.
  • genkit-tools/common/src/types/parts.ts
    • Updated the description for TextPartSchema from 'document' to 'message'.
    • Added ToolRequest type definition.
    • Updated ToolResponse type and ToolResponseSchema to use TextOrMediaPart for content.
    • Removed the top-level PartSchema and Part definitions.
    • Introduced TextOrMediaPartSchema and TextOrMediaPart to represent a union of text and media parts.
    • Updated MultipartToolResponseSchema to use TextOrMediaPartSchema for its content.
  • genkit-tools/common/src/types/reranker.ts
    • Modified the import path for DocumentPartSchema from ./document to ./parts.
  • genkit-tools/genkit-schema.json
    • Removed the DocumentPart definition from the root of the schema.
    • Added resources and use properties to the GenerateActionOptions definition.
    • Updated GenerationCommonConfig properties with detailed descriptions, maxItems for stopSequences, and an apiKey field, and changed additionalProperties to true.
    • Added new definitions for MiddlewareDesc, MiddlewareRef, and ModelReference.
    • Relocated the DocumentPart definition to a later section in the schema.
    • Updated MultipartToolResponse content to reference DocumentPart.
  • py/packages/genkit/src/genkit/core/typing.py
    • Updated GenerationCommonConfig class to include detailed field descriptions, max_length for stop_sequences, and an api_key field, and changed extra from 'forbid' to 'allow'.
    • Added new Python classes: MiddlewareDesc, MiddlewareRef, and ModelReference.
    • Reorganized and added DocumentPart, RankedDocumentData, RerankerResponse, DocumentData, EmbedRequest, MultipartToolResponse, RerankerRequest, RetrieverRequest, RetrieverResponse, and Docs classes.
    • Updated Content class to correctly reference DocumentPart or Part as appropriate.
    • Removed redundant class definitions that were moved or replaced.
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.

@MichaelDoyle MichaelDoyle force-pushed the chore-genkit-tools-schema branch from 2787033 to 9c1ebe0 Compare February 24, 2026 22:53
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 updates the schemas and regenerates Python types, primarily focusing on introducing middleware-related types and enhancing the "GenerationCommonConfig". The changes involve refactoring "PartSchema" definitions across different files to improve organization and avoid naming conflicts. New properties for "resources" and "use" (for middleware) have been added to "GenerateActionOptions". The "GenerationCommonConfig" now includes more descriptive fields, a maximum length constraint for "stopSequences", and an "apiKey" field. Overall, the changes appear to be a consistent and well-explained evolution of the schema definitions.

}
},
"additionalProperties": false
"additionalProperties": true
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The "GenerationCommonConfig" schema has been updated to allow "additionalProperties". While this provides flexibility for model-specific configurations, it also means that any unknown properties passed in the config will be accepted without validation. This could potentially mask typos in property names or lead to unexpected behavior if downstream consumers of this schema do not explicitly handle these extra properties. Consider if this level of flexibility is strictly necessary, or if a more explicit approach (e.g., using a dedicated "modelConfig" object within the common config) would be safer for preventing unintended inputs.

Suggested change
"additionalProperties": true
"additionalProperties": false

top_k: float | None = Field(default=None)
top_p: float | None = Field(default=None)
stop_sequences: list[str] | None = Field(default=None)
model_config: ClassVar[ConfigDict] = ConfigDict(alias_generator=to_camel, extra='allow', populate_by_name=True)
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The "GenerationCommonConfig" Pydantic model now uses "extra='allow'". This change corresponds to the "additionalProperties: true" in the JSON schema. While it offers flexibility, it relaxes strict validation and might allow unrecognized parameters to be passed without error. If the intent is to allow model-specific configurations, consider if a more structured approach (e.g., a nested "model_config" field) would provide better type safety and prevent accidental misconfigurations.

Suggested change
model_config: ClassVar[ConfigDict] = ConfigDict(alias_generator=to_camel, extra='allow', populate_by_name=True)
model_config: ClassVar[ConfigDict] = ConfigDict(alias_generator=to_camel, extra='forbid', populate_by_name=True)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

1 participant