agentkit-sdk-python 0.7.5__py3-none-any.whl → 0.7.6__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.
@@ -3,6 +3,7 @@
3
3
  from __future__ import annotations
4
4
 
5
5
  from collections.abc import AsyncGenerator
6
+ import hashlib
6
7
  import inspect
7
8
  import json
8
9
  from typing import Any
@@ -141,7 +142,15 @@ class LangGraphAgentkitBridge(BaseAgent):
141
142
  session_id = getattr(session, "id", None)
142
143
  if not session_id:
143
144
  return None
144
- return {"configurable": {"thread_id": session_id}}
145
+ app_name = getattr(session, "app_name", None)
146
+ user_id = getattr(session, "user_id", None)
147
+ if app_name and user_id:
148
+ raw_identity = f"{app_name}\0{user_id}\0{session_id}"
149
+ digest = hashlib.sha256(raw_identity.encode("utf-8")).hexdigest()
150
+ thread_id = f"agentkit:{digest}"
151
+ else:
152
+ thread_id = session_id
153
+ return {"configurable": {"thread_id": thread_id}}
145
154
 
146
155
  def _pending_interrupt(self, ctx: InvocationContext) -> Any | None:
147
156
  session = getattr(ctx, "session", None)
@@ -218,32 +227,37 @@ class LangGraphAgentkitBridge(BaseAgent):
218
227
  stream_fn = getattr(self._graph, "stream", None)
219
228
  if not callable(stream_fn):
220
229
  return None
221
- try:
222
- return stream_fn(
223
- payload,
224
- **_method_kwargs(
225
- stream_fn,
226
- {
227
- "config": config,
228
- "stream_mode": ["messages", "updates"],
229
- "version": "v2",
230
- },
231
- ),
232
- )
233
- except TypeError:
234
- try:
235
- return stream_fn(
236
- payload,
237
- **_method_kwargs(
238
- stream_fn,
239
- {
240
- "config": config,
241
- "stream_mode": ["messages", "updates"],
242
- },
243
- ),
244
- )
245
- except TypeError:
246
- return stream_fn(payload, **_method_kwargs(stream_fn, {"config": config}))
230
+ attempts = [
231
+ {
232
+ "config": config,
233
+ "stream_mode": ["messages", "updates"],
234
+ "version": "v2",
235
+ },
236
+ {
237
+ "config": config,
238
+ "stream_mode": ["messages", "updates"],
239
+ },
240
+ {"config": config},
241
+ ]
242
+
243
+ def iterate_attempts():
244
+ last_error: TypeError | None = None
245
+ for kwargs in attempts:
246
+ emitted = False
247
+ try:
248
+ stream = stream_fn(payload, **_method_kwargs(stream_fn, kwargs))
249
+ for item in stream:
250
+ emitted = True
251
+ yield item
252
+ return
253
+ except TypeError as exc:
254
+ if emitted:
255
+ raise
256
+ last_error = exc
257
+ if last_error is not None:
258
+ raise last_error
259
+
260
+ return iterate_attempts()
247
261
 
248
262
  async def _stream_graph(self, payload: Any, config: dict[str, Any] | None, *, prefer_sync: bool = False):
249
263
  if prefer_sync:
@@ -255,35 +269,33 @@ class LangGraphAgentkitBridge(BaseAgent):
255
269
 
256
270
  astream = getattr(self._graph, "astream", None)
257
271
  if callable(astream):
258
- try:
259
- stream = astream(
260
- payload,
261
- **_method_kwargs(
262
- astream,
263
- {
264
- "config": config,
265
- "stream_mode": ["messages", "updates"],
266
- "version": "v2",
267
- },
268
- ),
269
- )
270
- except TypeError:
272
+ attempts = [
273
+ {
274
+ "config": config,
275
+ "stream_mode": ["messages", "updates"],
276
+ "version": "v2",
277
+ },
278
+ {
279
+ "config": config,
280
+ "stream_mode": ["messages", "updates"],
281
+ },
282
+ {"config": config},
283
+ ]
284
+ last_error: TypeError | None = None
285
+ for kwargs in attempts:
286
+ emitted = False
271
287
  try:
272
- stream = astream(
273
- payload,
274
- **_method_kwargs(
275
- astream,
276
- {
277
- "config": config,
278
- "stream_mode": ["messages", "updates"],
279
- },
280
- ),
281
- )
282
- except TypeError:
283
- stream = astream(payload, **_method_kwargs(astream, {"config": config}))
284
- async for item in stream:
285
- yield item
286
- return
288
+ stream = astream(payload, **_method_kwargs(astream, kwargs))
289
+ async for item in stream:
290
+ emitted = True
291
+ yield item
292
+ return
293
+ except TypeError as exc:
294
+ if emitted:
295
+ raise
296
+ last_error = exc
297
+ if last_error is not None:
298
+ raise last_error
287
299
 
288
300
  stream = self._sync_stream(payload, config)
289
301
  if stream is not None:
@@ -4,6 +4,7 @@ from __future__ import annotations
4
4
 
5
5
  import importlib
6
6
  import importlib.util
7
+ import inspect
7
8
  from pathlib import Path
8
9
  import sys
9
10
  from types import ModuleType
@@ -55,6 +56,50 @@ def _resolve_object(module: ModuleType, object_path: str) -> Any:
55
56
  return target
56
57
 
57
58
 
59
+ def _call_zero_arg_factory(target: Any, object_path: str) -> Any:
60
+ if not callable(target):
61
+ raise TypeError(
62
+ f"Entry object {object_path!r} was marked as a factory, "
63
+ "but the loaded object is not callable."
64
+ )
65
+
66
+ try:
67
+ signature = inspect.signature(target)
68
+ except (TypeError, ValueError) as exc:
69
+ raise TypeError(
70
+ f"Entry factory {object_path!r} has no inspectable signature. "
71
+ "Expose a zero-argument factory or a constructed agent object."
72
+ ) from exc
73
+
74
+ required_params = [
75
+ name
76
+ for name, param in signature.parameters.items()
77
+ if param.default is inspect.Parameter.empty
78
+ and param.kind
79
+ in {
80
+ inspect.Parameter.POSITIONAL_ONLY,
81
+ inspect.Parameter.POSITIONAL_OR_KEYWORD,
82
+ inspect.Parameter.KEYWORD_ONLY,
83
+ }
84
+ ]
85
+ if required_params:
86
+ formatted = ", ".join(required_params)
87
+ raise TypeError(
88
+ f"Entry factory {object_path!r} requires arguments: {formatted}. "
89
+ "agentkit migrate can only call zero-argument factories; expose a "
90
+ "thin zero-argument entry object for migration."
91
+ )
92
+
93
+ result = target()
94
+ if inspect.isawaitable(result):
95
+ raise TypeError(
96
+ f"Entry factory {object_path!r} returned an awaitable object. "
97
+ "Async factories are not supported by generated migration apps; "
98
+ "expose a synchronous factory or a constructed agent object."
99
+ )
100
+ return result
101
+
102
+
58
103
  def load_entry_object(
59
104
  *,
60
105
  file: str,
@@ -63,6 +108,7 @@ def load_entry_object(
63
108
  project_root: str | Path = ".",
64
109
  base_dir: str | Path | None = None,
65
110
  import_name: str = "agentkit_migrated_entry",
111
+ call_factory: bool = False,
66
112
  ) -> Any:
67
113
  """Load an object from a migrated project's original entry reference.
68
114
 
@@ -83,4 +129,7 @@ def load_entry_object(
83
129
  entry_path = (base_path / file).resolve()
84
130
  loaded_module = _load_module_from_file(entry_path, import_name)
85
131
 
86
- return _resolve_object(loaded_module, object_path)
132
+ target = _resolve_object(loaded_module, object_path)
133
+ if call_factory:
134
+ return _call_zero_arg_factory(target, object_path)
135
+ return target
agentkit/version.py CHANGED
@@ -12,4 +12,4 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
 
15
- VERSION = "0.7.5"
15
+ VERSION = "0.7.6"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: agentkit-sdk-python
3
- Version: 0.7.5
3
+ Version: 0.7.6
4
4
  Summary: Python SDK for transforming any AI agent into a production-ready application. Framework-agnostic primitives for runtime, memory, authentication, and tools with volcengine-managed infrastructure.
5
5
  Author-email: Xiangrui Cheng <innsdcc@gmail.com>, Yumeng Bao <baoyumeng.123@gmail.com>, Yaozheng Fang <fangyozheng@gmail.com>, Guodong Li <cu.eric.lee@gmail.com>
6
6
  License: Apache License
@@ -1,6 +1,6 @@
1
1
  agentkit/__init__.py,sha256=l27ZMDslc3VhmmnPZJyrqVvTDoZ0LqhCtM5hw0caHcU,1021
2
2
  agentkit/errors.py,sha256=UWlXv0ZsXd_oLTMlxuf4u9-XkTdRYeVZueE--Z3JsHU,1214
3
- agentkit/version.py,sha256=jdEhJm4AO9pEv0qL-YVddyFb51tMohK9OaZmnNwBxME,653
3
+ agentkit/version.py,sha256=oFLDChAr94DBKT7M7QxgZ_7Ypdo7s4CRVCDwIb-kkCk,653
4
4
  agentkit/apps/__init__.py,sha256=-oXTjxV3gejpJ8pffTUcUAXw0LfxKCYZJk-_hIJhtLM,1921
5
5
  agentkit/apps/base_app.py,sha256=3hZZExL1wyTGWveJEZZoqXN086MzmkVS_WU1vyulIWg,754
6
6
  agentkit/apps/utils.py,sha256=IzimIDmT6FS6PV9MLimPh46mq5zT-EjVmnYPxBdyEq0,1934
@@ -43,8 +43,8 @@ agentkit/client/base_service_client.py,sha256=zpPUidGMDRAMDnSVjrX7BwuOp4BQdAEk0b
43
43
  agentkit/frameworks/__init__.py,sha256=cfUdMeixph0xAo6B5qGQBBdm8LeQbWZIl1vmO9cEL3E,971
44
44
  agentkit/frameworks/_common.py,sha256=0L0cyBQxtlOdi3GbQ_UgaOoHWwenztlKrxUsyvV3hXw,3859
45
45
  agentkit/frameworks/langchain.py,sha256=Tcy2HGYqKmcugDSn3OMaD_6uxhsJtZI3o5E8Rw7UJrg,5947
46
- agentkit/frameworks/langgraph.py,sha256=maa-igm302-PhMAJB3yMJhRfZMuRgKrs0wmV-uCSlGc,13788
47
- agentkit/frameworks/migration.py,sha256=cDXu3FqbmCUEx3uGtN-atkC6pnICaEb9FboJdekpBek,2680
46
+ agentkit/frameworks/langgraph.py,sha256=FX8QHjfS4QHSTGq4oYwQ7MytrUejDFmVczihNPCts4A,14201
47
+ agentkit/frameworks/migration.py,sha256=j8MxFvAFKkDsTy_e1l5bN-B276AE7rwxLrHuBodNcfc,4385
48
48
  agentkit/frameworks/serving/__init__.py,sha256=EaR0jzP6np8v1gyD6CYlaRoIY1KgBaFosqCmRUgMc2E,302
49
49
  agentkit/frameworks/serving/fastapi_mount.py,sha256=LV6gJunwd7aU8MFdDYSxeaIUYWvYwMl2Am1J07ddP0A,1958
50
50
  agentkit/frameworks/serving/langserve.py,sha256=R2R0g95LHcSFJ1BnOm2cxnULv3wQaZNUdm5Aqd-Oq5s,17238
@@ -241,9 +241,9 @@ agentkit/utils/redact.py,sha256=RAtiggxH74eb1Da6Gg0G5SLTVWRaIE5RqYnCozSZozQ,2167
241
241
  agentkit/utils/request.py,sha256=1IGxPS3BSCKk1K1_j862_v34xzLEx04CIvrLVb1MsGQ,1625
242
242
  agentkit/utils/template_utils.py,sha256=Qjg9V6dEpjAd_yYezIIPwuDsDeeMmp6XTMn5ZECifNc,6336
243
243
  agentkit/utils/ve_sign.py,sha256=JfKig7zni8KvdhgbLJXm3Zy_ttyzKrYGUmBY_82_A4Q,12762
244
- agentkit_sdk_python-0.7.5.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
245
- agentkit_sdk_python-0.7.5.dist-info/METADATA,sha256=fT7Oz5J_Xywf4oDXInVpG6kdlLOhRrNUVxmlgKTLGWg,21144
246
- agentkit_sdk_python-0.7.5.dist-info/WHEEL,sha256=K260EYznzXsJYBQGqmI8VTxEdiZYNvDZwW9cBh9-_MA,91
247
- agentkit_sdk_python-0.7.5.dist-info/entry_points.txt,sha256=fhzZUsvsLXeB4mPaa0SBQiTBqFT404uDAKPaePAOUAE,58
248
- agentkit_sdk_python-0.7.5.dist-info/top_level.txt,sha256=ipy8JF-QQ-V0C1oRFLxsyaW8zwrasfJ-zjAh9vgOc7U,9
249
- agentkit_sdk_python-0.7.5.dist-info/RECORD,,
244
+ agentkit_sdk_python-0.7.6.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
245
+ agentkit_sdk_python-0.7.6.dist-info/METADATA,sha256=qyc849JYVuXgxK90Hcc_20C9n8xCerH5S8Z9WnV8ReU,21144
246
+ agentkit_sdk_python-0.7.6.dist-info/WHEEL,sha256=K260EYznzXsJYBQGqmI8VTxEdiZYNvDZwW9cBh9-_MA,91
247
+ agentkit_sdk_python-0.7.6.dist-info/entry_points.txt,sha256=fhzZUsvsLXeB4mPaa0SBQiTBqFT404uDAKPaePAOUAE,58
248
+ agentkit_sdk_python-0.7.6.dist-info/top_level.txt,sha256=ipy8JF-QQ-V0C1oRFLxsyaW8zwrasfJ-zjAh9vgOc7U,9
249
+ agentkit_sdk_python-0.7.6.dist-info/RECORD,,