Sets up the context for a new invocation. Args: session: The session to set up the invocation context for. new_message: The new message to process and append to the session. run_config: The run config of the agent. state_delta: Optional state changes to apply to the sess
(
self,
*,
session: Session,
new_message: types.Content,
run_config: RunConfig,
state_delta: Optional[dict[str, Any]],
)
| 1827 | return collected_events |
| 1828 | |
| 1829 | async def _setup_context_for_new_invocation( |
| 1830 | self, |
| 1831 | *, |
| 1832 | session: Session, |
| 1833 | new_message: types.Content, |
| 1834 | run_config: RunConfig, |
| 1835 | state_delta: Optional[dict[str, Any]], |
| 1836 | ) -> InvocationContext: |
| 1837 | """Sets up the context for a new invocation. |
| 1838 | |
| 1839 | Args: |
| 1840 | session: The session to set up the invocation context for. |
| 1841 | new_message: The new message to process and append to the session. |
| 1842 | run_config: The run config of the agent. |
| 1843 | state_delta: Optional state changes to apply to the session. |
| 1844 | |
| 1845 | Returns: |
| 1846 | The invocation context for the new invocation. |
| 1847 | """ |
| 1848 | # Step 1: Create invocation context in memory. |
| 1849 | invocation_context = self._new_invocation_context( |
| 1850 | session, |
| 1851 | new_message=new_message, |
| 1852 | run_config=run_config, |
| 1853 | ) |
| 1854 | # Step 2: Handle new message, by running callbacks and appending to |
| 1855 | # session. |
| 1856 | await self._handle_new_message( |
| 1857 | session=invocation_context.session, |
| 1858 | new_message=new_message, |
| 1859 | invocation_context=invocation_context, |
| 1860 | run_config=run_config, |
| 1861 | state_delta=state_delta, |
| 1862 | ) |
| 1863 | # Step 3: Set agent to run for the invocation. |
| 1864 | invocation_context.agent = self._find_agent_to_run( |
| 1865 | invocation_context.session, self.agent |
| 1866 | ) |
| 1867 | return invocation_context |
| 1868 | |
| 1869 | async def _setup_context_for_resumed_invocation( |
| 1870 | self, |
no test coverage detected