Skip to content

Commit b89aac9

Browse files
google-genai-botcopybara-github
authored andcommitted
ADK changes
PiperOrigin-RevId: 783804355
1 parent 3f9f773 commit b89aac9

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

src/google/adk/cli/fast_api.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ class AgentRunRequest(common.BaseModel):
177177
session_id: str
178178
new_message: types.Content
179179
streaming: bool = False
180+
state_delta: Optional[dict[str, Any]] = None
180181

181182

182183
class AddSessionToEvalSetRequest(common.BaseModel):
@@ -877,6 +878,7 @@ async def event_generator():
877878
user_id=req.user_id,
878879
session_id=req.session_id,
879880
new_message=req.new_message,
881+
state_delta=req.state_delta,
880882
run_config=RunConfig(streaming_mode=stream_mode),
881883
):
882884
# Format as SSE data

src/google/adk/runners.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,14 @@
1717
import asyncio
1818
import logging
1919
import queue
20+
import time
21+
from typing import Any
2022
from typing import AsyncGenerator
2123
from typing import Callable
2224
from typing import Generator
2325
from typing import List
2426
from typing import Optional
27+
import uuid
2528
import warnings
2629

2730
from google.genai import types
@@ -38,6 +41,7 @@
3841
from .auth.credential_service.base_credential_service import BaseCredentialService
3942
from .code_executors.built_in_code_executor import BuiltInCodeExecutor
4043
from .events.event import Event
44+
from .events.event import EventActions
4145
from .flows.llm_flows.functions import find_matching_function_call
4246
from .memory.base_memory_service import BaseMemoryService
4347
from .memory.in_memory_memory_service import InMemoryMemoryService
@@ -174,6 +178,7 @@ async def run_async(
174178
user_id: str,
175179
session_id: str,
176180
new_message: types.Content,
181+
state_delta: Optional[dict[str, Any]] = None,
177182
run_config: RunConfig = RunConfig(),
178183
) -> AsyncGenerator[Event, None]:
179184
"""Main entry method to run the agent in this runner.
@@ -216,6 +221,7 @@ async def run_async(
216221
new_message,
217222
invocation_context,
218223
run_config.save_input_blobs_as_artifacts,
224+
state_delta,
219225
)
220226

221227
invocation_context.agent = self._find_agent_to_run(session, root_agent)
@@ -284,6 +290,7 @@ async def _append_new_message_to_session(
284290
new_message: types.Content,
285291
invocation_context: InvocationContext,
286292
save_input_blobs_as_artifacts: bool = False,
293+
state_delta: Optional[dict[str, Any]] = None,
287294
):
288295
"""Appends a new message to the session.
289296
@@ -315,11 +322,19 @@ async def _append_new_message_to_session(
315322
text=f'Uploaded file: {file_name}. It is saved into artifacts'
316323
)
317324
# Appends only. We do not yield the event because it's not from the model.
318-
event = Event(
319-
invocation_id=invocation_context.invocation_id,
320-
author='user',
321-
content=new_message,
322-
)
325+
if state_delta:
326+
event = Event(
327+
invocation_id=invocation_context.invocation_id,
328+
author='user',
329+
actions=EventActions(state_delta=state_delta),
330+
content=new_message,
331+
)
332+
else:
333+
event = Event(
334+
invocation_id=invocation_context.invocation_id,
335+
author='user',
336+
content=new_message,
337+
)
323338
await self.session_service.append_event(session=session, event=event)
324339

325340
async def run_live(

0 commit comments

Comments
 (0)