Skip to content

Commit 21ed0a4

Browse files
feat: implement PlatformWorkspaceContext for GAP-3
- Add PlatformWorkspaceContext class implementing WorkspaceContextProtocol - Provides workspace context and agent config via database queries - Scopes agent queries to workspace for security - Returns None for missing workspace/agent as per spec - Export PlatformWorkspaceContext from services module 🤖 Generated with [Claude Code](https://claude.ai/code) Co-authored-by: MervinPraison <MervinPraison@users.noreply.github.com>
1 parent d76b56e commit 21ed0a4

File tree

2 files changed

+88
-0
lines changed

2 files changed

+88
-0
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from .agent_service import AgentService
1111
from .label_service import LabelService
1212
from .dependency_service import DependencyService
13+
from .workspace_context import PlatformWorkspaceContext
1314

1415
__all__ = [
1516
"AuthService",
@@ -22,4 +23,5 @@
2223
"AgentService",
2324
"LabelService",
2425
"DependencyService",
26+
"PlatformWorkspaceContext",
2527
]
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
"""
2+
Workspace context service — implements WorkspaceContextProtocol for platform integration.
3+
4+
Provides workspace-level context and agent configuration by querying the database,
5+
implementing the WorkspaceContextProtocol from praisonaiagents.auth.protocols.
6+
"""
7+
8+
from __future__ import annotations
9+
10+
from typing import Any, Dict, Optional
11+
12+
from sqlalchemy import select
13+
from sqlalchemy.ext.asyncio import AsyncSession
14+
15+
from ..db.models import Agent, Workspace
16+
17+
18+
class PlatformWorkspaceContext:
19+
"""
20+
Platform implementation of WorkspaceContextProtocol.
21+
22+
Provides workspace context and agent configuration by querying the platform database.
23+
"""
24+
25+
def __init__(self, workspace_id: str, session: AsyncSession):
26+
"""
27+
Initialize workspace context provider.
28+
29+
Args:
30+
workspace_id: ID of the workspace to provide context for
31+
session: Database session for queries
32+
"""
33+
self.workspace_id = workspace_id
34+
self._session = session
35+
36+
async def get_workspace_context(self) -> Optional[Dict[str, Any]]:
37+
"""
38+
Get workspace-level context for agents.
39+
40+
Returns:
41+
Dict containing workspace data if found, None otherwise.
42+
Keys: id, name, slug, description, settings
43+
"""
44+
workspace = await self._session.get(Workspace, self.workspace_id)
45+
if workspace is None:
46+
return None
47+
48+
return {
49+
"id": workspace.id,
50+
"name": workspace.name,
51+
"slug": workspace.slug,
52+
"description": workspace.description,
53+
"settings": workspace.settings or {},
54+
}
55+
56+
async def get_agent_config(self, agent_id: str) -> Optional[Dict[str, Any]]:
57+
"""
58+
Get agent configuration from the platform.
59+
60+
Args:
61+
agent_id: The agent identifier
62+
63+
Returns:
64+
Agent configuration dict if found, None otherwise.
65+
Keys: id, name, runtime_mode, instructions, config, max_concurrent_tasks
66+
"""
67+
# Query for agent scoped to the workspace
68+
stmt = (
69+
select(Agent)
70+
.where(Agent.id == agent_id)
71+
.where(Agent.workspace_id == self.workspace_id)
72+
)
73+
result = await self._session.execute(stmt)
74+
agent = result.scalar_one_or_none()
75+
76+
if agent is None:
77+
return None
78+
79+
return {
80+
"id": agent.id,
81+
"name": agent.name,
82+
"runtime_mode": agent.runtime_mode,
83+
"instructions": agent.instructions,
84+
"config": agent.runtime_config or {},
85+
"max_concurrent_tasks": agent.max_concurrent_tasks,
86+
}

0 commit comments

Comments
 (0)