|
17 | 17 | import asyncio
|
18 | 18 | import logging
|
19 | 19 | import queue
|
| 20 | +import time |
| 21 | +from typing import Any |
20 | 22 | from typing import AsyncGenerator
|
21 | 23 | from typing import Callable
|
22 | 24 | from typing import Generator
|
23 | 25 | from typing import List
|
24 | 26 | from typing import Optional
|
| 27 | +import uuid |
25 | 28 | import warnings
|
26 | 29 |
|
27 | 30 | from google.genai import types
|
|
38 | 41 | from .auth.credential_service.base_credential_service import BaseCredentialService
|
39 | 42 | from .code_executors.built_in_code_executor import BuiltInCodeExecutor
|
40 | 43 | from .events.event import Event
|
| 44 | +from .events.event import EventActions |
41 | 45 | from .flows.llm_flows.functions import find_matching_function_call
|
42 | 46 | from .memory.base_memory_service import BaseMemoryService
|
43 | 47 | from .memory.in_memory_memory_service import InMemoryMemoryService
|
@@ -174,6 +178,7 @@ async def run_async(
|
174 | 178 | user_id: str,
|
175 | 179 | session_id: str,
|
176 | 180 | new_message: types.Content,
|
| 181 | + state_delta: Optional[dict[str, Any]] = None, |
177 | 182 | run_config: RunConfig = RunConfig(),
|
178 | 183 | ) -> AsyncGenerator[Event, None]:
|
179 | 184 | """Main entry method to run the agent in this runner.
|
@@ -216,6 +221,7 @@ async def run_async(
|
216 | 221 | new_message,
|
217 | 222 | invocation_context,
|
218 | 223 | run_config.save_input_blobs_as_artifacts,
|
| 224 | + state_delta, |
219 | 225 | )
|
220 | 226 |
|
221 | 227 | invocation_context.agent = self._find_agent_to_run(session, root_agent)
|
@@ -284,6 +290,7 @@ async def _append_new_message_to_session(
|
284 | 290 | new_message: types.Content,
|
285 | 291 | invocation_context: InvocationContext,
|
286 | 292 | save_input_blobs_as_artifacts: bool = False,
|
| 293 | + state_delta: Optional[dict[str, Any]] = None, |
287 | 294 | ):
|
288 | 295 | """Appends a new message to the session.
|
289 | 296 |
|
@@ -315,11 +322,19 @@ async def _append_new_message_to_session(
|
315 | 322 | text=f'Uploaded file: {file_name}. It is saved into artifacts'
|
316 | 323 | )
|
317 | 324 | # 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 | + ) |
323 | 338 | await self.session_service.append_event(session=session, event=event)
|
324 | 339 |
|
325 | 340 | async def run_live(
|
|
0 commit comments