Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
69ffec1
feat: add endpoint to generate memory from session
guillaumeblaquiere Sep 10, 2025
58238d4
chore: renaming function
guillaumeblaquiere Sep 10, 2025
69571ea
fix: session missing handling
guillaumeblaquiere Sep 10, 2025
e69cac4
chore: Improvement based on Gemini recommendation
guillaumeblaquiere Sep 10, 2025
b4577d0
Merge branch 'main' into add-session-to-memory
guillaumeblaquiere Sep 10, 2025
a7a7d03
fix: make API path more RESTful
guillaumeblaquiere Sep 10, 2025
8b788e7
Merge remote-tracking branch 'origin/add-session-to-memory' into add-…
guillaumeblaquiere Sep 10, 2025
9c1a262
Merge branch 'main' into add-session-to-memory
guillaumeblaquiere Sep 10, 2025
6b4d947
Update adk_web_server.py
DeanChensj Sep 10, 2025
68bb329
Chore: pyink formatting
guillaumeblaquiere Sep 10, 2025
9d418a0
Merge remote-tracking branch 'origin/add-session-to-memory' into add-…
guillaumeblaquiere Sep 10, 2025
7868eee
Merge branch 'main' into add-session-to-memory
guillaumeblaquiere Sep 10, 2025
a1a7fd8
Chore: typo
guillaumeblaquiere Sep 10, 2025
de6eab8
Merge branch 'main' into add-session-to-memory
DeanChensj Sep 10, 2025
08c19eb
fix: None body return
guillaumeblaquiere Sep 11, 2025
aecb0f0
fix: test improvement
guillaumeblaquiere Sep 11, 2025
5d9dc6b
fix: test improvement
guillaumeblaquiere Sep 11, 2025
3f82b8e
Merge branch 'main' into add-session-to-memory
guillaumeblaquiere Sep 11, 2025
c853518
Merge branch 'main' into add-session-to-memory
DeanChensj Sep 11, 2025
85cc594
chore: pyink fix
guillaumeblaquiere Sep 11, 2025
3e763fc
Merge branch 'main' into add-session-to-memory
guillaumeblaquiere Sep 11, 2025
8c667de
Merge branch 'main' into add-session-to-memory
DeanChensj Sep 11, 2025
13d42ae
Merge branch 'main' into add-session-to-memory
guillaumeblaquiere Sep 12, 2025
98eca83
Merge branch 'main' into add-session-to-memory
guillaumeblaquiere Sep 12, 2025
1527493
feat: update add session to memory endpoint structure
guillaumeblaquiere Sep 13, 2025
d0003af
Merge branch 'main' into add-session-to-memory
guillaumeblaquiere Sep 13, 2025
e0465b5
Merge branch 'main' into add-session-to-memory
GWeale Sep 15, 2025
c451d08
Merge branch 'main' into add-session-to-memory
DeanChensj Sep 17, 2025
17f4478
Merge branch 'main' into add-session-to-memory
guillaumeblaquiere Sep 18, 2025
830da14
feat: change return code of patch_memory
guillaumeblaquiere Sep 18, 2025
6e2f09b
doc: merge the exceptions description
guillaumeblaquiere Sep 18, 2025
c831d87
refactor: merge the memory request check and exceptions
guillaumeblaquiere Sep 18, 2025
faf8ec7
Merge branch 'main' into add-session-to-memory
DeanChensj Sep 18, 2025
0507de4
Merge branch 'main' into add-session-to-memory
DeanChensj Sep 18, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions src/google/adk/cli/adk_web_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
from fastapi import FastAPI
from fastapi import HTTPException
from fastapi import Query
from fastapi import Response
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import RedirectResponse
from fastapi.responses import StreamingResponse
Expand Down Expand Up @@ -210,6 +211,13 @@ class RunEvalRequest(common.BaseModel):
eval_metrics: list[EvalMetric]


class UpdateMemoryRequest(common.BaseModel):
"""Request to add a session to the memory service."""

session_id: str
"""The ID of the session to add to memory."""


class RunEvalResult(common.BaseModel):
eval_set_file: str
eval_set_id: str
Expand Down Expand Up @@ -1144,6 +1152,41 @@ async def delete_artifact(
filename=artifact_name,
)

@app.patch("/apps/{app_name}/users/{user_id}/memory")
async def patch_memory(
app_name: str, user_id: str, update_memory_request: UpdateMemoryRequest
) -> None:
"""Adds all events from a given session to the memory service.

Args:
app_name: The name of the application.
user_id: The ID of the user.
update_memory_request: The memory request for the update

Raises:
HTTPException: If the memory service is not configured or the request is invalid.
"""
if not self.memory_service:
raise HTTPException(
status_code=400, detail="Memory service is not configured."
)
if (
update_memory_request is None
or update_memory_request.session_id is None
):
raise HTTPException(
status_code=400, detail="Update memory request is invalid."
)

session = await self.session_service.get_session(
app_name=app_name,
user_id=user_id,
session_id=update_memory_request.session_id,
)
if not session:
raise HTTPException(status_code=404, detail="Session not found")
await self.memory_service.add_session_to_memory(session)

@app.post("/run", response_model_exclude_none=True)
async def run_agent(req: RunAgentRequest) -> list[Event]:
session = await self.session_service.get_session(
Expand Down
16 changes: 15 additions & 1 deletion tests/unittests/cli/test_fast_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import time
from typing import Any
from typing import Optional
from unittest.mock import AsyncMock
from unittest.mock import MagicMock
from unittest.mock import patch

Expand Down Expand Up @@ -344,7 +345,7 @@ async def delete_artifact(self, app_name, user_id, session_id, filename):
@pytest.fixture
def mock_memory_service():
"""Create a mock memory service."""
return MagicMock()
return AsyncMock()


@pytest.fixture
Expand Down Expand Up @@ -939,5 +940,18 @@ def test_a2a_disabled_by_default(test_app):
logger.info("A2A disabled by default test passed")


def test_patch_memory(test_app, create_test_session, mock_memory_service):
"""Test adding a session to memory."""
info = create_test_session
url = f"/apps/{info['app_name']}/users/{info['user_id']}/memory"
payload = {"session_id": info["session_id"]}
response = test_app.patch(url, json=payload)

# Verify the response
assert response.status_code == 200
mock_memory_service.add_session_to_memory.assert_called_once()
logger.info("Add session to memory test completed successfully")


if __name__ == "__main__":
pytest.main(["-xvs", __file__])