Add example: EU AI Act compliance checking with Gemini function calling + Agent Module#1167
Add example: EU AI Act compliance checking with Gemini function calling + Agent Module#1167AgentModuleAdmin wants to merge 11 commits into
Conversation
|
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
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 introduces a new example notebook demonstrating how to leverage Gemini's function calling capabilities to perform EU AI Act compliance checks. It integrates with the Agent Module API, allowing users to autonomously retrieve and apply compliance logic to AI systems, providing a practical, real-world application of AI governance. Highlights
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. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces a new example notebook, Agent_Module_EU_AI_Act_Compliance.ipynb, which demonstrates how to use Gemini's function calling capabilities to interact with an external API for EU AI Act compliance checking. The notebook is well-structured, clear, and provides a practical, self-contained example. It correctly follows the cookbook's best practices, including secure API key handling and proper SDK usage. I have one minor suggestion to improve code readability by adhering to the style guide for long strings. Overall, this is a valuable addition to the cookbook.
| " \"I'm deploying a customer service chatbot in the EU. It handles \"\n", | ||
| " \"insurance claims, collects personal data (name, policy number, \"\n", | ||
| " \"claim details), and makes preliminary claim assessments.\\n\\n\"\n", | ||
| " \"Check this system against EU AI Act requirements for:\\n\"\n", | ||
| " \"1. Data sovereignty and ownership (ETH_001)\\n\"\n", | ||
| " \"2. Transparency and explainability (ETH_003)\\n\"\n", | ||
| " \"3. Human oversight (ETH_006)\"\n", |
There was a problem hiding this comment.
The construction of this long prompt string using implicit string literal concatenation is a bit hard to read. The repository style guide recommends using triple-quoted strings for long strings to improve readability.
| " \"I'm deploying a customer service chatbot in the EU. It handles \"\n", | |
| " \"insurance claims, collects personal data (name, policy number, \"\n", | |
| " \"claim details), and makes preliminary claim assessments.\\n\\n\"\n", | |
| " \"Check this system against EU AI Act requirements for:\\n\"\n", | |
| " \"1. Data sovereignty and ownership (ETH_001)\\n\"\n", | |
| " \"2. Transparency and explainability (ETH_003)\\n\"\n", | |
| " \"3. Human oversight (ETH_006)\"\n", | |
| """I'm deploying a customer service chatbot in the EU. It handles insurance claims, collects personal data (name, policy number, claim details), and makes preliminary claim assessments.\n\nCheck this system against EU AI Act requirements for:\n1. Data sovereignty and ownership (ETH_001)\n2. Transparency and explainability (ETH_003)\n3. Human oversight (ETH_006)""" |
References
- Long text variables should use triple double quotes and proper indentation for better readability. The current implementation uses implicit string concatenation which is less readable. (link)
|
Parece unetodo eficaz y moderno |
Giom-V
left a comment
There was a problem hiding this comment.
Thanks for the submission @AgentModuleAdmin but I wasn't able to run the notebook. Can you also make sure to keep the outputs so one can understant what's happening without running the notebook?
| "\n", | ||
| "status = requests.get(f\"{AGENT_MODULE_API}/api/status\", timeout=10).json()\n", | ||
| "\n", | ||
| "ethics_module_count = status[\"ethics\"][\"node_count\"]\n", |
There was a problem hiding this comment.
Fixed in 7516631. The API renamed this field from status["ethics"] to status["ai_compliance"] after the original submission — that was the KeyError. Updated throughout.
| ")\n", | ||
| "\n", | ||
| "response = chat.send_message(\n", | ||
| " \"\"\"\\\n", |
There was a problem hiding this comment.
I don't think you need the backslashes
There was a problem hiding this comment.
Agreed — removed in 7516631.
| "Check this system against EU AI Act requirements for:\n", | ||
| "1. Data sovereignty and ownership (ETH_001)\n", | ||
| "2. Transparency and explainability (ETH_003)\n", | ||
| "3. Human oversight (ETH_006)\"\"\"\n", |
There was a problem hiding this comment.
Can you also add more indent to the text and a new line before the closing """ ?
There was a problem hiding this comment.
Done in 7516631 — body indented and newline added before the closing """.
|
Thanks for the review @Giom-V — all four items addressed across commits The root cause of the failure was a server-side schema rename ( Responding to each inline comment below. |
|
Thank you! Appreciate the feedback. |
17ee284 to
4a79993
Compare
|
@googlebot I signed it. |
|
Hi @AgentModuleAdmin, thank you for submitting this example! The EU AI Act compliance checking is a very interesting use case. |
|
Thanks @kkorpal, really appreciate you picking this up. Quick status on the automated checks:
On the third-party framework question - totally fair for you to check with the core maintainers. Some context that may help inform your decision: The value we intended here is Gemini-centric, not Agent Module-centric. The notebook is really a worked example of Gemini's automatic function calling handling multi-step tool use against a live external knowledge source, for a use case Gemini developers building production agents will actually face (EU AI Act Annex III enforcement activates August 2, 2026 — that's ~100 days away for anyone shipping to EU users). The pattern a reader walks away with is reusable against any stable external knowledge API, MCP-compatible or REST - Agent Module is the concrete example, not the subject. A few things that might help the maintainer discussion:
Obviously take the time you need on the maintainer side. Just let me know what shape works best and I'll iterate on it. Thank you! |
|
Hi @AgentModuleAdmin, thank you for the detailed and thoughtful context! I appreciate your willingness to adapt the notebook to fit the repository's guidelines. The use case is definitely compelling. |
|
Hey @kkorpal, Absolutely, am getting to this ASAP. I really appreciate your patience and the detailed re-run feedback. My first time contributing to the Gemini cookbook and I'm still learning the repo's CI quirks (colab.name metadata, the second_person style rule, CLA email matching) - all solvable, just taking me a few cycles to get right. Will be back shortly with a proper fix-up commit and a status reply, today if possible. Thanks for your patience while I sort it out! |
- status["ethics"] -> status["ai_compliance"] (v0.9.21 schema rename; was the KeyError that blocked the reviewer run) - Remove unnecessary backslash line-continuations in the compliance_run prompt string; indent body; newline before closing """ - Replace static 22-row module table with dynamic discovery pointer (/api/status, /api/demo, /llms.txt) so the snapshot never goes stale - Branding: "ethics modules" -> "AI Compliance modules" in human-facing markdown; vertical slug documented as ai-compliance with ethics as legacy alias (both still accepted by the API) - Correct ETH_001 EU AI Act mapping (Art. 9 + 10, not 10 + 13)
Follow-up to the schema/formatting fixes. Colab testing surfaced a runtime bug: the Agent Module API returns a masked preview of an existing trial key (e.g. `am_trial_841...f660`) if you request a new one while the old one is still active, and the original notebook wrapper blindly stored the preview — corrupting _trial_key and breaking every downstream retrieve_compliance_logic call. Changes: - Generate a unique per-run agent_id (uuid suffix) so reruns within 24 hours do not collide with a still-active trial on the server - Make get_trial_key idempotent (short-circuit if _trial_key already set in this session) so Gemini tool loops cannot re-trigger it - Detect status=="already_active" in the MCP response and refuse to store the masked preview; surface a clear error instead - Remove get_trial_key from the tools list passed to Gemini. Trial bootstrap is a setup step, not a runtime tool — the model should only see retrieve_compliance_logic and submit_proof_of_value - Reframe the cell 27 preamble to explain the setup/runtime split
- Add Colab badge to notebook title cell (tfo-notebook-buttons CI check) - Add notebook entry to examples/README.md table (new-example-links CI check)
- Rewords 'Agent-native' to 'Purpose-built for autonomous agents' in the branding cell to clear google::inclusive_language lint flag - Applies tensorflow_docs.tools.nbfmt formatting pass to clear Notebook format check - No other content changes; all 21 cell outputs preserved
…t + second_person checks
873d0c3 to
c4ca79a
Compare
|
Update for @kkorpal: rebased the branch onto latest main (removes Embeddings.ipynb and Get_started_TTS.ipynb from the CI change-set — those were flagged by the lint/format runs but aren't part of this PR). On top of the rebase, one new commit (c4ca79a) fixing:
Local @googlebot I signed it! |
c4ca79a to
839e475
Compare
|
Marking this pull request as stale since it has been open for 14 days with no activity. This PR will be closed if no further activity occurs. |
Closes #1163
Summary
examples/Agent_Module_EU_AI_Act_Compliance.ipynb— a complete notebook demonstrating Gemini function calling with a live EU AI Act compliance APIWhat the notebook covers
client.chats.create()Technical details
google-genaiSDK (not legacy)gemini-2.5-flash%pip install,userdata.get("GOOGLE_API_KEY"), Colab formsLinks
🤖 Generated with Claude Code