Skip to content

feat: add guarded durable-memory ADK recipe - #2507

Closed
vgudur-dev wants to merge 5 commits into
google:mainfrom
vgudur-dev:contrib/amg-memory-guard
Closed

vgudur-dev wants to merge 5 commits into
google:mainfrom
vgudur-dev:contrib/amg-memory-guard

Conversation

@vgudur-dev

Copy link
Copy Markdown

Summary

This contribution adds a standalone community recipe that places OWASP Agent Memory Guard (AMG) at the durable-session-state boundary of a Google ADK agent. It retains a benign external observation while blocking a representative indirect prompt-injection payload before it reaches session state.

The recipe follows the repository’s standalone Python layout and includes a manifest, pyproject.toml, environment example, runnable agent module, README, and isolated tests.

Demonstrated control boundary

Tool-derived observations are marked as EXTERNAL_TOOL, every proposed durable write passes through MemoryGuard(policy=Policy.strict()), and ADK state is updated only after AMG permits the operation. A blocked write returns structured security information for the application’s logging or incident workflow.

Validation

The recipe passed the repository’s recipe validation, manifest schema, placement checks, README checks, Ruff format/lint checks, and two isolated no-network tests. It uses no model API key and makes no production-security guarantee; it is a focused implementation pattern for an ADK durable-memory boundary.

@vgudur-dev
vgudur-dev requested a review from happyhuman as a code owner August 13, 2026 05:50
@google-cla

google-cla Bot commented Aug 13, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

[project]
name = "amg-memory-guard"
version = "0.1.0"
description = "Guard Google ADK durable session-state writes with OWASP Agent Memory Guard."

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 doesn't match description in manifest.yaml ("A Google ADK recipe that screens external observations before they are committed to durable session state."), and check_recipe_pyproject.py fails the PR when the two disagree. I suggest matching this one to the manifest.

"rule": exc.rule,
}

tool_context.state["guarded_external_observation"] = content

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.

It seems the state write happens whatever action comes back as, since only a raised PolicyViolation skips it. Is allow the only outcome that doesn't raise?

if tool_context is None:
return {"status": "error", "message": "ADK tool context is required."}

session_id = tool_context._invocation_context.session.id

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.

_invocation_context isn't guarded like tool_context just above

@@ -0,0 +1 @@
MODEL_NAME=gemini-3.5-flash

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.

MODEL_NAME is the only key here — should GOOGLE_GENAI_USE_VERTEXAI and the credentials vars go in too? contrib/python/market-research-agent/.env.example has them, and the README sends the reader through cp .env.example .env before adk run.

@@ -0,0 +1,18 @@
"""Google ADK durable-memory protection recipe."""

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.

licence header sits under the docstring in this one

@happyhuman happyhuman left a comment

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.

Please go through the comments, and also the failed workflows and fix them.

@github-actions

Copy link
Copy Markdown
Contributor

This pull request has had no activity for 60 days, so it has been labelled stale.

If it is still wanted, a comment or a push is enough to reset the clock. Otherwise it will be closed automatically in 30 days.

Nothing about this is final — a closed pull request reopens with one click, and your commits are untouched on your own branch.

Maintainers: apply keep-open to exempt this permanently. Thresholds live in .github/policy.yml under stale_policy.

@github-actions github-actions Bot added the stale No activity for the period set in .github/policy.yml label Oct 19, 2026
@tommywagz
tommywagz self-requested a review as a code owner October 23, 2026 02:59
@github-actions

Copy link
Copy Markdown
Contributor

This pull request isn't ready for review yet.

I removed the review request for tommywagz until the items below are fixed.

Failing checks (1)

Fix the failing checks. Once everything is green I will re-request the review automatically, so there is no need to ping anyone. This is re-checked every 15 minutes.

Applied by the review gate (.github/review-gate-config.yml); the status/not-ready-for-review label is removed on release.

@github-actions github-actions Bot added the status/not-ready-for-review Review requests held until checks pass and bot comments are resolved label Oct 23, 2026

@github-actions github-actions Bot left a comment

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.

Automated House Rules review — 1 finding(s).

Also, on lines this PR does not change:

  • contrib/python/amg-memory-guard/Dockerfile:1 — [CRITICAL] required file missing: Dockerfile (.github/policy.yml required_files)


def test_agent_runnability() -> None:
"""Verify that the recipe module imports and exports a root agent."""
os.environ.setdefault("MODEL_NAME", "gemini-3.5-flash")

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.

[MINOR] env read carries a hardcoded default (second argument is a hardcoded default); 2 occurrence(s) across 2 file(s). Defaults belong in .env.example, not in the code (contrib/python/amg-memory-guard/tests/test_runnability.py:20; contrib/python/amg-memory-guard/tests/test_memory_screening.py:17)

@github-actions github-actions Bot left a comment

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.

Automated Maintainability review — 2 finding(s).


Round 1 · 0 of this PR's 25 automated comments used · this round is capped at 20 across all reviewers.


import os

os.environ.setdefault("MODEL_NAME", "gemini-3.5-flash")

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.

[MINOR] Is there a reason MODEL_NAME is hardcoded here instead of reading configuration?

session = _FakeSession()


class FakeToolContext:

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.

[MINOR] inconsistent with _FakeSession naming

@github-actions github-actions Bot left a comment

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.

Automated Hygiene review — 2 finding(s).


Round 1 · 0 of this PR's 25 automated comments used · this round is capped at 20 across all reviewers.

- "OWASP Agent Memory Guard"

ownership:
team: "community"

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.

[MINOR] Can you please add a real team here?

## References

- [OWASP Agent Memory Guard](https://github.com/OWASP/www-project-agent-memory-guard)
- [Google ADK recipes](https://github.com/google/adk-samples)

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.

[MINOR] outdated repository url here

@github-actions github-actions Bot left a comment

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.

Automated Correctness review — 2 finding(s).


Round 1 · 0 of this PR's 25 automated comments used · this round is capped at 20 across all reviewers.


from dotenv import load_dotenv

load_dotenv()

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.

[MAJOR] Can you please export root_agent here? adk run amg_memory_guard_adk expects it to be available on the package.



def remember_external_observation(
content: str, tool_context: ToolContext | None = None

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.

[MAJOR] Is there a reason tool_context defaults to None? In ADK tools, context parameters should be tool_context: ToolContext so the framework injects them rather than exposing them in the model schema.

@tommywagz

Copy link
Copy Markdown
Collaborator

There have been reviews given and critiques made over two months ago. The use case is strong but the features displayed beyond the basics are sparing and don't give a real fully developed, deployable ADK agent.

Unfortunately, this leads me to closing the PR, but thank you for the contribution!

@tommywagz tommywagz closed this Oct 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stale No activity for the period set in .github/policy.yml status/not-ready-for-review Review requests held until checks pass and bot comments are resolved

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants