diff --git a/agents-api/agents_api/activities/execute_system.py b/agents-api/agents_api/activities/execute_system.py index 37cce0e5b..b81385898 100644 --- a/agents-api/agents_api/activities/execute_system.py +++ b/agents-api/agents_api/activities/execute_system.py @@ -17,6 +17,7 @@ SystemDef, TextOnlyDocSearchRequest, UpdateSessionRequest, + UpdateUserRequest, VectorDocSearchRequest, ) from ..common.protocol.tasks import ExecutionInput, StepContext @@ -110,7 +111,7 @@ async def execute_system( await bg_runner() return res - # Handle create operations + # Handle create session if system.operation == "create" and system.resource == "session": developer_id = arguments.pop("developer_id") session_id = arguments.pop("session_id", None) @@ -132,7 +133,7 @@ async def execute_system( ), ) - # Handle update operations + # Handle update session if system.operation == "update" and system.resource == "session": developer_id = arguments.pop("developer_id") session_id = arguments.pop("session_id") @@ -154,11 +155,35 @@ async def execute_system( ), ) + # Handle update user + if system.operation == "update" and system.resource == "user": + developer_id = arguments.pop("developer_id") + user_id = arguments.pop("user_id") + update_user_request = UpdateUserRequest(**arguments) + + # In case users.update becomes asynchronous in the future + if asyncio.iscoroutinefunction(handler): + return await handler() + + # Run the synchronous function in another process + loop = asyncio.get_running_loop() + return await loop.run_in_executor( + process_pool_executor, + partial( + handler, + developer_id=developer_id, + user_id=user_id, + data=update_user_request, + ), + ) + # Handle regular operations if asyncio.iscoroutinefunction(handler): return await handler(**arguments) # Run the synchronous function in another process + # FIXME: When the handler throws an exception, the process dies and the error is not captured. Instead it throws: + # "concurrent.futures.process.BrokenProcessPool: A process in the process pool was terminated abruptly while the future was running or pending." loop = asyncio.get_running_loop() return await loop.run_in_executor( process_pool_executor, partial(handler, **arguments) diff --git a/agents-api/agents_api/common/protocol/sessions.py b/agents-api/agents_api/common/protocol/sessions.py index 121afe702..0d03af9d8 100644 --- a/agents-api/agents_api/common/protocol/sessions.py +++ b/agents-api/agents_api/common/protocol/sessions.py @@ -117,6 +117,7 @@ def get_chat_environment(self) -> dict[str, dict | list[dict]]: "agents": [agent.model_dump() for agent in self.agents], "current_agent": current_agent.model_dump(), "agent": current_agent.model_dump(), + "user": self.users[0].model_dump() if len(self.users) > 0 else None, "users": [user.model_dump() for user in self.users], "settings": settings, "tools": [tool.model_dump() for tool in tools],