⚠ This page is served via a proxy. Original site: https://github.com
This service does not collect credentials or authentication data.
Skip to content

Conversation

@madhavmadupu
Copy link

Description

Fixes #13734

Added new Python code snippets for Vertex AI Agent Engine (Reasoning Engine).
The following operations are covered:

  • Creating an Agent Engine instance with Memory Bank configuration.
  • Generating memories for an Agent Engine instance.
  • Deleting an Agent Engine instance.

These snippets include the required region tags for documentation integration and have accompanying unit tests in test_agent_engine_examples.py.

Checklist

@madhavmadupu madhavmadupu requested review from a team as code owners January 12, 2026 16:32
@snippet-bot
Copy link

snippet-bot bot commented Jan 12, 2026

Here is the summary of changes.

You are about to add 3 region tags.

This comment is generated by snippet-bot.
If you find problems with this result, please file an issue at:
https://github.com/googleapis/repo-automation-bots/issues.
To update this comment, add snippet-bot:force-run label or use the checkbox below:

  • Refresh this comment

@product-auto-label product-auto-label bot added the samples Issues that are directly related to samples. label Jan 12, 2026
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @madhavmadupu, 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 expands the Python documentation samples for Vertex AI by introducing new examples for the Agent Engine (Reasoning Engine). These samples demonstrate core operations such as creating and deleting Agent Engine instances, and generating memories, providing users with practical, ready-to-use code for integrating this service. Additionally, a minor but important fix was applied to an existing image generation sample to prevent potential errors related to directory creation.

Highlights

  • New Vertex AI Agent Engine Samples: Introduced new Python code snippets for Vertex AI Agent Engine (Reasoning Engine).
  • Agent Engine Operations: Added functionality for creating, generating memories for, and deleting Agent Engine instances.
  • Unit Tests: Included comprehensive unit tests for the new Agent Engine examples to ensure correctness and provide usage patterns.
  • Image Generation Sample Improvement: Improved image saving robustness in an existing image generation sample by ensuring the output directory exists before saving an image.
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.

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

  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
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 adds new Python code snippets for Vertex AI Agent Engine, covering creation, memory generation, and deletion. The changes are a good addition, but there are several areas for improvement, particularly in the test suite. The tests currently leak cloud resources and contain an empty test case, which are critical issues to address. Additionally, the new sample code can be improved for better readability and maintainability by adding type hints and simplifying client initialization. My review includes specific suggestions to fix these issues.

@madhavmadupu
Copy link
Author

I have addressed all bot feedback:

  1. Updated region tags to the correct product prefix.
  2. Added finally blocks for resource cleanup in tests to prevent leaks.
  3. Implemented functional tests for the delete operation.
  4. Added return type hints and simplified the client initialization as suggested.

The PR is now ready for final human review. Thank you!

@madhavmadupu
Copy link
Author

Note to reviewer: You may notice that this PR includes a commit (0276892) from my other PR regarding the image generation output folder. I accidentally branched off my previous feature branch instead of main. If you'd like me to rebase this PR to remove those unrelated commits, please let me know and I'm happy to do so!

Copy link

@yeesian yeesian left a comment

Choose a reason for hiding this comment

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

Thank you!

@gericdong gericdong added the kokoro:run Add this label to force Kokoro to re-run the tests. label Jan 12, 2026
@kokoro-team kokoro-team removed the kokoro:run Add this label to force Kokoro to re-run the tests. label Jan 12, 2026
@madhavmadupu
Copy link
Author

Hi @gericdong and @yeesian, I have updated the PR to address the latest feedback:

  • License Headers: Updated the copyright year to 2026 across all four files.
  • Model Update: Updated the default model in create_agent_engine_with_memorybank_config to gemini-3-flash. This ensures the samples utilize the latest generation of intelligence optimized for agentic reasoning as of January 2026.

The PR should be ready for final review. Thank you!

@gericdong gericdong added the kokoro:run Add this label to force Kokoro to re-run the tests. label Jan 13, 2026
@kokoro-team kokoro-team removed the kokoro:run Add this label to force Kokoro to re-run the tests. label Jan 13, 2026
@yeesian
Copy link

yeesian commented Jan 13, 2026

Can you address the following linter issues (not all of it is introduced by this PR, but it's still required for it to be merged)?

cd generative_ai/reasoning_engine
cp /workspace/noxfile-template.py noxfile.py
cd generative_ai/reasoning_engine
nox -s lint
nox > Running session lint
nox > Creating virtual environment (virtualenv) using python3.12 in .nox/lint
nox > python -m pip install flake8 flake8-import-order flake8-annotations
nox > flake8 --show-source --builtin=gettext --max-complexity=20 --import-order-style=google '--exclude=.nox,.cache,env,lib,generated_pb2,*_pb2.py,*_pb2_grpc.py' --ignore=ANN101,ANN102,E121,E123,E126,E203,E226,E24,E266,E501,E704,W503,W504,I202 --max-line-length=88 --application-import-names test_reasoning_engine_examples,delete_agent_engine,get_reasoning_engine_example,test_agent_engine_examples,create_agent_engine,create_reasoning_engine_example,.nox,query_reasoning_engine_example,noxfile_config,create_reasoning_engine_advanced_example,generate_memories,delete_reasoning_engine_example,list_reasoning_engine_example,noxfile .
./delete_agent_engine.py:23:1: W293 blank line contains whitespace
    
^
./generate_memories.py:23:1: W293 blank line contains whitespace
    
^
./test_agent_engine_examples.py:16:1: I100 Import statements are in the wrong order. 'import os' should be before 'import pytest' and in a different group.
import os
^
./test_agent_engine_examples.py:16:1: I201 Missing newline between import groups. 'import os' is identified as Stdlib and 'import pytest' is identified as Third Party.
import os
^
./test_agent_engine_examples.py:18:1: F401 'google.cloud.aiplatform' imported but unused
from google.cloud import aiplatform
^
./test_agent_engine_examples.py:22:1: I100 Import statements are in the wrong order. 'import delete_agent_engine' should be before 'import generate_memories'
import delete_agent_engine
^
./test_agent_engine_examples.py:27:1: E302 expected 2 blank lines, found 1
@pytest.fixture(scope="module")
^
./test_agent_engine_examples.py:28:22: ANN201 Missing return type annotation for public function
def agent_engine_id():
                     ^
./test_agent_engine_examples.py:50:1: E302 expected 2 blank lines, found 1
@pytest.mark.skipif(not PROJECT_ID, reason="GOOGLE_CLOUD_PROJECT not set")
^
./test_agent_engine_examples.py:51:30: ANN001 Missing type annotation for function argument 'agent_engine_id'
def test_create_agent_engine(agent_engine_id):
                             ^
./test_agent_engine_examples.py:51:46: ANN201 Missing return type annotation for public function
def test_create_agent_engine(agent_engine_id):
                                             ^
./test_agent_engine_examples.py:54:1: E302 expected 2 blank lines, found 1
@pytest.mark.skipif(not PROJECT_ID, reason="GOOGLE_CLOUD_PROJECT not set")
^
./test_agent_engine_examples.py:55:28: ANN001 Missing type annotation for function argument 'agent_engine_id'
def test_generate_memories(agent_engine_id):
                           ^
./test_agent_engine_examples.py:55:44: ANN201 Missing return type annotation for public function
def test_generate_memories(agent_engine_id):
                                           ^
./test_agent_engine_examples.py:61:1: E302 expected 2 blank lines, found 1
@pytest.mark.skipif(not PROJECT_ID, reason="GOOGLE_CLOUD_PROJECT not set")
^
./test_agent_engine_examples.py:62:31: ANN201 Missing return type annotation for public function
def test_delete_agent_engine():
                              ^
./test_agent_engine_examples.py:67:1: W293 blank line contains whitespace
    
^
./test_agent_engine_examples.py:74:1: E302 expected 2 blank lines, found 1
def test_imports():
^
./test_agent_engine_examples.py:74:19: ANN201 Missing return type annotation for public function
def test_imports():
                  ^
nox > Command flake8 --show-source --builtin=gettext --max-complexity=20 --import-order-style=google '--exclude=.nox,.cache,env,lib,generated_pb2,*_pb2.py,*_pb2_grpc.py' --ignore=ANN101,ANN102,E121,E123,E126,E203,E226,E24,E266,E501,E704,W503,W504,I202 --max-line-length=88 --application-import-names test_reasoning_engine_examples,delete_agent_engine,get_reasoning_engine_example,test_agent_engine_examples,create_agent_engine,create_reasoning_engine_example,.nox,query_reasoning_engine_example,noxfile_config,create_reasoning_engine_advanced_example,generate_memories,delete_reasoning_engine_example,list_reasoning_engine_example,noxfile . failed with exit code 1
nox > Session lint failed.
make: *** [Makefile:40: test] Error 1
/workspace/generative_ai/reasoning_engine
PWD: /workspace/generative_ai/reasoning_engine

 Testing failed: Nox returned a non-zero exit code. 

The python unit test failure (see below) also seem to suggest that e.g. https://github.com/GoogleCloudPlatform/python-docs-samples/blob/main/generative_ai/reasoning_engine/requirements.txt needs to be updated to more recent versions of google-cloud-aiplatform

=================================== FAILURES ===================================
___________________________ test_delete_agent_engine ___________________________
Traceback (most recent call last):
  File "/workspace/generative_ai/reasoning_engine/.nox/py-3-9/lib/python3.9/site-packages/_pytest/runner.py", line 341, in from_call
    result: Optional[TResult] = func()
  File "/workspace/generative_ai/reasoning_engine/.nox/py-3-9/lib/python3.9/site-packages/_pytest/runner.py", line 241, in 
    lambda: runtest_hook(item=item, **kwds), when=when, reraise=reraise
  File "/workspace/generative_ai/reasoning_engine/.nox/py-3-9/lib/python3.9/site-packages/pluggy/_hooks.py", line 512, in __call__
    return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
  File "/workspace/generative_ai/reasoning_engine/.nox/py-3-9/lib/python3.9/site-packages/pluggy/_manager.py", line 120, in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
  File "/workspace/generative_ai/reasoning_engine/.nox/py-3-9/lib/python3.9/site-packages/pluggy/_callers.py", line 167, in _multicall
    raise exception
  File "/workspace/generative_ai/reasoning_engine/.nox/py-3-9/lib/python3.9/site-packages/pluggy/_callers.py", line 139, in _multicall
    teardown.throw(exception)
  File "/workspace/generative_ai/reasoning_engine/.nox/py-3-9/lib/python3.9/site-packages/_pytest/threadexception.py", line 87, in pytest_runtest_call
    yield from thread_exception_runtest_hook()
  File "/workspace/generative_ai/reasoning_engine/.nox/py-3-9/lib/python3.9/site-packages/_pytest/threadexception.py", line 63, in thread_exception_runtest_hook
    yield
  File "/workspace/generative_ai/reasoning_engine/.nox/py-3-9/lib/python3.9/site-packages/pluggy/_callers.py", line 139, in _multicall
    teardown.throw(exception)
  File "/workspace/generative_ai/reasoning_engine/.nox/py-3-9/lib/python3.9/site-packages/_pytest/unraisableexception.py", line 90, in pytest_runtest_call
    yield from unraisable_exception_runtest_hook()
  File "/workspace/generative_ai/reasoning_engine/.nox/py-3-9/lib/python3.9/site-packages/_pytest/unraisableexception.py", line 65, in unraisable_exception_runtest_hook
    yield
  File "/workspace/generative_ai/reasoning_engine/.nox/py-3-9/lib/python3.9/site-packages/pluggy/_callers.py", line 139, in _multicall
    teardown.throw(exception)
  File "/workspace/generative_ai/reasoning_engine/.nox/py-3-9/lib/python3.9/site-packages/_pytest/logging.py", line 850, in pytest_runtest_call
    yield from self._runtest_for(item, "call")
  File "/workspace/generative_ai/reasoning_engine/.nox/py-3-9/lib/python3.9/site-packages/_pytest/logging.py", line 833, in _runtest_for
    yield
  File "/workspace/generative_ai/reasoning_engine/.nox/py-3-9/lib/python3.9/site-packages/pluggy/_callers.py", line 139, in _multicall
    teardown.throw(exception)
  File "/workspace/generative_ai/reasoning_engine/.nox/py-3-9/lib/python3.9/site-packages/_pytest/capture.py", line 878, in pytest_runtest_call
    return (yield)
  File "/workspace/generative_ai/reasoning_engine/.nox/py-3-9/lib/python3.9/site-packages/pluggy/_callers.py", line 139, in _multicall
    teardown.throw(exception)
  File "/workspace/generative_ai/reasoning_engine/.nox/py-3-9/lib/python3.9/site-packages/_pytest/skipping.py", line 257, in pytest_runtest_call
    return (yield)
  File "/workspace/generative_ai/reasoning_engine/.nox/py-3-9/lib/python3.9/site-packages/pluggy/_callers.py", line 121, in _multicall
    res = hook_impl.function(*args)
  File "/workspace/generative_ai/reasoning_engine/.nox/py-3-9/lib/python3.9/site-packages/_pytest/runner.py", line 183, in pytest_runtest_call
    raise e
  File "/workspace/generative_ai/reasoning_engine/.nox/py-3-9/lib/python3.9/site-packages/_pytest/runner.py", line 173, in pytest_runtest_call
    item.runtest()
  File "/workspace/generative_ai/reasoning_engine/.nox/py-3-9/lib/python3.9/site-packages/_pytest/python.py", line 1627, in runtest
    self.ihook.pytest_pyfunc_call(pyfuncitem=self)
  File "/workspace/generative_ai/reasoning_engine/.nox/py-3-9/lib/python3.9/site-packages/pluggy/_hooks.py", line 512, in __call__
    return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
  File "/workspace/generative_ai/reasoning_engine/.nox/py-3-9/lib/python3.9/site-packages/pluggy/_manager.py", line 120, in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
  File "/workspace/generative_ai/reasoning_engine/.nox/py-3-9/lib/python3.9/site-packages/pluggy/_callers.py", line 167, in _multicall
    raise exception
  File "/workspace/generative_ai/reasoning_engine/.nox/py-3-9/lib/python3.9/site-packages/pluggy/_callers.py", line 139, in _multicall
    teardown.throw(exception)
  File "/workspace/generative_ai/reasoning_engine/.nox/py-3-9/lib/python3.9/site-packages/pluggy/_callers.py", line 53, in run_old_style_hookwrapper
    return result.get_result()
  File "/workspace/generative_ai/reasoning_engine/.nox/py-3-9/lib/python3.9/site-packages/pluggy/_result.py", line 103, in get_result
    raise exc.with_traceback(tb)
  File "/workspace/generative_ai/reasoning_engine/.nox/py-3-9/lib/python3.9/site-packages/pluggy/_callers.py", line 38, in run_old_style_hookwrapper
    res = yield
  File "/workspace/generative_ai/reasoning_engine/.nox/py-3-9/lib/python3.9/site-packages/pluggy/_callers.py", line 121, in _multicall
    res = hook_impl.function(*args)
  File "/workspace/generative_ai/reasoning_engine/.nox/py-3-9/lib/python3.9/site-packages/_pytest/python.py", line 162, in pytest_pyfunc_call
    result = testfunction(**testargs)
  File "/workspace/generative_ai/reasoning_engine/test_agent_engine_examples.py", line 65, in test_delete_agent_engine
    engine = create_agent_engine.create_agent_engine_with_memorybank_config(PROJECT_ID, LOCATION)
  File "/workspace/generative_ai/reasoning_engine/create_agent_engine.py", line 26, in create_agent_engine_with_memorybank_config
    client = vertexai.Client()
  File "/workspace/generative_ai/reasoning_engine/.nox/py-3-9/lib/python3.9/site-packages/vertexai/__init__.py", line 42, in __getattr__
    raise AttributeError(f"module '{__name__}' has no attribute '{name}'")
AttributeError: module 'vertexai' has no attribute 'Client'
- generated xml file: /workspace/generative_ai/reasoning_engine/sponge_log.xml -
=========================== short test summary info ============================
FAILED test_agent_engine_examples.py::test_delete_agent_engine - AttributeErr...
==================== 1 failed, 2 passed, 6 skipped in 2.75s ====================

@madhavmadupu
Copy link
Author

Thanks for pointing those out, @yeesian. I'll address these linter issues and push an update shortly. Working on it!

- Unpin google-cloud-aiplatform in requirements.txt

- Add type hints and cleanup imports in test_agent_engine_examples.py

- Fix whitespace in delete_agent_engine.py and generate_memories.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

samples Issues that are directly related to samples.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add doc samples for Agent Engine

4 participants