mirror of
https://github.com/encounter/adk-python.git
synced 2026-07-09 18:19:28 -07:00
feat: add add_events_to_memory facade for event-delta
Adds BaseMemoryService.add_events_to_memory(session, events=..., custom_metadata=...) and CallbackContext.add_events_to_memory(events=..., custom_metadata=...) so callers can add memories from an explicit subset of ADK events. Co-authored-by: George Weale <gweale@google.com> PiperOrigin-RevId: 868261578
This commit is contained in:
committed by
Copybara-Service
parent
de79bf12b5
commit
59e88972ae
@@ -373,6 +373,46 @@ class TestCallbackContextAddSessionToMemory:
|
||||
await context.add_session_to_memory()
|
||||
|
||||
|
||||
class TestCallbackContextAddEventsToMemory:
|
||||
"""Tests add_events_to_memory in CallbackContext."""
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_add_events_to_memory_success(self, mock_invocation_context):
|
||||
"""Tests that add_events_to_memory calls the memory service correctly."""
|
||||
memory_service = AsyncMock()
|
||||
mock_invocation_context.memory_service = memory_service
|
||||
test_event = MagicMock()
|
||||
|
||||
context = CallbackContext(mock_invocation_context)
|
||||
await context.add_events_to_memory(
|
||||
events=[test_event],
|
||||
custom_metadata={"ttl": "6000s"},
|
||||
)
|
||||
|
||||
memory_service.add_events_to_memory.assert_called_once_with(
|
||||
app_name=mock_invocation_context.session.app_name,
|
||||
user_id=mock_invocation_context.session.user_id,
|
||||
session_id=mock_invocation_context.session.id,
|
||||
events=[test_event],
|
||||
custom_metadata={"ttl": "6000s"},
|
||||
)
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_add_events_to_memory_no_service_raises(
|
||||
self, mock_invocation_context
|
||||
):
|
||||
"""Tests that add_events_to_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 events to memory: memory service is not available\.",
|
||||
):
|
||||
await context.add_events_to_memory(events=[MagicMock()])
|
||||
|
||||
|
||||
class TestToolContextAddSessionToMemory:
|
||||
"""Test the add_session_to_memory method in ToolContext."""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user