mirror of
https://github.com/encounter/adk-python.git
synced 2026-07-09 18:19:28 -07:00
feat: add generate/create modes for Vertex AI Memory Bank writes
add_events_to_memory now supports memory_write_mode to select generate (event-based extraction/consolidation) or create (direct raw fact writes via memory_facts). This now lets custom memory pipelines while keeping generate as the default path Co-authored-by: George Weale <gweale@google.com> PiperOrigin-RevId: 869897256
This commit is contained in:
committed by
Copybara-Service
parent
d5332f4434
commit
811e50a0cb
@@ -412,6 +412,37 @@ class TestCallbackContextAddEventsToMemory:
|
||||
):
|
||||
await context.add_events_to_memory(events=[MagicMock()])
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_add_memory_forwards_metadata(self, mock_invocation_context):
|
||||
"""Tests that add_memory forwards memories and metadata."""
|
||||
memory_service = AsyncMock()
|
||||
mock_invocation_context.memory_service = memory_service
|
||||
memories = ["fact one"]
|
||||
metadata = {"ttl": "6000s"}
|
||||
|
||||
context = CallbackContext(mock_invocation_context)
|
||||
await context.add_memory(memories=memories, custom_metadata=metadata)
|
||||
|
||||
memory_service.add_memory.assert_called_once_with(
|
||||
app_name=mock_invocation_context.session.app_name,
|
||||
user_id=mock_invocation_context.session.user_id,
|
||||
memories=memories,
|
||||
custom_metadata=metadata,
|
||||
)
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_add_memory_no_service_raises(self, mock_invocation_context):
|
||||
"""Tests that add_memory raises ValueError with no service."""
|
||||
mock_invocation_context.memory_service = None
|
||||
|
||||
context = CallbackContext(mock_invocation_context)
|
||||
|
||||
with pytest.raises(
|
||||
ValueError,
|
||||
match=r"Cannot add memory: memory service is not available\.",
|
||||
):
|
||||
await context.add_memory(memories=["fact one"])
|
||||
|
||||
|
||||
class TestToolContextAddSessionToMemory:
|
||||
"""Test the add_session_to_memory method in ToolContext."""
|
||||
|
||||
@@ -486,3 +486,33 @@ class TestContextMemoryMethods:
|
||||
match=r"Cannot add events to memory: memory service is not available\.",
|
||||
):
|
||||
await context.add_events_to_memory(events=[MagicMock()])
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_add_memory_forwards_metadata(self, mock_invocation_context):
|
||||
"""Tests that add_memory forwards memories and metadata."""
|
||||
memory_service = AsyncMock()
|
||||
mock_invocation_context.memory_service = memory_service
|
||||
memories = ["fact one"]
|
||||
metadata = {"ttl": "6000s"}
|
||||
|
||||
context = Context(mock_invocation_context)
|
||||
await context.add_memory(memories=memories, custom_metadata=metadata)
|
||||
|
||||
memory_service.add_memory.assert_called_once_with(
|
||||
app_name=mock_invocation_context.session.app_name,
|
||||
user_id=mock_invocation_context.session.user_id,
|
||||
memories=memories,
|
||||
custom_metadata=metadata,
|
||||
)
|
||||
|
||||
async def test_add_memory_no_service_raises(self, mock_invocation_context):
|
||||
"""Test that add_memory raises ValueError when no service."""
|
||||
mock_invocation_context.memory_service = None
|
||||
|
||||
context = Context(mock_invocation_context)
|
||||
|
||||
with pytest.raises(
|
||||
ValueError,
|
||||
match=r"Cannot add memory: memory service is not available\.",
|
||||
):
|
||||
await context.add_memory(memories=["fact one"])
|
||||
|
||||
Reference in New Issue
Block a user