feat(agents): add metadata parameter to generator completion pipeline#2300
feat(agents): add metadata parameter to generator completion pipeline#2300kevinmessiaen merged 7 commits intomainfrom
Conversation
Thread `metadata: dict[str, Any] | None` through the entire completion pipeline (complete, middleware, _call_model) and add a `metadata` field to `Response`. Change `_call_model` return type from tuple to `Response` for extensibility. Update cursor rule accordingly. Made-with: Cursor
Summary of ChangesHello, 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 refactors the generator completion pipeline by introducing a flexible Highlights
🧠 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
Activity
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
Code Review
This pull request integrates a metadata parameter across the completion pipeline, from BaseGenerator to CompletionMiddleware and _call_model, to support contextual information like trace IDs and tags. While the overall implementation is clean and consistent, there are critical issues that need addressing. Specifically, the LiteLLMGenerator implementation is incomplete, as it ignores the metadata parameter and fails to populate the response metadata. Furthermore, the introduction of a strictly typed Pydantic Response model for the generator output poses a potential Denial of Service risk if the LLM provider returns an unexpected finish_reason string.
libs/giskard-agents/src/giskard/agents/generators/litellm_generator.py
Outdated
Show resolved
Hide resolved
libs/giskard-agents/src/giskard/agents/generators/litellm_generator.py
Outdated
Show resolved
Hide resolved
…l signature Made-with: Cursor
…tring - Forward input metadata to litellm's acompletion (used by logging integrations like Langfuse) - Populate Response.metadata with raw ModelResponse fields (minus choices) under a "litellm" key - Add docstring to _complete template method Made-with: Cursor
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces a metadata parameter to the generator completion pipeline, allowing for better context propagation and tracing. The change is comprehensive, threading the metadata through the BaseGenerator, middlewares, and litellm implementation. The return type of _call_model has also been refactored to return a Response object, which is a good improvement for extensibility. The changes are well-implemented and all tests have been updated accordingly. I have one suggestion to improve the metadata handling in the litellm generator to ensure that caller-provided metadata is preserved in the final response.
4dbe756 to
7516cf9
Compare
Main goal of this PR is to add metadata both as input and output to the BaseGenerator (needed for other subclasses)
Thread
metadata: dict[str, Any] | Nonethrough the entire completion pipeline (complete, middleware, _call_model) and add ametadatafield toResponse. Change_call_modelreturn type from tuple toResponsefor extensibility. Update cursor rule accordingly.Description
Related Issue
Type of Change
Checklist
CODE_OF_CONDUCT.mddocument.CONTRIBUTING.mdguide.pdm.lockrunningpdm update-lock(only applicable whenpyproject.tomlhas beenmodified)