GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat: Add memory related methods to AdkApp · googleapis/python-aiplatform@c49c52b

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • tests/unit/vertex_adk
    • test_reasoning_engine_templates_adk.py
  • vertexai/preview/reasoning_engines/templates
    • adk.py
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎tests/unit/vertex_adk/test_reasoning_engine_templates_adk.py‎

Copy file name to clipboardExpand all lines: tests/unit/vertex_adk/test_reasoning_engine_templates_adk.py
+34Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,40 @@ def test_delete_session(self):
370370
response0 = app.list_sessions(user_id="test_user_id")
371371
assert not response0.sessions
372372

373+
@pytest.mark.asyncio
374+
async def test_async_generate_memories(self):
375+
app = reasoning_engines.AdkApp(
376+
agent=Agent(name="test_agent", model=_TEST_MODEL)
377+
)
378+
assert app._tmpl_attrs.get("memory_service") is None
379+
session = app.create_session(user_id="test_user_id")
380+
list(app.stream_query(
381+
user_id="test_user_id",
382+
session_id=session.id,
383+
message="My cat's name is Garfield",
384+
))
385+
await app.async_generate_memories(source=session)
386+
assert app._tmpl_attrs.get("memory_service") is not None
387+
388+
@pytest.mark.asyncio
389+
async def test_async_search_memories(self):
390+
app = reasoning_engines.AdkApp(
391+
agent=Agent(name="test_agent", model=_TEST_MODEL)
392+
)
393+
assert app._tmpl_attrs.get("memory_service") is None
394+
session = app.create_session(user_id="test_user_id")
395+
list(app.stream_query(
396+
user_id="test_user_id",
397+
session_id=session.id,
398+
message="My cat's name is Garfield",
399+
))
400+
await app.async_generate_memories(source=session)
401+
await app.search_memories(
402+
user_id="test_user_id",
403+
query="What is my cat's name",
404+
)
405+
assert app._tmpl_attrs.get("memory_service") is not None
406+
373407
@pytest.mark.usefixtures("caplog")
374408
def test_enable_tracing(
375409
self,
Collapse file

‎vertexai/preview/reasoning_engines/templates/adk.py‎

Copy file name to clipboardExpand all lines: vertexai/preview/reasoning_engines/templates/adk.py
+40Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -961,6 +961,44 @@ def _asyncio_thread_main():
961961
if isinstance(outcome, RuntimeError):
962962
raise outcome from None
963963

964+
async def async_generate_memories(self, *, source: Any):
965+
"""Generates memories.
966+
967+
Args:
968+
source (Union[Session, Dict[str, Any]]):
969+
Required. The source (e.g. session) for generating memories.
970+
"""
971+
from google.adk.sessions.session import Session
972+
973+
if isinstance(source, Dict):
974+
source = Session.model_validate(source)
975+
elif not isinstance(source, Session):
976+
raise TypeError("source must be a Session object.")
977+
978+
if not self._tmpl_attrs.get("memory_service"):
979+
self.set_up()
980+
return await self._tmpl_attrs.get("memory_service").add_session_to_memory(
981+
session=source,
982+
)
983+
984+
async def async_search_memories(self, *, user_id: str, query: str):
985+
"""Searches memories for the given user.
986+
987+
Args:
988+
user_id: The id of the user.
989+
query: The query to match the memories on.
990+
991+
Returns:
992+
A SearchMemoryResponse containing the matching memories.
993+
"""
994+
if not self._tmpl_attrs.get("memory_service"):
995+
self.set_up()
996+
return await self._tmpl_attrs.get("memory_service").search_memory(
997+
app_name=self._tmpl_attrs.get("app_name"),
998+
user_id=user_id,
999+
query=query,
1000+
)
1001+
9641002
def register_operations(self) -> Dict[str, List[str]]:
9651003
"""Registers the operations of the ADK application."""
9661004
return {
@@ -975,6 +1013,8 @@ def register_operations(self) -> Dict[str, List[str]]:
9751013
"async_list_sessions",
9761014
"async_create_session",
9771015
"async_delete_session",
1016+
"async_generate_memories",
1017+
"async_search_memories",
9781018
],
9791019
"stream": ["stream_query", "streaming_agent_run_with_events"],
9801020
"async_stream": ["async_stream_query"],

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.