persona-sdk-python 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- persona_sdk/__init__.py +32 -0
- persona_sdk/api/__init__.py +0 -0
- persona_sdk/api/agents.py +27 -0
- persona_sdk/api/credentials.py +21 -0
- persona_sdk/api/features.py +27 -0
- persona_sdk/api/knowledge_bases.py +34 -0
- persona_sdk/api/missions.py +41 -0
- persona_sdk/api/projects.py +27 -0
- persona_sdk/api/service_prices.py +24 -0
- persona_sdk/api/sessions.py +42 -0
- persona_sdk/api/triggers.py +34 -0
- persona_sdk/api/workflows.py +34 -0
- persona_sdk/client.py +50 -0
- persona_sdk/runners/__init__.py +3 -0
- persona_sdk/runners/agent_runner.py +70 -0
- persona_sdk/runners/resource_retriever.py +68 -0
- persona_sdk/runners/tool_invoker.py +59 -0
- persona_sdk_python-0.1.0.dist-info/METADATA +7 -0
- persona_sdk_python-0.1.0.dist-info/RECORD +20 -0
- persona_sdk_python-0.1.0.dist-info/WHEEL +4 -0
persona_sdk/__init__.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
from persona_sdk.client import PersonaClient
|
|
2
|
+
from persona_sdk.api.agents import AgentsApi
|
|
3
|
+
from persona_sdk.api.workflows import WorkflowsApi
|
|
4
|
+
from persona_sdk.api.triggers import TriggersApi
|
|
5
|
+
from persona_sdk.api.sessions import SessionsApi
|
|
6
|
+
from persona_sdk.api.credentials import CredentialsApi
|
|
7
|
+
from persona_sdk.api.knowledge_bases import KnowledgeBasesApi
|
|
8
|
+
from persona_sdk.api.projects import ProjectsApi
|
|
9
|
+
from persona_sdk.api.features import FeaturesApi
|
|
10
|
+
from persona_sdk.api.missions import MissionsApi
|
|
11
|
+
from persona_sdk.api.service_prices import ServicePricesApi
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class PersonaSdk:
|
|
15
|
+
def __init__(self, base_url: str, api_key: str, workflows_url: str = None):
|
|
16
|
+
self.client = PersonaClient(base_url, api_key)
|
|
17
|
+
self.workflows_client = PersonaClient(workflows_url, api_key) if workflows_url else self.client
|
|
18
|
+
self.agents = AgentsApi(self.client)
|
|
19
|
+
self.workflows = WorkflowsApi(self.workflows_client)
|
|
20
|
+
self.triggers = TriggersApi(self.client)
|
|
21
|
+
self.sessions = SessionsApi(self.client)
|
|
22
|
+
self.credentials = CredentialsApi(self.client)
|
|
23
|
+
self.knowledge_bases = KnowledgeBasesApi(self.client)
|
|
24
|
+
self.projects = ProjectsApi(self.client)
|
|
25
|
+
self.features = FeaturesApi(self.client)
|
|
26
|
+
self.missions = MissionsApi(self.client)
|
|
27
|
+
self.service_prices = ServicePricesApi(self.client)
|
|
28
|
+
|
|
29
|
+
async def close(self):
|
|
30
|
+
await self.client.close()
|
|
31
|
+
if self.workflows_client is not self.client:
|
|
32
|
+
await self.workflows_client.close()
|
|
File without changes
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
from persona_sdk.client import PersonaClient
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class AgentsApi:
|
|
5
|
+
def __init__(self, client: PersonaClient):
|
|
6
|
+
self._client = client
|
|
7
|
+
|
|
8
|
+
async def list(self, keyword: str = None, page: int = 1, size: int = 20) -> dict:
|
|
9
|
+
params = {"page": page, "size": size}
|
|
10
|
+
if keyword:
|
|
11
|
+
params["keyword"] = keyword
|
|
12
|
+
return await self._client.get("/agents", params=params)
|
|
13
|
+
|
|
14
|
+
async def get(self, agent_id: str) -> dict:
|
|
15
|
+
return await self._client.get(f"/agents/{agent_id}")
|
|
16
|
+
|
|
17
|
+
async def create(self, agent: dict) -> dict:
|
|
18
|
+
return await self._client.post("/agents", json=agent)
|
|
19
|
+
|
|
20
|
+
async def update(self, agent_id: str, agent: dict) -> dict:
|
|
21
|
+
return await self._client.put(f"/agents/{agent_id}", json=agent)
|
|
22
|
+
|
|
23
|
+
async def delete(self, agent_id: str) -> dict:
|
|
24
|
+
return await self._client.delete(f"/agents/{agent_id}")
|
|
25
|
+
|
|
26
|
+
async def get_voices(self, synthesizer_type: str) -> dict:
|
|
27
|
+
return await self._client.get(f"/values/synthesizers/{synthesizer_type}/voices")
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
from persona_sdk.client import PersonaClient
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class CredentialsApi:
|
|
5
|
+
def __init__(self, client: PersonaClient):
|
|
6
|
+
self._client = client
|
|
7
|
+
|
|
8
|
+
async def list(self) -> dict:
|
|
9
|
+
return await self._client.get("/credentials")
|
|
10
|
+
|
|
11
|
+
async def list_by_provider(self, provider: str) -> dict:
|
|
12
|
+
return await self._client.get(f"/credentials/{provider}")
|
|
13
|
+
|
|
14
|
+
async def get(self, credentials_id: str) -> dict:
|
|
15
|
+
return await self._client.get(f"/credentials/all/{credentials_id}")
|
|
16
|
+
|
|
17
|
+
async def authorize(self, provider: str, request: dict) -> dict:
|
|
18
|
+
return await self._client.post(f"/credentials/{provider}/authorize", json=request)
|
|
19
|
+
|
|
20
|
+
async def delete(self, credentials_id: str) -> dict:
|
|
21
|
+
return await self._client.delete(f"/credentials/all/{credentials_id}")
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
from persona_sdk.client import PersonaClient
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class FeaturesApi:
|
|
5
|
+
def __init__(self, client: PersonaClient):
|
|
6
|
+
self._client = client
|
|
7
|
+
|
|
8
|
+
async def list(self, keyword: str = None, page: int = 1, size: int = 20) -> dict:
|
|
9
|
+
params = {"page": page, "size": size}
|
|
10
|
+
if keyword:
|
|
11
|
+
params["keyword"] = keyword
|
|
12
|
+
return await self._client.get("/features/templates", params=params)
|
|
13
|
+
|
|
14
|
+
async def get(self, template_id: str) -> dict:
|
|
15
|
+
return await self._client.get(f"/features/templates/{template_id}")
|
|
16
|
+
|
|
17
|
+
async def create(self, feature_template: dict) -> dict:
|
|
18
|
+
return await self._client.post("/features/templates", json=feature_template)
|
|
19
|
+
|
|
20
|
+
async def update(self, template_id: str, feature_template: dict) -> dict:
|
|
21
|
+
return await self._client.put(f"/features/templates/{template_id}", json=feature_template)
|
|
22
|
+
|
|
23
|
+
async def delete(self, template_id: str) -> dict:
|
|
24
|
+
return await self._client.delete(f"/features/templates/{template_id}")
|
|
25
|
+
|
|
26
|
+
async def get_mcp_tools(self, mcp_config: dict) -> dict:
|
|
27
|
+
return await self._client.post("/features/templates/mcp/available-tools", json=mcp_config)
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
from persona_sdk.client import PersonaClient
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class KnowledgeBasesApi:
|
|
5
|
+
def __init__(self, client: PersonaClient):
|
|
6
|
+
self._client = client
|
|
7
|
+
|
|
8
|
+
async def list(self, keyword: str = None, page: int = 1, size: int = 20) -> dict:
|
|
9
|
+
params = {"page": page, "size": size}
|
|
10
|
+
if keyword:
|
|
11
|
+
params["keyword"] = keyword
|
|
12
|
+
return await self._client.get("/knowledges", params=params)
|
|
13
|
+
|
|
14
|
+
async def get(self, knowledge_base_id: str) -> dict:
|
|
15
|
+
return await self._client.get(f"/knowledges/{knowledge_base_id}")
|
|
16
|
+
|
|
17
|
+
async def create(self, knowledge_base: dict) -> dict:
|
|
18
|
+
return await self._client.post("/knowledges", json=knowledge_base)
|
|
19
|
+
|
|
20
|
+
async def update(self, knowledge_base_id: str, knowledge_base: dict) -> dict:
|
|
21
|
+
return await self._client.put(f"/knowledges/{knowledge_base_id}", json=knowledge_base)
|
|
22
|
+
|
|
23
|
+
async def delete(self, knowledge_base_id: str) -> dict:
|
|
24
|
+
return await self._client.delete(f"/knowledges/{knowledge_base_id}")
|
|
25
|
+
|
|
26
|
+
async def list_documents(self, knowledge_base_id: str, page: int = 1, size: int = 20) -> dict:
|
|
27
|
+
params = {"page": page, "size": size}
|
|
28
|
+
return await self._client.get(f"/knowledges/{knowledge_base_id}/documents", params=params)
|
|
29
|
+
|
|
30
|
+
async def delete_document(self, knowledge_base_id: str, document_id: str) -> dict:
|
|
31
|
+
return await self._client.delete(f"/knowledges/{knowledge_base_id}/documents/{document_id}")
|
|
32
|
+
|
|
33
|
+
async def search_chunks(self, knowledge_base_id: str, request: dict) -> dict:
|
|
34
|
+
return await self._client.post(f"/knowledges/{knowledge_base_id}/search", json=request)
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
from persona_sdk.client import PersonaClient
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class MissionsApi:
|
|
5
|
+
def __init__(self, client: PersonaClient):
|
|
6
|
+
self._client = client
|
|
7
|
+
|
|
8
|
+
async def list(self, keyword: str = None, status: str = None, page: int = 1, size: int = 20) -> dict:
|
|
9
|
+
params = {"page": page, "size": size}
|
|
10
|
+
if keyword:
|
|
11
|
+
params["keyword"] = keyword
|
|
12
|
+
if status:
|
|
13
|
+
params["status"] = status
|
|
14
|
+
return await self._client.get("/missions", params=params)
|
|
15
|
+
|
|
16
|
+
async def get(self, mission_id: str) -> dict:
|
|
17
|
+
return await self._client.get(f"/missions/{mission_id}")
|
|
18
|
+
|
|
19
|
+
async def create(self, mission: dict) -> dict:
|
|
20
|
+
return await self._client.post("/missions", json=mission)
|
|
21
|
+
|
|
22
|
+
async def update(self, mission_id: str, mission: dict) -> dict:
|
|
23
|
+
return await self._client.put(f"/missions/{mission_id}", json=mission)
|
|
24
|
+
|
|
25
|
+
async def delete(self, mission_id: str) -> dict:
|
|
26
|
+
return await self._client.delete(f"/missions/{mission_id}")
|
|
27
|
+
|
|
28
|
+
async def generate(self, mission_id: str) -> dict:
|
|
29
|
+
return await self._client.post(f"/missions/{mission_id}/generate")
|
|
30
|
+
|
|
31
|
+
async def execute(self, mission_id: str) -> dict:
|
|
32
|
+
return await self._client.post(f"/missions/{mission_id}/execute")
|
|
33
|
+
|
|
34
|
+
async def continue_mission(self, mission_id: str) -> dict:
|
|
35
|
+
return await self._client.post(f"/missions/{mission_id}/continue")
|
|
36
|
+
|
|
37
|
+
async def stop(self, mission_id: str) -> dict:
|
|
38
|
+
return await self._client.post(f"/missions/{mission_id}/stop")
|
|
39
|
+
|
|
40
|
+
async def send_instructions(self, mission_id: str, instructions: dict) -> dict:
|
|
41
|
+
return await self._client.post(f"/missions/{mission_id}/instructions", json=instructions)
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
from persona_sdk.client import PersonaClient
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class ProjectsApi:
|
|
5
|
+
def __init__(self, client: PersonaClient):
|
|
6
|
+
self._client = client
|
|
7
|
+
|
|
8
|
+
async def list(self, keyword: str = None, page: int = 1, size: int = 20) -> dict:
|
|
9
|
+
params = {"page": page, "size": size}
|
|
10
|
+
if keyword:
|
|
11
|
+
params["keyword"] = keyword
|
|
12
|
+
return await self._client.get("/projects", params=params)
|
|
13
|
+
|
|
14
|
+
async def get(self, project_id: str) -> dict:
|
|
15
|
+
return await self._client.get(f"/projects/{project_id}")
|
|
16
|
+
|
|
17
|
+
async def get_mine(self) -> dict:
|
|
18
|
+
return await self._client.get("/projects/mine")
|
|
19
|
+
|
|
20
|
+
async def create(self, project: dict) -> dict:
|
|
21
|
+
return await self._client.post("/projects", json=project)
|
|
22
|
+
|
|
23
|
+
async def update(self, project_id: str, project: dict) -> dict:
|
|
24
|
+
return await self._client.put(f"/projects/{project_id}", json=project)
|
|
25
|
+
|
|
26
|
+
async def delete(self, project_id: str) -> dict:
|
|
27
|
+
return await self._client.delete(f"/projects/{project_id}")
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
from persona_sdk.client import PersonaClient
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class ServicePricesApi:
|
|
5
|
+
def __init__(self, client: PersonaClient):
|
|
6
|
+
self._client = client
|
|
7
|
+
|
|
8
|
+
async def list(self, keyword: str = None, page: int = 1, size: int = 20) -> dict:
|
|
9
|
+
params = {"page": page, "size": size}
|
|
10
|
+
if keyword:
|
|
11
|
+
params["keyword"] = keyword
|
|
12
|
+
return await self._client.get("/service-prices", params=params)
|
|
13
|
+
|
|
14
|
+
async def get(self, service_price_id: str) -> dict:
|
|
15
|
+
return await self._client.get(f"/service-prices/{service_price_id}")
|
|
16
|
+
|
|
17
|
+
async def create(self, service_price: dict) -> dict:
|
|
18
|
+
return await self._client.post("/service-prices", json=service_price)
|
|
19
|
+
|
|
20
|
+
async def update(self, service_price_id: str, service_price: dict) -> dict:
|
|
21
|
+
return await self._client.put(f"/service-prices/{service_price_id}", json=service_price)
|
|
22
|
+
|
|
23
|
+
async def delete(self, service_price_id: str) -> dict:
|
|
24
|
+
return await self._client.delete(f"/service-prices/{service_price_id}")
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
from persona_sdk.client import PersonaClient
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class SessionsApi:
|
|
5
|
+
def __init__(self, client: PersonaClient):
|
|
6
|
+
self._client = client
|
|
7
|
+
|
|
8
|
+
async def list(
|
|
9
|
+
self,
|
|
10
|
+
keyword: str = None,
|
|
11
|
+
status: str = None,
|
|
12
|
+
agent_id: str = None,
|
|
13
|
+
user_id: str = None,
|
|
14
|
+
page: int = 1,
|
|
15
|
+
size: int = 20,
|
|
16
|
+
) -> dict:
|
|
17
|
+
params = {"page": page, "size": size}
|
|
18
|
+
if keyword:
|
|
19
|
+
params["keyword"] = keyword
|
|
20
|
+
if status:
|
|
21
|
+
params["status"] = status
|
|
22
|
+
if agent_id:
|
|
23
|
+
params["agentId"] = agent_id
|
|
24
|
+
if user_id:
|
|
25
|
+
params["userId"] = user_id
|
|
26
|
+
return await self._client.get("/sessions", params=params)
|
|
27
|
+
|
|
28
|
+
async def get(self, session_id: str) -> dict:
|
|
29
|
+
return await self._client.get(f"/sessions/{session_id}")
|
|
30
|
+
|
|
31
|
+
async def get_usage(self, session_id: str) -> dict:
|
|
32
|
+
return await self._client.get(f"/sessions/{session_id}/usage")
|
|
33
|
+
|
|
34
|
+
async def generate_message(self, code: str, request: dict) -> dict:
|
|
35
|
+
return await self._client.post(f"/sessions/{code}/messages", json=request)
|
|
36
|
+
|
|
37
|
+
async def get_messages(self, code: str, page: int = 1, size: int = 20) -> dict:
|
|
38
|
+
params = {"page": page, "size": size}
|
|
39
|
+
return await self._client.get(f"/sessions/{code}/messages", params=params)
|
|
40
|
+
|
|
41
|
+
async def delete(self, code: str) -> dict:
|
|
42
|
+
return await self._client.delete(f"/sessions/{code}")
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
from persona_sdk.client import PersonaClient
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class TriggersApi:
|
|
5
|
+
def __init__(self, client: PersonaClient):
|
|
6
|
+
self._client = client
|
|
7
|
+
|
|
8
|
+
async def list(self, keyword: str = None, page: int = 1, size: int = 20) -> dict:
|
|
9
|
+
params = {"page": page, "size": size}
|
|
10
|
+
if keyword:
|
|
11
|
+
params["keyword"] = keyword
|
|
12
|
+
return await self._client.get("/triggers", params=params)
|
|
13
|
+
|
|
14
|
+
async def get(self, trigger_id: str) -> dict:
|
|
15
|
+
return await self._client.get(f"/triggers/{trigger_id}")
|
|
16
|
+
|
|
17
|
+
async def create(self, trigger: dict) -> dict:
|
|
18
|
+
return await self._client.post("/triggers", json=trigger)
|
|
19
|
+
|
|
20
|
+
async def update(self, trigger_id: str, trigger: dict) -> dict:
|
|
21
|
+
return await self._client.put(f"/triggers/{trigger_id}", json=trigger)
|
|
22
|
+
|
|
23
|
+
async def delete(self, trigger_id: str) -> dict:
|
|
24
|
+
return await self._client.delete(f"/triggers/{trigger_id}")
|
|
25
|
+
|
|
26
|
+
async def execute(self, trigger_id: str) -> dict:
|
|
27
|
+
return await self._client.post(f"/triggers/{trigger_id}/executions")
|
|
28
|
+
|
|
29
|
+
async def list_executions(self, trigger_id: str, page: int = 1, size: int = 20) -> dict:
|
|
30
|
+
params = {"page": page, "size": size}
|
|
31
|
+
return await self._client.get(f"/triggers/{trigger_id}/executions", params=params)
|
|
32
|
+
|
|
33
|
+
async def get_execution(self, execution_id: str) -> dict:
|
|
34
|
+
return await self._client.get(f"/triggers/executions/{execution_id}")
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
from persona_sdk.client import PersonaClient
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class WorkflowsApi:
|
|
5
|
+
def __init__(self, client: PersonaClient):
|
|
6
|
+
self._client = client
|
|
7
|
+
|
|
8
|
+
async def list(self, keyword: str = None, page: int = 1, size: int = 20) -> dict:
|
|
9
|
+
params = {"page": page, "size": size}
|
|
10
|
+
if keyword:
|
|
11
|
+
params["keyword"] = keyword
|
|
12
|
+
return await self._client.get("/workflows", params=params)
|
|
13
|
+
|
|
14
|
+
async def get(self, workflow_id: str) -> dict:
|
|
15
|
+
return await self._client.get(f"/workflows/{workflow_id}")
|
|
16
|
+
|
|
17
|
+
async def create(self, workflow: dict) -> dict:
|
|
18
|
+
return await self._client.post("/workflows", json=workflow)
|
|
19
|
+
|
|
20
|
+
async def update(self, workflow_id: str, workflow: dict) -> dict:
|
|
21
|
+
return await self._client.put(f"/workflows/{workflow_id}", json=workflow)
|
|
22
|
+
|
|
23
|
+
async def delete(self, workflow_id: str) -> dict:
|
|
24
|
+
return await self._client.delete(f"/workflows/{workflow_id}")
|
|
25
|
+
|
|
26
|
+
async def execute(self, workflow_id: str, data: dict = None) -> dict:
|
|
27
|
+
return await self._client.post(f"/workflows/{workflow_id}/execute", json=data or {})
|
|
28
|
+
|
|
29
|
+
async def queue(self, workflow_id: str, data: dict = None) -> dict:
|
|
30
|
+
return await self._client.post(f"/workflows/{workflow_id}/queue", json=data or {})
|
|
31
|
+
|
|
32
|
+
async def list_executions(self, workflow_id: str, page: int = 1, size: int = 20) -> dict:
|
|
33
|
+
params = {"page": page, "size": size}
|
|
34
|
+
return await self._client.get(f"/workflows/{workflow_id}/executions", params=params)
|
persona_sdk/client.py
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import httpx
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class PersonaClient:
|
|
5
|
+
"""
|
|
6
|
+
HTTP client for the Persona API.
|
|
7
|
+
|
|
8
|
+
Args:
|
|
9
|
+
base_url: The base URL of the Persona API (e.g. http://localhost:8000).
|
|
10
|
+
api_key: The API key or JWT token for authentication.
|
|
11
|
+
The x-persona-apikey header accepts both plain API keys and JWT tokens.
|
|
12
|
+
JWT tokens are automatically detected and validated by the server.
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
def __init__(self, base_url: str, api_key: str):
|
|
16
|
+
self.base_url = base_url.rstrip("/")
|
|
17
|
+
self.api_key = api_key
|
|
18
|
+
self._client = httpx.AsyncClient(
|
|
19
|
+
base_url=self.base_url,
|
|
20
|
+
headers={"x-persona-apikey": self.api_key},
|
|
21
|
+
timeout=30.0,
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
async def get(self, path: str, params: dict = None) -> dict:
|
|
25
|
+
response = await self._client.get(path, params=params)
|
|
26
|
+
response.raise_for_status()
|
|
27
|
+
return response.json()
|
|
28
|
+
|
|
29
|
+
async def post(self, path: str, json: dict = None) -> dict:
|
|
30
|
+
response = await self._client.post(path, json=json)
|
|
31
|
+
response.raise_for_status()
|
|
32
|
+
return response.json()
|
|
33
|
+
|
|
34
|
+
async def put(self, path: str, json: dict = None) -> dict:
|
|
35
|
+
response = await self._client.put(path, json=json)
|
|
36
|
+
response.raise_for_status()
|
|
37
|
+
return response.json()
|
|
38
|
+
|
|
39
|
+
async def patch(self, path: str, json: dict = None) -> dict:
|
|
40
|
+
response = await self._client.patch(path, json=json)
|
|
41
|
+
response.raise_for_status()
|
|
42
|
+
return response.json()
|
|
43
|
+
|
|
44
|
+
async def delete(self, path: str) -> dict:
|
|
45
|
+
response = await self._client.delete(path)
|
|
46
|
+
response.raise_for_status()
|
|
47
|
+
return response.json()
|
|
48
|
+
|
|
49
|
+
async def close(self):
|
|
50
|
+
await self._client.aclose()
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
from typing import Optional, Union, List
|
|
3
|
+
|
|
4
|
+
from pydantic import BaseModel
|
|
5
|
+
|
|
6
|
+
from persona_models import AgentResponse, GenerationResponse
|
|
7
|
+
from persona_models.common import create_uuid
|
|
8
|
+
from persona_models.mcp import GenerationRequest
|
|
9
|
+
from persona_models.sessions import AgentContext, Message, SessionType
|
|
10
|
+
from persona_sdk.client import PersonaClient
|
|
11
|
+
|
|
12
|
+
logger = logging.getLogger(__name__)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class AgentRunner:
|
|
16
|
+
def __init__(
|
|
17
|
+
self,
|
|
18
|
+
client: PersonaClient,
|
|
19
|
+
agent_id: str,
|
|
20
|
+
session_code: Optional[str] = None,
|
|
21
|
+
parent_session_id: Optional[str] = None,
|
|
22
|
+
user_id: Optional[str] = None,
|
|
23
|
+
session_type: SessionType = "async",
|
|
24
|
+
):
|
|
25
|
+
self._client = client
|
|
26
|
+
self.agent_id = agent_id
|
|
27
|
+
self.session_code = session_code or create_uuid()
|
|
28
|
+
self.parent_session_id = parent_session_id
|
|
29
|
+
self.user_id = user_id
|
|
30
|
+
self.session_type = session_type
|
|
31
|
+
|
|
32
|
+
async def __aenter__(self):
|
|
33
|
+
return self
|
|
34
|
+
|
|
35
|
+
async def __aexit__(self, exc_type, exc_value, traceback):
|
|
36
|
+
pass
|
|
37
|
+
|
|
38
|
+
async def run(
|
|
39
|
+
self,
|
|
40
|
+
request: Union[str, Message, List[Message]],
|
|
41
|
+
response_schema: Optional[type[BaseModel]] = None,
|
|
42
|
+
context: AgentContext = None,
|
|
43
|
+
) -> AgentResponse | None:
|
|
44
|
+
user_message = request
|
|
45
|
+
if isinstance(request, Message):
|
|
46
|
+
user_message = request.model_dump(by_alias=True)
|
|
47
|
+
elif isinstance(request, list):
|
|
48
|
+
user_message = [m.model_dump(by_alias=True) for m in request]
|
|
49
|
+
|
|
50
|
+
gen_request = GenerationRequest(
|
|
51
|
+
agent_id=self.agent_id,
|
|
52
|
+
parent_session_id=self.parent_session_id,
|
|
53
|
+
user_id=self.user_id,
|
|
54
|
+
user_message=user_message,
|
|
55
|
+
initial_context=context.model_dump(by_alias=True) if context else None,
|
|
56
|
+
response_schema=(
|
|
57
|
+
response_schema.model_json_schema() if response_schema else None
|
|
58
|
+
),
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
try:
|
|
62
|
+
response_data = await self._client.post(
|
|
63
|
+
f"/sessions/{self.session_code}/messages",
|
|
64
|
+
json=gen_request.model_dump(by_alias=True),
|
|
65
|
+
)
|
|
66
|
+
generation_response = GenerationResponse.model_validate(response_data)
|
|
67
|
+
return generation_response.response
|
|
68
|
+
except Exception as e:
|
|
69
|
+
logger.error(f"Error from Persona API: {e}")
|
|
70
|
+
return None
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
|
|
3
|
+
from persona_models.common import create_uuid
|
|
4
|
+
from persona_models.mcp import RetrieveResourceRequest, RetrieveResourceResponse, McpTransport
|
|
5
|
+
from persona_sdk.client import PersonaClient
|
|
6
|
+
|
|
7
|
+
logger = logging.getLogger(__name__)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class ResourceRetriever:
|
|
11
|
+
@staticmethod
|
|
12
|
+
async def retrieve(
|
|
13
|
+
client: PersonaClient,
|
|
14
|
+
mcp_server_name: str,
|
|
15
|
+
transport: McpTransport,
|
|
16
|
+
uri: str,
|
|
17
|
+
session_id: str = None,
|
|
18
|
+
user_id: str = None,
|
|
19
|
+
billing_disabled: bool = False,
|
|
20
|
+
) -> str | dict | None:
|
|
21
|
+
request = RetrieveResourceRequest(
|
|
22
|
+
mcp_server_name=mcp_server_name,
|
|
23
|
+
transport=transport,
|
|
24
|
+
uri=uri,
|
|
25
|
+
session_id=session_id or create_uuid("resource-retrieve"),
|
|
26
|
+
user_id=user_id,
|
|
27
|
+
billing_disabled=billing_disabled,
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
response_data = await client.post(
|
|
31
|
+
"/mcp/resources/retrieve",
|
|
32
|
+
json=request.model_dump(by_alias=True),
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
result = RetrieveResourceResponse.model_validate(response_data)
|
|
36
|
+
|
|
37
|
+
if result.contents:
|
|
38
|
+
for content in result.contents:
|
|
39
|
+
if isinstance(content, dict):
|
|
40
|
+
if "blob" in content:
|
|
41
|
+
return {
|
|
42
|
+
"content": content.get("blob"),
|
|
43
|
+
"content_type": content.get("mimeType"),
|
|
44
|
+
}
|
|
45
|
+
elif "text" in content:
|
|
46
|
+
return content.get("text")
|
|
47
|
+
|
|
48
|
+
return None
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
async def retrieve_resource(
|
|
52
|
+
client: PersonaClient,
|
|
53
|
+
mcp_server_name: str,
|
|
54
|
+
transport: McpTransport,
|
|
55
|
+
uri: str,
|
|
56
|
+
session_id: str = None,
|
|
57
|
+
user_id: str = None,
|
|
58
|
+
billing_disabled: bool = False,
|
|
59
|
+
) -> str | dict | None:
|
|
60
|
+
return await ResourceRetriever.retrieve(
|
|
61
|
+
client=client,
|
|
62
|
+
mcp_server_name=mcp_server_name,
|
|
63
|
+
transport=transport,
|
|
64
|
+
uri=uri,
|
|
65
|
+
session_id=session_id,
|
|
66
|
+
user_id=user_id,
|
|
67
|
+
billing_disabled=billing_disabled,
|
|
68
|
+
)
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
|
|
3
|
+
from persona_models.common import create_uuid
|
|
4
|
+
from persona_models.mcp import ToolInvokeRequest, ToolInvokeResponse, McpTransport
|
|
5
|
+
from persona_sdk.client import PersonaClient
|
|
6
|
+
|
|
7
|
+
logger = logging.getLogger(__name__)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class ToolInvoker:
|
|
11
|
+
@staticmethod
|
|
12
|
+
async def invoke(
|
|
13
|
+
client: PersonaClient,
|
|
14
|
+
mcp_server_name: str,
|
|
15
|
+
transport: McpTransport,
|
|
16
|
+
tool_name: str,
|
|
17
|
+
args: dict = None,
|
|
18
|
+
session_id: str = None,
|
|
19
|
+
user_id: str = None,
|
|
20
|
+
billing_disabled: bool = False,
|
|
21
|
+
) -> ToolInvokeResponse:
|
|
22
|
+
request = ToolInvokeRequest(
|
|
23
|
+
mcp_server_name=mcp_server_name,
|
|
24
|
+
transport=transport,
|
|
25
|
+
tool_name=tool_name,
|
|
26
|
+
args=args or {},
|
|
27
|
+
session_id=session_id or create_uuid("tool-invoke"),
|
|
28
|
+
user_id=user_id,
|
|
29
|
+
billing_disabled=billing_disabled,
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
response_data = await client.post(
|
|
33
|
+
"/mcp/tools/invoke",
|
|
34
|
+
json=request.model_dump(by_alias=True),
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
return ToolInvokeResponse.model_validate(response_data)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
async def invoke_tool(
|
|
41
|
+
client: PersonaClient,
|
|
42
|
+
mcp_server_name: str,
|
|
43
|
+
transport: McpTransport,
|
|
44
|
+
tool_name: str,
|
|
45
|
+
args: dict = None,
|
|
46
|
+
session_id: str = None,
|
|
47
|
+
user_id: str = None,
|
|
48
|
+
billing_disabled: bool = False,
|
|
49
|
+
) -> ToolInvokeResponse:
|
|
50
|
+
return await ToolInvoker.invoke(
|
|
51
|
+
client=client,
|
|
52
|
+
mcp_server_name=mcp_server_name,
|
|
53
|
+
transport=transport,
|
|
54
|
+
tool_name=tool_name,
|
|
55
|
+
args=args,
|
|
56
|
+
session_id=session_id,
|
|
57
|
+
user_id=user_id,
|
|
58
|
+
billing_disabled=billing_disabled,
|
|
59
|
+
)
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
persona_sdk/__init__.py,sha256=LJldOXaAvV9-60pclsKbgk7HDb3Rvx3mgXhoBqZbYdM,1513
|
|
2
|
+
persona_sdk/client.py,sha256=8C2gWeVZVvmM58qycL3l2DFBxXeRss0YSRwJDhP_4PQ,1707
|
|
3
|
+
persona_sdk/api/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
|
+
persona_sdk/api/agents.py,sha256=LO-e_keKlZhIpsMMAvYuWTHKh3aypHYRXnD1LSUqCu8,1027
|
|
5
|
+
persona_sdk/api/credentials.py,sha256=fe2D2IH2p4K7kDDZJF5VQfYBNSgYqAe7hfgOsl5ha_I,792
|
|
6
|
+
persona_sdk/api/features.py,sha256=6jMCn66RYsfSg9rP_KWLdemoBHN4dW6_PrbvHAvQweI,1159
|
|
7
|
+
persona_sdk/api/knowledge_bases.py,sha256=8W78AfegdpzhDOOzM6GI3JFYXvC1-Tjc_G2nxjWCuG0,1605
|
|
8
|
+
persona_sdk/api/missions.py,sha256=zAuj5-W5KQ7Y424tfSmut_kpScbgb5zV-lmwN7BuyG8,1688
|
|
9
|
+
persona_sdk/api/projects.py,sha256=1HN6M91wWa_UQJJZFQwi3kZT3ukBDnAeMyoFgyU9aSs,1001
|
|
10
|
+
persona_sdk/api/service_prices.py,sha256=r60Sr2Pu9BDSlFqyDSElV2-93ofKrQN6PVAsv4LPX6s,1001
|
|
11
|
+
persona_sdk/api/sessions.py,sha256=5tA6OYbvkj4E9yIQ6XvX2z5XSO6M8-nyuvrr_4qqs58,1430
|
|
12
|
+
persona_sdk/api/triggers.py,sha256=0AGQlc9wgtZgNbLl-7De8ntHAVj4ZlS-W2BHflof-GA,1410
|
|
13
|
+
persona_sdk/api/workflows.py,sha256=WtSzN2p6YtXa-tE157aQu5kuZaAR1QavgZD0FR3EBMY,1488
|
|
14
|
+
persona_sdk/runners/__init__.py,sha256=GzO-IwwCp7VeBVWLAQFDeg30Q8SaVBHIWT4Fy8gwl0g,183
|
|
15
|
+
persona_sdk/runners/agent_runner.py,sha256=wztVa44d-9cC0Bg-GVli7YuIy6jnG0j_PL5d017fbyI,2394
|
|
16
|
+
persona_sdk/runners/resource_retriever.py,sha256=_ZsSk8XUpOjqtzLB30xpGFFQ_1gGmlQxlgjSVnpetxw,2032
|
|
17
|
+
persona_sdk/runners/tool_invoker.py,sha256=DVtl45MpEMB5w7gRgW6CsuX97nRUaHosd0vE_pCjVbE,1643
|
|
18
|
+
persona_sdk_python-0.1.0.dist-info/METADATA,sha256=ubAJkpRYZ454rh-cVaHiwucZcBYcB4fkYpvXDs9st9A,203
|
|
19
|
+
persona_sdk_python-0.1.0.dist-info/WHEEL,sha256=QccIxa26bgl1E6uMy58deGWi-0aeIkkangHcxk2kWfw,87
|
|
20
|
+
persona_sdk_python-0.1.0.dist-info/RECORD,,
|