feat(py/genkit): add context, name, client_header to Genkit constructor#4512
feat(py/genkit): add context, name, client_header to Genkit constructor#4512
Conversation
Summary of ChangesHello @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 Python Genkit SDK by introducing new configuration options to its main constructor, achieving greater feature parity with the JavaScript SDK. These additions provide developers with more control over application context, improve visibility in developer tools through custom naming, and allow for detailed API client attribution. The changes aim to make the Genkit Python SDK more flexible and observable for users. 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 effectively adds context, name, and client_header parameters to the Genkit constructor, achieving parity with the JS SDK. The changes are well-implemented across the core and AI layers, including updates to the registry, runtime manager, and constants. The introduction of thread-safe functions for managing the client header is a good addition. The new functionality is thoroughly covered by new tests, which is excellent.
I have one suggestion to improve the testability of the new client header functionality by making a small adjustment to the set_client_header API. Overall, this is a solid contribution.
… and merge order Comprehensive update reflecting current state of all merged and open PRs: Merged PRs reflected: - #4511 (G5+G6: span_id + X-Genkit-Span-Id) → marked Done - #4507+#4508 (G11: CHANGELOG.md) → marked Done - #4509 (plugin test coverage uplift) → marked Done - #4505 (PARITY_AUDIT.md baseline) → marked Done - #4488 (sample naming, py.typed, check_consistency) → marked Done Open PRs tracked: - #4516 (G1+G2: model middleware storage) - #4514 (Transfer-Encoding fix) - #4513 (G18: multipart tools) - #4512 (G20-G22: constructor parity) - #4510 (G3+G12-G16: middleware functions) - #4504 (Checks plugin) - #4495, #4494, #4401 (bug fixes + reflection v2) New content: - Middleware Taxonomy section with 4-layer diagram - Decision guide for which middleware layer to use - G38 gap (auto-wiring via get_model_middleware) - PR merge order graph with file conflict matrix - Updated summary metrics and phase tables
… and merge order Comprehensive update reflecting current state of all merged and open PRs: Merged PRs reflected: - #4511 (G5+G6: span_id + X-Genkit-Span-Id) → marked Done - #4507+#4508 (G11: CHANGELOG.md) → marked Done - #4509 (plugin test coverage uplift) → marked Done - #4505 (PARITY_AUDIT.md baseline) → marked Done - #4488 (sample naming, py.typed, check_consistency) → marked Done Open PRs tracked: - #4516 (G1+G2: model middleware storage) - #4514 (Transfer-Encoding fix) - #4513 (G18: multipart tools) - #4512 (G20-G22: constructor parity) - #4510 (G3+G12-G16: middleware functions) - #4504 (Checks plugin) - #4495, #4494, #4401 (bug fixes + reflection v2) New content: - Middleware Taxonomy section with 4-layer diagram - Decision guide for which middleware layer to use - G38 gap (auto-wiring via get_model_middleware) - PR merge order graph with file conflict matrix - Updated summary metrics and phase tables
Add three new constructor parameters for JS SDK parity: - context: default action context stored on registry.context - name: display name for dev tooling, written to runtime file - client_header: additional x-goog-api-client attribution These mirror GenkitOptions.context, GenkitOptions.name, and GenkitOptions.clientHeader from the JS SDK. Also adds get_client_header() and set_client_header() functions matching the JS SDK global header management pattern. The google-genai plugin (and others) can use get_client_header() to retrieve the full attribution header. Includes 12 new tests covering constants, constructor params, and runtime file name propagation.
Address review feedback: allow set_client_header(None) to clear additional attribution, enabling tests to use the public API for cleanup instead of manipulating private module state. Also adds a dedicated test for the None reset behavior.
1da7738 to
fb99cfd
Compare
… and merge order Comprehensive update reflecting current state of all merged and open PRs: Merged PRs reflected: - #4511 (G5+G6: span_id + X-Genkit-Span-Id) → marked Done - #4507+#4508 (G11: CHANGELOG.md) → marked Done - #4509 (plugin test coverage uplift) → marked Done - #4505 (PARITY_AUDIT.md baseline) → marked Done - #4488 (sample naming, py.typed, check_consistency) → marked Done Open PRs tracked: - #4516 (G1+G2: model middleware storage) - #4514 (Transfer-Encoding fix) - #4513 (G18: multipart tools) - #4512 (G20-G22: constructor parity) - #4510 (G3+G12-G16: middleware functions) - #4504 (Checks plugin) - #4495, #4494, #4401 (bug fixes + reflection v2) New content: - Middleware Taxonomy section with 4-layer diagram - Decision guide for which middleware layer to use - G38 gap (auto-wiring via get_model_middleware) - PR merge order graph with file conflict matrix - Updated summary metrics and phase tables
… and merge order Comprehensive update reflecting current state of all merged and open PRs: Merged PRs reflected: - #4511 (G5+G6: span_id + X-Genkit-Span-Id) → marked Done - #4507+#4508 (G11: CHANGELOG.md) → marked Done - #4509 (plugin test coverage uplift) → marked Done - #4505 (PARITY_AUDIT.md baseline) → marked Done - #4488 (sample naming, py.typed, check_consistency) → marked Done Open PRs tracked: - #4516 (G1+G2: model middleware storage) - #4514 (Transfer-Encoding fix) - #4513 (G18: multipart tools) - #4512 (G20-G22: constructor parity) - #4510 (G3+G12-G16: middleware functions) - #4504 (Checks plugin) - #4495, #4494, #4401 (bug fixes + reflection v2) New content: - Middleware Taxonomy section with 4-layer diagram - Decision guide for which middleware layer to use - G38 gap (auto-wiring via get_model_middleware) - PR merge order graph with file conflict matrix - Updated summary metrics and phase tables
… and merge order Comprehensive update reflecting current state of all merged and open PRs: Merged PRs reflected: - #4511 (G5+G6: span_id + X-Genkit-Span-Id) → marked Done - #4507+#4508 (G11: CHANGELOG.md) → marked Done - #4509 (plugin test coverage uplift) → marked Done - #4505 (PARITY_AUDIT.md baseline) → marked Done - #4488 (sample naming, py.typed, check_consistency) → marked Done Open PRs tracked: - #4516 (G1+G2: model middleware storage) - #4514 (Transfer-Encoding fix) - #4513 (G18: multipart tools) - #4512 (G20-G22: constructor parity) - #4510 (G3+G12-G16: middleware functions) - #4504 (Checks plugin) - #4495, #4494, #4401 (bug fixes + reflection v2) New content: - Middleware Taxonomy section with 4-layer diagram - Decision guide for which middleware layer to use - G38 gap (auto-wiring via get_model_middleware) - PR merge order graph with file conflict matrix - Updated summary metrics and phase tables fix: address review comments — fix G1/G2 status consistency, middleware level count, #4514 merged docs(py): update PARITY_AUDIT.md — mark #4494 and #4514 merged, add #4518 Cohere Update PR status tracking: - #4494 (RedactedSpan fix): marked merged - #4514 (Transfer-Encoding fix): marked merged - #4518 (Cohere provider plugin): added as open PR - Updated dependency chain, summary metrics, and open PR counts docs(py): update PARITY_AUDIT.md — add #4519 (Core fix) docs(py): update PARITY_AUDIT.md with latest merged PR status Rationale: Several PRs have merged since the last update. This syncs the document with the current state of all PRs. Changes: - Mark #4495, #4518, #4520 as merged in all tables - Move #4495, #4518 from INDEPENDENT to MERGED in dependency chain - Add #4520 (converter extraction) to merged list - Update summary metrics: 6 open PRs (down from 8) - Simplify Layer 3 deps since #4495 is now merged docs(py): add issue tracker analysis, dependency graph, model conformance roadmap, and sample flow test plan Rationale: Comprehensive update to PARITY_AUDIT.md with 5 new sections (§12–§16) covering: - Cross-SDK issue tracker analysis verified against Python source code - Dependency-aware reverse topological sort roadmap for prioritized fixes - Model conformance testing roadmap with provider parity matrix - Sample flow test plan with optimal execution order for error detection Changes: - §12: Fixability assessment of 9 'likely' issues with code-level verdicts - §13: Dependency graph (W1–W14), file conflict matrix, PR manifest with regression test specifications, sprint-based execution plan - §14: Model conformance roadmap (Phases 0–4), plugin parity matrix, conformance PR mapping, JS-only plugin gaps - §15: Combined roadmap unifying parity gaps, issue fixes, and conformance - §16: Sample flow test plan with 5-phase error detection priority pyramid, 36 samples ordered by feature coverage, quick-start commands, and env var reference table docs(py): add active RFC redesigns (Middleware V2, Bidi, Agent) to parity audit - Add 7 new gaps (G38-G44) for Middleware V2, Bidi Action/Flow/Model, Agent primitive, Plugin V2, and Reflection API V2 - Mark middleware gaps G1-G3, G12-G16 as PAUSED (blocked on upstream JS #4515 and Go #4422 Middleware V2 RFCs) - Mark G19 (Model API V2) as SUPERSEDED by G38 + G41 - Add deep-dive sections §8l-8p covering all 5 active RFC designs - Update dependency graph: critical path now G38→G2→G1→G3 (4 levels) - Restructure phased roadmap: Phase 1 (unblocked), Phase 2-3 (paused), Phase 4 (bidi/agent, blocked), Phase 5 (integration), Phase 6 (deferred) - Update §5g cross-SDK gaps table with new primitives - Update §9b status tracker and §9c dependency matrix - Update summary metrics: 36 total gaps, 8 paused, 6 upstream-blocked docs(py): update PARITY_AUDIT.md PR status to 2026-02-11 Comprehensive status update reflecting 23 PRs merged since last update (2026-02-09), 3 PRs closed/superseded, and 11 currently open PRs including releasekit tooling, dotprompt fixes, and CI workflow migration. Key changes: - §14f: Checks plugin marked as merged (#4504) - §15b: Split into Recently Merged / Closed / Currently Open - §15c: Updated metrics (31 merged, 11 open, 3 closed) - Added releasekit PRs (14 merged, 3 open) as new workstream
Summary
Adds three new parameters to the
Genkitconstructor for JS SDK parity:contextGenkitOptions.contextregistry.contextnameGenkitOptions.nameclient_headerGenkitOptions.clientHeaderx-goog-api-clientheaderChanges
Core (
genkit.core):constants.py— Addedget_client_header()andset_client_header()(thread-safe, matching JS global pattern)registry.py— Addedcontextandnameattributes toRegistry__init__.py— Exported new functionsAI layer (
genkit.ai):_aio.py— Addedcontext,name,client_headerparams toGenkit.__init___base_async.py— Propagatedcontext/nameto registry andRuntimeManager_runtime.py— Addednameto runtime file JSON metadata__init__.py— Exportedget_client_headerandset_client_headerTests (12 new, 512 total pass):
constants_test.py— 3 tests for header get/set functionsgenkit_api_test.py— 6 tests for constructor parametersruntime_test.py— 3 tests for runtime file name fieldTesting