Skip to content

Add example: EU AI Act compliance checking with Gemini function calling + Agent Module#1167

Open
AgentModuleAdmin wants to merge 11 commits into
google-gemini:mainfrom
AgentModuleAdmin:add-agent-module-example
Open

Add example: EU AI Act compliance checking with Gemini function calling + Agent Module#1167
AgentModuleAdmin wants to merge 11 commits into
google-gemini:mainfrom
AgentModuleAdmin:add-agent-module-example

Conversation

@AgentModuleAdmin
Copy link
Copy Markdown

Closes #1163

Summary

  • Adds examples/Agent_Module_EU_AI_Act_Compliance.ipynb — a complete notebook demonstrating Gemini function calling with a live EU AI Act compliance API
  • Three tool functions wrap Agent Module's MCP endpoint (get trial key, retrieve compliance logic, submit assessment)
  • Fully self-contained: no API key needed to run (free 24hr trial issued via tool function)
  • Follows template, contributing guidelines, and style guide

What the notebook covers

  • Wrapping an external REST API as Gemini-callable Python functions
  • Automatic function calling with client.chats.create()
  • Multi-step compositional tool use (4 sequential calls)
  • Inspecting function call history
  • A real-world compliance use case with a live API

Technical details

  • Uses google-genai SDK (not legacy)
  • Defaults to gemini-2.5-flash
  • %pip install, userdata.get("GOOGLE_API_KEY"), Colab forms
  • Apache 2.0 license cell, Colab badge, contributor attribution
  • Error handling, "Next steps" with cross-links

Links

🤖 Generated with Claude Code

@review-notebook-app
Copy link
Copy Markdown

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@github-actions github-actions Bot added status:awaiting review PR awaiting review from a maintainer component:examples Issues/PR referencing examples folder labels Mar 23, 2026
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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

  • New Example Notebook: Added a new Jupyter notebook (examples/Agent_Module_EU_AI_Act_Compliance.ipynb) to demonstrate EU AI Act compliance checking.
  • Gemini Function Calling: Showcases Gemini's function calling capabilities by integrating with a live Agent Module API for compliance assessments.
  • Tool Integration: Implemented three Python tool functions to wrap Agent Module's MCP endpoint for trial key acquisition, compliance logic retrieval, and assessment submission.
  • Self-Contained Demo: The notebook is fully self-contained, providing a free 24-hour trial key via a tool function, eliminating the need for external API keys.
  • Multi-step Tool Use: Illustrates automatic function calling, multi-step compositional tool use, and inspection of the function call history within the Gemini chat.
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.

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
Copy Markdown
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 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.

Comment on lines +490 to +496
" \"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",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

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.

Suggested change
" \"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
  1. 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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Ok

@JAMSspec
Copy link
Copy Markdown

Parece unetodo eficaz y moderno

Copy link
Copy Markdown
Collaborator

@Giom-V Giom-V left a comment

Choose a reason for hiding this comment

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

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",
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This didn't work for me

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

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",
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I don't think you need the backslashes

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

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",
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can you also add more indent to the text and a new line before the closing """ ?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done in 7516631 — body indented and newline added before the closing """.

@AgentModuleAdmin
Copy link
Copy Markdown
Author

Thanks for the review @Giom-V — all four items addressed across commits 7516631 through 74ea163, and the notebook is now saved with full cell outputs.

The root cause of the failure was a server-side schema rename (status["ethics"]status["ai_compliance"]) that shipped after the original submission. Running the notebook end-to-end also surfaced a few runtime edge cases (trial key collision handling, auth field naming) that are now defended against in the client code.

Responding to each inline comment below.

@AgentModuleAdmin
Copy link
Copy Markdown
Author

Thank you! Appreciate the feedback.

@AgentModuleAdmin AgentModuleAdmin force-pushed the add-agent-module-example branch from 17ee284 to 4a79993 Compare April 12, 2026 14:30
@AgentModuleAdmin
Copy link
Copy Markdown
Author

@googlebot I signed it.

@kkorpal kkorpal self-assigned this Apr 20, 2026
@kkorpal kkorpal added the status:awaiting response Awaiting a response from the author label Apr 20, 2026
@kkorpal
Copy link
Copy Markdown
Collaborator

kkorpal commented Apr 20, 2026

Hi @AgentModuleAdmin, thank you for submitting this example! The EU AI Act compliance checking is a very interesting use case.
Before we can proceed with any review, there are a few automated checks that need to be resolved:
Google CLA: It looks like you have not signed the Google Contributor License Agreement (CLA). We cannot review or merge any code until this is signed. Please click the "Details" link next to the failing cla/google check below and follow the instructions.
Notebook Format & Linting: The automated CI checks for notebook formatting and linting are currently failing. Please check the action logs, run the formatting tools locally, and push the fixes.
Additionally, because this notebook relies heavily on an external framework (Agent Module), I will need to discuss with the core maintainers if this aligns with our current guidelines for third-party tools in the Cookbook.
Please let us know once the CLA is signed and the CI checks are green so we can continue!

@AgentModuleAdmin
Copy link
Copy Markdown
Author

Thanks @kkorpal, really appreciate you picking this up.

Quick status on the automated checks:

  • CLA: Was signed under AgentModuleAdmin with a public email now attached to the commit history. Please let me know if it doesn't refresh and I'll look again.

  • Notebook lint: The flag was on "Agent-native" in the branding cell at the top - I've reworded that line to "Purpose-built for autonomous agents" and pushed the fix.

  • Notebook format: Re-ran python3 -m tensorflow_docs.tools.nbfmt locally and pushed the normalized file.

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:

  1. The API is versioned (currently v0.9.23) with a public changelog at /v1/changelog, and the notebook uses a self-issued free trial key (no signup, no auth to break). Happy to commit to updating the notebook on any breaking API change on our side.

  2. Happy to retitle / reframe if a more generic framing reads better - something like "Multi-step function calling with Gemini against an external compliance API" with a neutralizing note that Agent Module is one of several knowledge APIs that fit the pattern. Whatever lands right for your guidelines.

  3. The cookbook already has integrations with LangChain, LlamaIndex, vector DBs, etc. so if possible, it would be useful to know if there's something specific that distinguishes this submission from those so I can adjust, rather than guess.

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!

@kkorpal
Copy link
Copy Markdown
Collaborator

kkorpal commented Apr 21, 2026

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.
Regarding the automated checks, I just re-ran the workflows, but unfortunately, they are still failing on our end:
CLA: It is still showing as missing. This usually happens if the email address associated with your Git commits does not exactly match the email address you used to sign the CLA.
Format & Lint: These checks are also still failing. Could you please click the "Details" link next to the failing checks at the bottom of this PR? The logs there will show you exactly which lines of code or markdown the bot is still flagging.
Take your time looking into these. Once we can get all the checks green, I will take your excellent points about the framework and generic framing to the maintainer team to figure out the best path forward for this PR!

@AgentModuleAdmin
Copy link
Copy Markdown
Author

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
@AgentModuleAdmin AgentModuleAdmin force-pushed the add-agent-module-example branch from 873d0c3 to c4ca79a Compare April 21, 2026 15:28
@AgentModuleAdmin
Copy link
Copy Markdown
Author

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:

  • colab.name metadata aligned to the repo filename (clears Notebook format)
  • cell 30 demo prompt rewritten in third-person (clears second_person lint)

Local nbfmt --test passes and no first-person pronouns remain in the notebook. Workflows will need re-approval on the new tip to run.

@googlebot I signed it!

@AgentModuleAdmin AgentModuleAdmin force-pushed the add-agent-module-example branch from c4ca79a to 839e475 Compare April 23, 2026 13:46
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 7, 2026

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.

@github-actions github-actions Bot added the status:stale Issue/PR is marked for closure due to inactivity label May 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component:examples Issues/PR referencing examples folder status:awaiting response Awaiting a response from the author status:awaiting review PR awaiting review from a maintainer status:stale Issue/PR is marked for closure due to inactivity

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add example: EU AI Act compliance checking with Gemini function calling + Agent Module

5 participants