aice-agent-platform 0.2.1__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,7 @@
1
+ """Python SDK for the AICE Agent Platform."""
2
+
3
+ from aice_agent_platform.client import AgentPlatformClient, AsyncAgentPlatformClient
4
+
5
+ __version__ = "0.2.1"
6
+
7
+ __all__ = ["AgentPlatformClient", "AsyncAgentPlatformClient", "__version__"]
@@ -0,0 +1,283 @@
1
+ """Sync and async clients for the AICE Agent Platform.
2
+
3
+ This service is deployed as a LangGraph Platform-compatible server (custom
4
+ auth validates AICE's own bearer tokens instead of LangSmith's scheme), so
5
+ this client is a **composition** of two things rather than one:
6
+
7
+ 1. The native LangGraph surface ``threads``, ``runs``, ``assistants``,
8
+ ``crons`` exposed unmodified via the vendor ``langgraph-sdk`` package
9
+ (``get_sync_client``/``get_client``). This is where streaming/run
10
+ execution lives: ``client.runs.stream(...)``,
11
+ ``client.threads.create(...)``, etc. See the `LangGraph SDK reference
12
+ <https://reference.langchain.com/python/langgraph-sdk>`_ for the full
13
+ surface. We pass our own bearer token through as a header and disable
14
+ the vendor SDK's own API-key handling (``api_key=None``) so it doesn't
15
+ also try to read ``LANGSMITH_API_KEY``/``LANGGRAPH_API_KEY`` from the
16
+ environment.
17
+ 2. AICE-specific management routes ``agents``, ``skills``, ``usage``,
18
+ ``suggestions`` that don't exist in LangGraph's own API. These are
19
+ custom siblings routed through ``aice_core``'s shared transport
20
+ (retries, typed errors, idempotency keys), exactly like every other
21
+ AICE service.
22
+
23
+ **Important asymmetry to be aware of:** (1) and (2) do NOT share error
24
+ handling or retry behavior. Calls through ``client.threads``/``client.runs``/
25
+ ``client.assistants``/``client.crons`` raise whatever ``langgraph-sdk``
26
+ itself raises (its own HTTP error types, its own retry policy via
27
+ ``callerOptions``) they never raise ``aice_core.AiceError`` subclasses and
28
+ never pass through the idempotency-key handling documented in
29
+ ``docs/conventions.md``. Calls through ``client.agents``/``client.skills``/
30
+ ``client.usage``/``client.suggestions`` behave like every other AICE SDK
31
+ (typed ``AiceError`` hierarchy, ``aice_core``'s retry/idempotency rules).
32
+ Don't assume uniform behavior across the two if you need a
33
+ ``langgraph-sdk`` failure to look like an ``AiceError`` for your own error
34
+ handling, catch and translate at the call site (see ``aice_sandbox`` for the
35
+ translation-layer pattern if this becomes common enough to warrant one).
36
+
37
+ Custom (AICE-specific) routes exposed by the upstream service (see
38
+ ``agent_platform/app/api/http_app.py``):
39
+
40
+ * ``GET /agents`` list configured agents
41
+ * ``POST /agents`` create an agent definition
42
+ * ``POST /agents/{agent_id}/publish`` publish an agent
43
+ * ``GET /skills`` list skills
44
+ * ``POST /skills`` create a skill
45
+ * ``POST /skills/{skill_id}/publish`` publish a skill
46
+ * ``GET /usage`` usage counters for the current project
47
+ * ``GET /suggestions/starters`` starter prompts
48
+ * ``POST /threads/{thread_id}/postturn`` generate post-turn suggestions
49
+ """
50
+
51
+ from __future__ import annotations
52
+
53
+ from typing import Any
54
+
55
+ from langgraph_sdk import get_client, get_sync_client
56
+
57
+ from aice_core import AsyncTransport, AuthContext, SyncTransport
58
+
59
+ _SERVICE_NAME = "agent-platform"
60
+
61
+
62
+ class _AgentsResource:
63
+ def __init__(self, transport: SyncTransport) -> None:
64
+ self._t = transport
65
+
66
+ def list(self) -> list[dict[str, Any]]:
67
+ return self._t.request("GET", "/agents")
68
+
69
+ def create(self, spec: dict[str, Any]) -> dict[str, Any]:
70
+ return self._t.request("POST", "/agents", json=spec)
71
+
72
+ def publish(self, agent_id: str) -> dict[str, Any]:
73
+ return self._t.request("POST", f"/agents/{agent_id}/publish")
74
+
75
+
76
+ class _AsyncAgentsResource:
77
+ def __init__(self, transport: AsyncTransport) -> None:
78
+ self._t = transport
79
+
80
+ async def list(self) -> list[dict[str, Any]]:
81
+ return await self._t.request("GET", "/agents")
82
+
83
+ async def create(self, spec: dict[str, Any]) -> dict[str, Any]:
84
+ return await self._t.request("POST", "/agents", json=spec)
85
+
86
+ async def publish(self, agent_id: str) -> dict[str, Any]:
87
+ return await self._t.request("POST", f"/agents/{agent_id}/publish")
88
+
89
+
90
+ class _SkillsResource:
91
+ def __init__(self, transport: SyncTransport) -> None:
92
+ self._t = transport
93
+
94
+ def list(self) -> list[dict[str, Any]]:
95
+ return self._t.request("GET", "/skills")
96
+
97
+ def create(self, spec: dict[str, Any]) -> dict[str, Any]:
98
+ return self._t.request("POST", "/skills", json=spec)
99
+
100
+ def publish(self, skill_id: str) -> dict[str, Any]:
101
+ return self._t.request("POST", f"/skills/{skill_id}/publish")
102
+
103
+
104
+ class _AsyncSkillsResource:
105
+ def __init__(self, transport: AsyncTransport) -> None:
106
+ self._t = transport
107
+
108
+ async def list(self) -> list[dict[str, Any]]:
109
+ return await self._t.request("GET", "/skills")
110
+
111
+ async def create(self, spec: dict[str, Any]) -> dict[str, Any]:
112
+ return await self._t.request("POST", "/skills", json=spec)
113
+
114
+ async def publish(self, skill_id: str) -> dict[str, Any]:
115
+ return await self._t.request("POST", f"/skills/{skill_id}/publish")
116
+
117
+
118
+ class _UsageResource:
119
+ def __init__(self, transport: SyncTransport) -> None:
120
+ self._t = transport
121
+
122
+ def get(self) -> dict[str, Any]:
123
+ return self._t.request("GET", "/usage")
124
+
125
+
126
+ class _AsyncUsageResource:
127
+ def __init__(self, transport: AsyncTransport) -> None:
128
+ self._t = transport
129
+
130
+ async def get(self) -> dict[str, Any]:
131
+ return await self._t.request("GET", "/usage")
132
+
133
+
134
+ class _SuggestionsResource:
135
+ def __init__(self, transport: SyncTransport) -> None:
136
+ self._t = transport
137
+
138
+ def starters(self) -> list[dict[str, Any]]:
139
+ return self._t.request("GET", "/suggestions/starters")
140
+
141
+ def create_for_thread(self, thread_id: str) -> dict[str, Any]:
142
+ return self._t.request("POST", f"/threads/{thread_id}/postturn")
143
+
144
+
145
+ class _AsyncSuggestionsResource:
146
+ def __init__(self, transport: AsyncTransport) -> None:
147
+ self._t = transport
148
+
149
+ async def starters(self) -> list[dict[str, Any]]:
150
+ return await self._t.request("GET", "/suggestions/starters")
151
+
152
+ async def create_for_thread(self, thread_id: str) -> dict[str, Any]:
153
+ return await self._t.request("POST", f"/threads/{thread_id}/postturn")
154
+
155
+
156
+ class AgentPlatformClient:
157
+ """Sync client for the Agent Platform.
158
+
159
+ Usage custom AICE management routes::
160
+
161
+ client = AgentPlatformClient(base_url="…", api_key="sk-…")
162
+ agents = client.agents.list()
163
+
164
+ Usage native LangGraph surface (streaming, threads, runs)::
165
+
166
+ thread = client.threads.create()
167
+ for chunk in client.runs.stream(
168
+ thread["thread_id"], assistant_id="agent", input={"messages": [...]}
169
+ ):
170
+ print(chunk.event, chunk.data)
171
+
172
+ See the module docstring for the important behavioral split between
173
+ these two surfaces (error types, retries, idempotency).
174
+ """
175
+
176
+ def __init__(
177
+ self,
178
+ *,
179
+ base_url: str,
180
+ api_key: str,
181
+ timeout: float = 30.0,
182
+ max_retries: int = 3,
183
+ user_id: str | None = None,
184
+ user_role: str | None = None,
185
+ ) -> None:
186
+ auth = AuthContext(api_key=api_key, user_id=user_id, user_role=user_role)
187
+ auth.require_scope("agent-platform")
188
+ self._t = SyncTransport(
189
+ base_url=base_url,
190
+ auth=auth,
191
+ service=_SERVICE_NAME,
192
+ timeout=timeout,
193
+ max_retries=max_retries,
194
+ )
195
+ self.agents = _AgentsResource(self._t)
196
+ self.skills = _SkillsResource(self._t)
197
+ self.usage = _UsageResource(self._t)
198
+ self.suggestions = _SuggestionsResource(self._t)
199
+
200
+ # Native LangGraph surface composed, not forked. api_key=None so
201
+ # langgraph-sdk doesn't also try LANGSMITH_API_KEY/LANGGRAPH_API_KEY
202
+ # from the environment; our bearer token goes through `headers`
203
+ # instead, matching how the rest of this SDK authenticates.
204
+ self._lg = get_sync_client(
205
+ url=base_url,
206
+ api_key=None,
207
+ headers=auth.as_headers(),
208
+ timeout=timeout,
209
+ )
210
+ self.threads = self._lg.threads
211
+ self.runs = self._lg.runs
212
+ self.assistants = self._lg.assistants
213
+ self.crons = self._lg.crons
214
+
215
+ def close(self) -> None:
216
+ self._t.close()
217
+ # Defensive: langgraph-sdk's sync client manages its own HTTP
218
+ # client lifecycle separately from aice_core's transport. Close it
219
+ # if the installed version exposes a close method; harmless no-op
220
+ # otherwise.
221
+ close_fn = getattr(self._lg, "close", None)
222
+ if callable(close_fn):
223
+ close_fn()
224
+
225
+ def __enter__(self) -> "AgentPlatformClient":
226
+ return self
227
+
228
+ def __exit__(self, *exc: Any) -> None:
229
+ self.close()
230
+
231
+
232
+ class AsyncAgentPlatformClient:
233
+ """Async client for the Agent Platform. See ``AgentPlatformClient`` for
234
+ the sync/streaming usage split this mirrors it with ``await``."""
235
+
236
+ def __init__(
237
+ self,
238
+ *,
239
+ base_url: str,
240
+ api_key: str,
241
+ timeout: float = 30.0,
242
+ max_retries: int = 3,
243
+ user_id: str | None = None,
244
+ user_role: str | None = None,
245
+ ) -> None:
246
+ auth = AuthContext(api_key=api_key, user_id=user_id, user_role=user_role)
247
+ auth.require_scope("agent-platform")
248
+ self._t = AsyncTransport(
249
+ base_url=base_url,
250
+ auth=auth,
251
+ service=_SERVICE_NAME,
252
+ timeout=timeout,
253
+ max_retries=max_retries,
254
+ )
255
+ self.agents = _AsyncAgentsResource(self._t)
256
+ self.skills = _AsyncSkillsResource(self._t)
257
+ self.usage = _AsyncUsageResource(self._t)
258
+ self.suggestions = _AsyncSuggestionsResource(self._t)
259
+
260
+ self._lg = get_client(
261
+ url=base_url,
262
+ api_key=None,
263
+ headers=auth.as_headers(),
264
+ timeout=timeout,
265
+ )
266
+ self.threads = self._lg.threads
267
+ self.runs = self._lg.runs
268
+ self.assistants = self._lg.assistants
269
+ self.crons = self._lg.crons
270
+
271
+ async def aclose(self) -> None:
272
+ await self._t.aclose()
273
+ close_fn = getattr(self._lg, "aclose", None) or getattr(self._lg, "close", None)
274
+ if callable(close_fn):
275
+ result = close_fn()
276
+ if hasattr(result, "__await__"):
277
+ await result
278
+
279
+ async def __aenter__(self) -> "AsyncAgentPlatformClient":
280
+ return self
281
+
282
+ async def __aexit__(self, *exc: Any) -> None:
283
+ await self.aclose()
File without changes
@@ -0,0 +1,87 @@
1
+ Metadata-Version: 2.5
2
+ Name: aice-agent-platform
3
+ Version: 0.2.1
4
+ Summary: Python SDK for the AICE Agent Platform (config-driven LangGraph agent runtime)
5
+ Author-email: Adanian Labs <engineering@adanianlabs.io>
6
+ License: MIT
7
+ Classifier: Development Status :: 4 - Beta
8
+ Classifier: Intended Audience :: Developers
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Typing :: Typed
12
+ Requires-Python: >=3.11
13
+ Requires-Dist: aice-core<0.4,>=0.3.0
14
+ Requires-Dist: langgraph-sdk<0.2,>=0.1.60
15
+ Provides-Extra: dev
16
+ Requires-Dist: pytest-asyncio>=0.24; extra == 'dev'
17
+ Requires-Dist: pytest>=8.3; extra == 'dev'
18
+ Requires-Dist: respx>=0.21; extra == 'dev'
19
+ Description-Content-Type: text/markdown
20
+
21
+ # aice-agent-platform
22
+
23
+ Python SDK for the [Agent Platform](../../../aice_packages/agent_platform/) the
24
+ config-driven LangGraph agent runtime exposed over Aegra's Agent Protocol.
25
+
26
+ This SDK is a composition of two surfaces:
27
+
28
+ 1. **AICE-specific management routes** (`agents`, `skills`, `usage`,
29
+ `suggestions`) go through `aice-core`'s shared transport, so they get
30
+ the usual typed `AiceError` hierarchy, retries, and idempotency-key
31
+ handling.
32
+ 2. **The native LangGraph surface** (`threads`, `runs`, `assistants`,
33
+ `crons`) this service is a LangGraph Platform-compatible deployment,
34
+ so this SDK composes the official
35
+ [`langgraph-sdk`](https://reference.langchain.com/python/langgraph-sdk)
36
+ directly rather than re-implementing it. This is where streaming/run
37
+ execution lives.
38
+
39
+ **These two surfaces do not share error types or retry behavior.**
40
+ `client.threads`/`client.runs`/`client.assistants`/`client.crons` raise
41
+ whatever `langgraph-sdk` itself raises, with its own retry policy never
42
+ `aice_core.AiceError`. `client.agents`/`client.skills`/`client.usage`/
43
+ `client.suggestions` behave like every other AICE SDK. See the docstring at
44
+ the top of `client.py` for the full rationale.
45
+
46
+ ```python
47
+ from aice_agent_platform import AgentPlatformClient
48
+
49
+ client = AgentPlatformClient(base_url="https://agents.example.com", api_key="sk-…")
50
+
51
+ # ── AICE-specific management routes ────────────────────────────────────
52
+
53
+ # List available agents
54
+ agents = client.agents.list()
55
+
56
+ # Publish a saved agent definition so it's runnable
57
+ client.agents.publish("ag_123")
58
+
59
+ # Discover skills
60
+ skills = client.skills.list()
61
+
62
+ # Fetch usage counters for the current project
63
+ usage = client.usage.get()
64
+
65
+ # Trigger the post-turn suggestion engine for a thread
66
+ suggestions = client.suggestions.create_for_thread("th_123")
67
+
68
+ # ── Native LangGraph surface (streaming, threads, runs) ────────────────
69
+
70
+ thread = client.threads.create()
71
+
72
+ for chunk in client.runs.stream(
73
+ thread["thread_id"],
74
+ assistant_id="agent",
75
+ input={"messages": [{"role": "user", "content": "hi"}]},
76
+ ):
77
+ print(chunk.event, chunk.data)
78
+ ```
79
+
80
+ Async variant mirrors this with `AsyncAgentPlatformClient` and `await`/
81
+ `async for`.
82
+
83
+ See the upstream service's own
84
+ [docs/API.md](../../../aice_packages/agent_platform/docs/API.md) for the
85
+ AICE-specific endpoint spec this SDK tracks, and the
86
+ [LangGraph SDK reference](https://reference.langchain.com/python/langgraph-sdk)
87
+ for the native `threads`/`runs`/`assistants`/`crons` surface.
@@ -0,0 +1,6 @@
1
+ aice_agent_platform/__init__.py,sha256=Ln9xhB9xFhlcA2bhgRzD9AHK3lEg0zG800JqItY00k8,233
2
+ aice_agent_platform/client.py,sha256=OKnz5zQd8_Kf2R_oI_mk8Po9wRK04QDCbGpwKlLVI-s,10399
3
+ aice_agent_platform/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
+ aice_agent_platform-0.2.1.dist-info/METADATA,sha256=RSGIcy4l8bxsB2SXibk7k7jzZA1SFRM4y6Evob366pk,3338
5
+ aice_agent_platform-0.2.1.dist-info/WHEEL,sha256=W3fkpkm7-wf9vBI5Z-7s0eWkeM-spu78I8Neb98DeEg,87
6
+ aice_agent_platform-0.2.1.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.32.4
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any