Platform for stateful agents: AI with advanced memory that can learn and self-improve over time.
feat(asyncify): migrate get block agents (#2226)
cthomasbc40da6cbbb8
diff --git a/letta/server/rest_api/routers/v1/blocks.py b/letta/server/rest_api/routers/v1/blocks.pyindex c95069062..bf669f432 100644--- a/letta/server/rest_api/routers/v1/blocks.py+++ b/letta/server/rest_api/routers/v1/blocks.py@@ -99,7 +99,7 @@ def retrieve_block(@router.get("/{block_id}/agents", response_model=List[AgentState], operation_id="list_agents_for_block")-def list_agents_for_block(+async def list_agents_for_block(block_id: str,server: SyncServer = Depends(get_letta_server),actor_id: Optional[str] = Header(None, alias="user_id"),@@ -108,9 +108,9 @@ def list_agents_for_block(Retrieves all agents associated with the specified block.Raises a 404 if the block does not exist."""- actor = server.user_manager.get_user_or_default(user_id=actor_id)+ actor = await server.user_manager.get_actor_or_default_async(actor_id=actor_id)try:- agents = server.block_manager.get_agents_for_block(block_id=block_id, actor=actor)+ agents = await server.block_manager.get_agents_for_block_async(block_id=block_id, actor=actor)return agentsexcept NoResultFound:raise HTTPException(status_code=404, detail=f"Block with id={block_id} not found")diff --git a/letta/services/block_manager.py b/letta/services/block_manager.pyindex 0d4e67da2..31a50d974 100644--- a/letta/services/block_manager.py+++ b/letta/services/block_manager.py@@ -258,6 +258,18 @@ class BlockManager:return agents_pydantic+ @enforce_types+ async def get_agents_for_block_async(self, block_id: str, actor: PydanticUser) -> List[PydanticAgentState]:+ """+ Retrieve all agents associated with a given block.+ """+ async with db_registry.async_session() as session:+ block = await BlockModel.read_async(db_session=session, identifier=block_id, actor=actor)+ agents_orm = block.agents+ agents_pydantic = [agent.to_pydantic() for agent in agents_orm]++ return agents_pydantic+@enforce_typesdef size(self,