Skip to content

Commit 8f35439

Browse files
fix(platform): align PlatformWorkspaceContext with WorkspaceContextProtocol
Agent-Logs-Url: https://github.com/MervinPraison/PraisonAI/sessions/4f65e6a4-b164-458e-ad64-6141c6d529c0 Co-authored-by: MervinPraison <454862+MervinPraison@users.noreply.github.com>
1 parent 21ed0a4 commit 8f35439

1 file changed

Lines changed: 22 additions & 9 deletions

File tree

src/praisonai-platform/praisonai_platform/services/workspace_context.py

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,18 @@
77

88
from __future__ import annotations
99

10+
import json
1011
from typing import Any, Dict, Optional
1112

1213
from sqlalchemy import select
1314
from sqlalchemy.ext.asyncio import AsyncSession
1415

16+
from praisonaiagents.auth.protocols import WorkspaceContextProtocol
17+
1518
from ..db.models import Agent, Workspace
1619

1720

18-
class PlatformWorkspaceContext:
21+
class PlatformWorkspaceContext(WorkspaceContextProtocol):
1922
"""
2023
Platform implementation of WorkspaceContextProtocol.
2124
@@ -33,27 +36,34 @@ def __init__(self, workspace_id: str, session: AsyncSession):
3336
self.workspace_id = workspace_id
3437
self._session = session
3538

36-
async def get_workspace_context(self) -> Optional[Dict[str, Any]]:
39+
async def get_workspace_context(self, workspace_id: str) -> Optional[str]:
3740
"""
3841
Get workspace-level context for agents.
3942
4043
Returns:
41-
Dict containing workspace data if found, None otherwise.
42-
Keys: id, name, slug, description, settings
44+
Workspace context string if found, None otherwise.
4345
"""
44-
workspace = await self._session.get(Workspace, self.workspace_id)
46+
if workspace_id != self.workspace_id:
47+
return None
48+
49+
workspace = await self._session.get(Workspace, workspace_id)
4550
if workspace is None:
4651
return None
4752

48-
return {
53+
payload = {
4954
"id": workspace.id,
5055
"name": workspace.name,
5156
"slug": workspace.slug,
5257
"description": workspace.description,
5358
"settings": workspace.settings or {},
5459
}
60+
return json.dumps(payload, ensure_ascii=False, default=str)
5561

56-
async def get_agent_config(self, agent_id: str) -> Optional[Dict[str, Any]]:
62+
async def get_agent_config(
63+
self,
64+
workspace_id: str,
65+
agent_id: str,
66+
) -> Optional[Dict[str, Any]]:
5767
"""
5868
Get agent configuration from the platform.
5969
@@ -64,11 +74,14 @@ async def get_agent_config(self, agent_id: str) -> Optional[Dict[str, Any]]:
6474
Agent configuration dict if found, None otherwise.
6575
Keys: id, name, runtime_mode, instructions, config, max_concurrent_tasks
6676
"""
77+
if workspace_id != self.workspace_id:
78+
return None
79+
6780
# Query for agent scoped to the workspace
6881
stmt = (
6982
select(Agent)
7083
.where(Agent.id == agent_id)
71-
.where(Agent.workspace_id == self.workspace_id)
84+
.where(Agent.workspace_id == workspace_id)
7285
)
7386
result = await self._session.execute(stmt)
7487
agent = result.scalar_one_or_none()
@@ -83,4 +96,4 @@ async def get_agent_config(self, agent_id: str) -> Optional[Dict[str, Any]]:
8396
"instructions": agent.instructions,
8497
"config": agent.runtime_config or {},
8598
"max_concurrent_tasks": agent.max_concurrent_tasks,
86-
}
99+
}

0 commit comments

Comments
 (0)