agentos-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.
@@ -0,0 +1,14 @@
1
+ from .handlers import AgentMessageHandler, AgentOSEventHandler, EventType, ToolReturn
2
+ from .sdk import AgentOSSDK
3
+ from .transport import ApiClient, ApiError, SseEvent
4
+
5
+ __all__ = [
6
+ "AgentMessageHandler",
7
+ "AgentOSEventHandler",
8
+ "AgentOSSDK",
9
+ "ApiClient",
10
+ "ApiError",
11
+ "EventType",
12
+ "SseEvent",
13
+ "ToolReturn",
14
+ ]
@@ -0,0 +1,15 @@
1
+ from .agentkit import AgentKitClient
2
+ from .appkit import AppKitClient
3
+ from .cronkit import CronKitClient
4
+ from .modelkit import ModelKitClient
5
+ from .systemkit import SystemKitClient
6
+ from .toolkit import ToolKitClient
7
+
8
+ __all__ = [
9
+ "AgentKitClient",
10
+ "AppKitClient",
11
+ "CronKitClient",
12
+ "ModelKitClient",
13
+ "SystemKitClient",
14
+ "ToolKitClient",
15
+ ]
@@ -0,0 +1,152 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import Any, AsyncIterator, Mapping
4
+
5
+ from agentos_sdk.normalizers import (
6
+ normalize_agent_event_name,
7
+ normalize_capability,
8
+ normalize_simple_capability,
9
+ normalize_user_task,
10
+ )
11
+ from agentos_sdk.transport import ApiClient, SseEvent, iter_sse
12
+
13
+
14
+ class AgentKitClient:
15
+ def __init__(self, api_client: ApiClient | None = None) -> None:
16
+ self.api_client = api_client or ApiClient()
17
+
18
+ async def get_version(self, bearer_token: str) -> dict[str, Any]:
19
+ return await self.api_client.request("/agentkit/version", headers=_auth(bearer_token))
20
+
21
+ async def get_agent(self, bearer_token: str, agent_id: str) -> dict[str, Any]:
22
+ return await self.api_client.request(
23
+ "/agentkit/agent", query={"agentId": agent_id}, headers=_auth(bearer_token)
24
+ )
25
+
26
+ async def create_agent(self, bearer_token: str, agent: Mapping[str, Any]) -> dict[str, Any]:
27
+ return await self.api_client.request(
28
+ "/agentkit/agent/create",
29
+ method="POST",
30
+ headers=_auth(bearer_token),
31
+ data=dict(agent),
32
+ )
33
+
34
+ async def update_agent(
35
+ self, bearer_token: str, agent_id: str, agent: Mapping[str, Any]
36
+ ) -> dict[str, Any]:
37
+ return await self.api_client.request(
38
+ "/agentkit/agent/update",
39
+ method="POST",
40
+ query={"agentId": agent_id},
41
+ headers=_auth(bearer_token),
42
+ data=dict(agent),
43
+ )
44
+
45
+ async def delete_agent(self, bearer_token: str, agent_id: str) -> dict[str, Any]:
46
+ return await self.api_client.request(
47
+ "/agentkit/agent/delete", query={"agentId": agent_id}, headers=_auth(bearer_token)
48
+ )
49
+
50
+ async def init_session(
51
+ self,
52
+ bearer_token: str,
53
+ *,
54
+ agent_id: str | None = None,
55
+ capability: Mapping[str, Any] | None = None,
56
+ ) -> dict[str, Any]:
57
+ return await self.api_client.request(
58
+ "/agentkit/initSession",
59
+ method="POST",
60
+ query={"agentId": agent_id} if agent_id else None,
61
+ headers=_auth(bearer_token),
62
+ data=normalize_capability(capability) if capability else None,
63
+ )
64
+
65
+ async def init_simple(
66
+ self, bearer_token: str, simple_capability: Mapping[str, Any]
67
+ ) -> dict[str, Any]:
68
+ return await self.api_client.request(
69
+ "/agentkit/initSimple",
70
+ method="POST",
71
+ headers=_auth(bearer_token),
72
+ data=normalize_simple_capability(simple_capability),
73
+ )
74
+
75
+ async def chat(
76
+ self, bearer_token: str, session_id: str, user_task: Mapping[str, Any]
77
+ ) -> AsyncIterator[SseEvent]:
78
+ response = await self.api_client.request_stream(
79
+ "/agentkit/chat",
80
+ method="POST",
81
+ query={"sessionId": session_id},
82
+ headers=_auth(bearer_token),
83
+ data=normalize_user_task(user_task),
84
+ )
85
+ async for event in iter_sse(response):
86
+ yield SseEvent(normalize_agent_event_name(event.event), event.data)
87
+
88
+ async def chat_simple(
89
+ self, bearer_token: str, session_id: str, user_task: Mapping[str, Any]
90
+ ) -> dict[str, Any]:
91
+ return await self.api_client.request(
92
+ "/agentkit/chat/simple",
93
+ method="POST",
94
+ query={"sessionId": session_id},
95
+ headers=_auth(bearer_token),
96
+ data=normalize_user_task(user_task),
97
+ )
98
+
99
+ async def history(self, bearer_token: str, session_id: str) -> list[Any]:
100
+ return await self.api_client.request(
101
+ "/agentkit/history", query={"sessionId": session_id}, headers=_auth(bearer_token)
102
+ )
103
+
104
+ async def stop(
105
+ self, bearer_token: str, session_id: str, task_id: str | None = None
106
+ ) -> dict[str, Any]:
107
+ return await self.api_client.request(
108
+ "/agentkit/stop",
109
+ query={"sessionId": session_id, "taskId": task_id},
110
+ headers=_auth(bearer_token),
111
+ )
112
+
113
+ async def clear(self, bearer_token: str, session_id: str) -> dict[str, Any]:
114
+ return await self.api_client.request(
115
+ "/agentkit/clear", query={"sessionId": session_id}, headers=_auth(bearer_token)
116
+ )
117
+
118
+ async def callback(
119
+ self, bearer_token: str, session_id: str, tool_return: Mapping[str, Any]
120
+ ) -> dict[str, Any]:
121
+ return await self.api_client.request(
122
+ "/agentkit/callback",
123
+ method="POST",
124
+ query={"sessionId": session_id},
125
+ headers=_auth(bearer_token),
126
+ data=dict(tool_return),
127
+ )
128
+
129
+ async def stream_callback(
130
+ self, bearer_token: str, session_id: str, event_tool_return: Mapping[str, Any]
131
+ ) -> dict[str, Any]:
132
+ return await self.api_client.request(
133
+ "/agentkit/streamCallback",
134
+ method="POST",
135
+ query={"sessionId": session_id},
136
+ headers=_auth(bearer_token),
137
+ data=dict(event_tool_return),
138
+ )
139
+
140
+ getVersion = get_version
141
+ getAgent = get_agent
142
+ createAgent = create_agent
143
+ updateAgent = update_agent
144
+ deleteAgent = delete_agent
145
+ initSession = init_session
146
+ initSimple = init_simple
147
+ chatSimple = chat_simple
148
+ streamCallback = stream_callback
149
+
150
+
151
+ def _auth(token: str) -> dict[str, str]:
152
+ return {"authorization": f"Bearer {token}"}
@@ -0,0 +1,23 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import Any, AsyncIterator, Mapping
4
+
5
+ from agentos_sdk.transport import ApiClient, SseEvent, iter_sse
6
+
7
+
8
+ class AppKitClient:
9
+ def __init__(self, api_client: ApiClient | None = None) -> None:
10
+ self.api_client = api_client or ApiClient()
11
+
12
+ async def register_bundle(self, bundle: Mapping[str, Any]) -> dict[str, Any]:
13
+ return await self.api_client.request("/appkit/register", method="POST", data=dict(bundle))
14
+
15
+ async def subscribe(self, bearer_token: str) -> AsyncIterator[SseEvent]:
16
+ response = await self.api_client.request_stream(
17
+ "/appkit/subscribe",
18
+ headers={"authorization": f"Bearer {bearer_token}"},
19
+ )
20
+ async for event in iter_sse(response):
21
+ yield event
22
+
23
+ registerBundle = register_bundle
@@ -0,0 +1,144 @@
1
+ from __future__ import annotations
2
+
3
+ from datetime import datetime
4
+ from typing import Any, Mapping
5
+
6
+ from agentos_sdk.normalizers import cron_create_defaults
7
+ from agentos_sdk.transport import ApiClient
8
+
9
+
10
+ class CronKitClient:
11
+ def __init__(self, api_client: ApiClient | None = None) -> None:
12
+ self.api_client = api_client or ApiClient()
13
+
14
+ async def get_task(self, bearer_token: str, cron_id: str) -> dict[str, Any]:
15
+ return await self.api_client.request(
16
+ "/cronkit/task", query={"cronId": cron_id}, headers=_auth(bearer_token)
17
+ )
18
+
19
+ async def list_tasks(
20
+ self,
21
+ bearer_token: str,
22
+ *,
23
+ enabled: bool | None = None,
24
+ offset: int | None = None,
25
+ limit: int | None = None,
26
+ ) -> list[dict[str, Any]]:
27
+ return await self.api_client.request(
28
+ "/cronkit/task/list",
29
+ query={"enabled": enabled, "offset": offset, "limit": limit},
30
+ headers=_auth(bearer_token),
31
+ )
32
+
33
+ async def create_task(self, bearer_token: str, request: Mapping[str, Any]) -> dict[str, Any]:
34
+ return await self.api_client.request(
35
+ "/cronkit/task/create",
36
+ method="POST",
37
+ headers=_auth(bearer_token),
38
+ data=cron_create_defaults(request),
39
+ )
40
+
41
+ async def update_task(self, bearer_token: str, request: Mapping[str, Any]) -> dict[str, Any]:
42
+ return await self.api_client.request(
43
+ "/cronkit/task/update", method="POST", headers=_auth(bearer_token), data=dict(request)
44
+ )
45
+
46
+ async def delete_task(self, bearer_token: str, cron_id: str) -> dict[str, Any]:
47
+ return await self.api_client.request(
48
+ "/cronkit/task/delete",
49
+ method="POST",
50
+ headers=_auth(bearer_token),
51
+ data={"cronId": cron_id},
52
+ )
53
+
54
+ async def enable_task(self, bearer_token: str, cron_id: str) -> dict[str, Any]:
55
+ return await self._set_task_enabled(bearer_token, cron_id, True)
56
+
57
+ async def disable_task(self, bearer_token: str, cron_id: str) -> dict[str, Any]:
58
+ return await self._set_task_enabled(bearer_token, cron_id, False)
59
+
60
+ async def run_task_now(
61
+ self, bearer_token: str, cron_id: str, scheduled_at: datetime | None = None
62
+ ) -> dict[str, Any]:
63
+ data = {"cronId": cron_id}
64
+ if scheduled_at:
65
+ data["scheduledAt"] = scheduled_at.isoformat()
66
+ return await self.api_client.request(
67
+ "/cronkit/task/runNow", method="POST", headers=_auth(bearer_token), data=data
68
+ )
69
+
70
+ async def get_run(self, bearer_token: str, run_id: str) -> dict[str, Any]:
71
+ return await self.api_client.request(
72
+ "/cronkit/run", query={"runId": run_id}, headers=_auth(bearer_token)
73
+ )
74
+
75
+ async def list_runs(
76
+ self,
77
+ bearer_token: str,
78
+ *,
79
+ cron_id: str | None = None,
80
+ after: datetime | None = None,
81
+ before: datetime | None = None,
82
+ offset: int | None = None,
83
+ limit: int | None = None,
84
+ ) -> list[dict[str, Any]]:
85
+ return await self.api_client.request(
86
+ "/cronkit/run/list",
87
+ query={
88
+ "cronId": cron_id,
89
+ "after": after,
90
+ "before": before,
91
+ "offset": offset,
92
+ "limit": limit,
93
+ },
94
+ headers=_auth(bearer_token),
95
+ )
96
+
97
+ async def list_run_messages(
98
+ self,
99
+ bearer_token: str,
100
+ run_id: str,
101
+ *,
102
+ offset: int | None = None,
103
+ limit: int | None = None,
104
+ ) -> list[dict[str, Any]]:
105
+ return await self.api_client.request(
106
+ "/cronkit/run/messages",
107
+ query={"runId": run_id, "offset": offset, "limit": limit},
108
+ headers=_auth(bearer_token),
109
+ )
110
+
111
+ async def delete_run(self, bearer_token: str, run_id: str) -> dict[str, Any]:
112
+ return await self.api_client.request(
113
+ "/cronkit/run/delete",
114
+ method="POST",
115
+ headers=_auth(bearer_token),
116
+ data={"runId": run_id},
117
+ )
118
+
119
+ async def _set_task_enabled(
120
+ self, bearer_token: str, cron_id: str, enabled: bool
121
+ ) -> dict[str, Any]:
122
+ return await self.api_client.request(
123
+ "/cronkit/task/setEnabled",
124
+ method="POST",
125
+ headers=_auth(bearer_token),
126
+ data={"cronId": cron_id, "enabled": enabled},
127
+ )
128
+
129
+ getTask = get_task
130
+ listTasks = list_tasks
131
+ createTask = create_task
132
+ updateTask = update_task
133
+ deleteTask = delete_task
134
+ enableTask = enable_task
135
+ disableTask = disable_task
136
+ runTaskNow = run_task_now
137
+ getRun = get_run
138
+ listRuns = list_runs
139
+ listRunMessages = list_run_messages
140
+ deleteRun = delete_run
141
+
142
+
143
+ def _auth(token: str) -> dict[str, str]:
144
+ return {"authorization": f"Bearer {token}"}
@@ -0,0 +1,127 @@
1
+ from __future__ import annotations
2
+
3
+ import json
4
+ from pathlib import Path
5
+ from typing import Any, AsyncIterator, Mapping
6
+
7
+ from agentos_sdk.normalizers import normalize_model_info, serialize_chat_request
8
+ from agentos_sdk.transport import ApiClient, iter_sse
9
+
10
+
11
+ class ModelKitChatClient:
12
+ def __init__(self, api_client: ApiClient) -> None:
13
+ self.api_client = api_client
14
+ self.base_url = f"{api_client.base_url.rstrip('/')}/modelkit/chat"
15
+
16
+ async def create(self, request: Mapping[str, Any]) -> dict[str, Any]:
17
+ return await self.api_client.request(
18
+ "/modelkit/chat/v1/chat/completions",
19
+ method="POST",
20
+ data=serialize_chat_request(request),
21
+ )
22
+
23
+ async def create_stream(self, request: Mapping[str, Any]) -> AsyncIterator[dict[str, Any]]:
24
+ payload = serialize_chat_request({**dict(request), "stream": True})
25
+ response = await self.api_client.request_stream(
26
+ "/modelkit/chat/v1/chat/completions",
27
+ method="POST",
28
+ data=payload,
29
+ )
30
+ async for event in iter_sse(response):
31
+ if event.data == "[DONE]":
32
+ return
33
+ yield json.loads(event.data)
34
+
35
+ async def create_remote_function_stream(
36
+ self, request: Mapping[str, Any]
37
+ ) -> AsyncIterator[dict[str, Any]]:
38
+ async for chunk in self.create_stream(request):
39
+ yield chunk
40
+
41
+ createStream = create_stream
42
+ createRemoteFunctionStream = create_remote_function_stream
43
+
44
+
45
+ class ModelKitEmbeddingClient:
46
+ def __init__(self, api_client: ApiClient) -> None:
47
+ self.api_client = api_client
48
+
49
+ async def create(self, request: Mapping[str, Any]) -> dict[str, Any]:
50
+ return await self.api_client.request(
51
+ "/modelkit/embedding/v1/embeddings",
52
+ method="POST",
53
+ data=dict(request),
54
+ )
55
+
56
+
57
+ class ModelKitAsrClient:
58
+ def __init__(self, api_client: ApiClient) -> None:
59
+ self.api_client = api_client
60
+
61
+ async def transcribe(self, request: Mapping[str, Any]) -> dict[str, Any]:
62
+ file_value = request["file"]
63
+ file_name = str(request.get("fileName", "audio.bin"))
64
+ if isinstance(file_value, (str, Path)):
65
+ path = Path(file_value)
66
+ file_part = (str(request.get("fileName", path.name)), path.read_bytes())
67
+ elif isinstance(file_value, bytes):
68
+ file_part = (file_name, file_value)
69
+ else:
70
+ file_part = file_value
71
+ form_data = {
72
+ key: json.dumps(value) if isinstance(value, (dict, list)) else str(value)
73
+ for key, value in request.items()
74
+ if key not in {"file", "fileName"} and value is not None
75
+ }
76
+ result = await self.api_client.request_multipart(
77
+ "/modelkit/asr/v1/audio/transcriptions",
78
+ data=form_data,
79
+ files={"file": file_part},
80
+ )
81
+ if isinstance(result, dict):
82
+ return result
83
+ if isinstance(result, str) and result:
84
+ try:
85
+ decoded = json.loads(result)
86
+ except json.JSONDecodeError:
87
+ return {"text": result}
88
+ return decoded if isinstance(decoded, dict) else {"text": result}
89
+ return {}
90
+
91
+
92
+ class ModelKitTtsClient:
93
+ def __init__(self, api_client: ApiClient) -> None:
94
+ self.api_client = api_client
95
+
96
+ async def synthesize(self, request: Mapping[str, Any]) -> bytes:
97
+ return await self.api_client.request_bytes(
98
+ "/modelkit/tts/v1/audio/speech",
99
+ method="POST",
100
+ data=dict(request),
101
+ headers={"accept": "audio/*"},
102
+ )
103
+
104
+ async def list_voices(self) -> dict[str, Any]:
105
+ result = await self.api_client.request("/modelkit/tts/v1/audio/voices")
106
+ return result if isinstance(result, dict) else {}
107
+
108
+ listVoices = list_voices
109
+
110
+
111
+ class ModelKitClient:
112
+ def __init__(self, api_client: ApiClient | None = None) -> None:
113
+ self.api_client = api_client or ApiClient()
114
+ self.chat = ModelKitChatClient(self.api_client)
115
+ self.embedding = ModelKitEmbeddingClient(self.api_client)
116
+ self.asr = ModelKitAsrClient(self.api_client)
117
+ self.tts = ModelKitTtsClient(self.api_client)
118
+
119
+ async def list_models(self) -> list[dict[str, Any]]:
120
+ data = await self.api_client.request("/modelkit/models")
121
+ return [normalize_model_info(item) for item in data]
122
+
123
+ async def list_models_by_task(self, task: str) -> list[dict[str, Any]]:
124
+ return [model for model in await self.list_models() if model["task"] == task]
125
+
126
+ listModels = list_models
127
+ listModelsByTask = list_models_by_task
@@ -0,0 +1,23 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import Any
4
+
5
+ from agentos_sdk.transport import ApiClient
6
+
7
+
8
+ class SystemKitClient:
9
+ def __init__(self, api_client: ApiClient | None = None) -> None:
10
+ self.api_client = api_client or ApiClient()
11
+
12
+ async def get_version(self) -> dict[str, Any]:
13
+ return await self.api_client.request("/version")
14
+
15
+ async def get_root(self) -> dict[str, Any]:
16
+ return await self.api_client.request("/")
17
+
18
+ async def get_ready(self) -> dict[str, Any]:
19
+ return await self.api_client.request("/ready")
20
+
21
+ getVersion = get_version
22
+ getRoot = get_root
23
+ getReady = get_ready
@@ -0,0 +1,43 @@
1
+ from __future__ import annotations
2
+
3
+ import json
4
+ from typing import Any, AsyncIterator
5
+
6
+ from agentos_sdk.protocol import OpenToolDefinition
7
+ from agentos_sdk.transport import ApiClient, iter_sse
8
+
9
+
10
+ class ToolKitClient:
11
+ def __init__(self, api_client: ApiClient | None = None) -> None:
12
+ self.api_client = api_client or ApiClient()
13
+
14
+ async def list_tool(self, all: str | None = None) -> list[dict[str, Any]]:
15
+ return await self.api_client.request(
16
+ "/toolkit/list",
17
+ query={"all": all} if all else None,
18
+ )
19
+
20
+ async def load_tool(self, tool_id: str) -> OpenToolDefinition | None:
21
+ response = await self.api_client.request(f"/toolkit/{tool_id}/load")
22
+ if response is None:
23
+ return None
24
+ return OpenToolDefinition(response)
25
+
26
+ async def subscribe_tool_events(
27
+ self,
28
+ daemon_api_key: str,
29
+ snapshot: bool = True,
30
+ ) -> AsyncIterator[dict[str, Any]]:
31
+ response = await self.api_client.request_stream(
32
+ "/toolkit/events",
33
+ query={"snapshot": "1" if snapshot else "0"},
34
+ headers={"x-tool-api-key": daemon_api_key},
35
+ )
36
+ async for event in iter_sse(response):
37
+ if event.event == "ready":
38
+ continue
39
+ yield json.loads(event.data)
40
+
41
+ listTool = list_tool
42
+ loadTool = load_tool
43
+ subscribeToolEvents = subscribe_tool_events
@@ -0,0 +1,92 @@
1
+ from __future__ import annotations
2
+
3
+ from dataclasses import dataclass
4
+ from typing import Any, Callable
5
+
6
+
7
+ class EventType:
8
+ DATA = "data"
9
+ DONE = "done"
10
+ ERROR = "error"
11
+
12
+
13
+ @dataclass
14
+ class ToolReturn:
15
+ id: str
16
+ result: Any
17
+
18
+ def to_json(self) -> dict[str, Any]:
19
+ return {"id": self.id, "result": self.result}
20
+
21
+ def toJson(self) -> dict[str, Any]:
22
+ return self.to_json()
23
+
24
+
25
+ class AgentOSEventHandler:
26
+ async def on_welcome(self, welcome: dict[str, Any]) -> None:
27
+ pass
28
+
29
+ async def on_call_app(self, call: dict[str, Any]) -> None:
30
+ pass
31
+
32
+ async def on_done(self) -> None:
33
+ pass
34
+
35
+ async def on_error(self, error: Exception) -> None:
36
+ pass
37
+
38
+ onWelcome = on_welcome
39
+ onCallApp = on_call_app
40
+ onDone = on_done
41
+ onError = on_error
42
+
43
+
44
+ class AgentMessageHandler:
45
+ async def on_function_call(
46
+ self, session_id: str, function_call: dict[str, Any]
47
+ ) -> ToolReturn | dict[str, Any]:
48
+ return ToolReturn(
49
+ function_call["id"],
50
+ {
51
+ "error": "FunctionNotSupportedException",
52
+ "message": function_call.get("name", ""),
53
+ },
54
+ )
55
+
56
+ async def on_stream_function_call(
57
+ self,
58
+ session_id: str,
59
+ function_call: dict[str, Any],
60
+ on_tool_return: Callable[[dict[str, Any]], None],
61
+ ) -> None:
62
+ on_tool_return(
63
+ {
64
+ "event": EventType.ERROR,
65
+ "toolReturn": ToolReturn(
66
+ function_call["id"],
67
+ {
68
+ "error": "FunctionNotSupportedException",
69
+ "message": function_call.get("name", ""),
70
+ },
71
+ ).to_json(),
72
+ }
73
+ )
74
+
75
+ async def on_message(self, session_id: str, message: dict[str, Any]) -> None:
76
+ raise NotImplementedError
77
+
78
+ async def on_chunk(self, session_id: str, chunk: dict[str, Any]) -> None:
79
+ raise NotImplementedError
80
+
81
+ async def on_done(self) -> None:
82
+ raise NotImplementedError
83
+
84
+ async def on_error(self, error: Exception) -> None:
85
+ raise NotImplementedError
86
+
87
+ onFunctionCall = on_function_call
88
+ onStreamFunctionCall = on_stream_function_call
89
+ onMessage = on_message
90
+ onChunk = on_chunk
91
+ onDone = on_done
92
+ onError = on_error