python-durable 0.2.0__py3-none-any.whl → 0.2.2__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.
Potentially problematic release.
This version of python-durable might be problematic. Click here for more details.
- durable/pydantic_ai.py +23 -4
- {python_durable-0.2.0.dist-info → python_durable-0.2.2.dist-info}/METADATA +1 -1
- {python_durable-0.2.0.dist-info → python_durable-0.2.2.dist-info}/RECORD +5 -5
- {python_durable-0.2.0.dist-info → python_durable-0.2.2.dist-info}/WHEEL +0 -0
- {python_durable-0.2.0.dist-info → python_durable-0.2.2.dist-info}/licenses/LICENSE +0 -0
durable/pydantic_ai.py
CHANGED
|
@@ -69,6 +69,20 @@ def _deserialize_messages(data: list[dict]) -> list[Any]:
|
|
|
69
69
|
return result
|
|
70
70
|
|
|
71
71
|
|
|
72
|
+
def _serialize_run_result(result: Any) -> dict:
|
|
73
|
+
"""Convert an agent RunResult to a JSON-serializable dict."""
|
|
74
|
+
output = result.output
|
|
75
|
+
# If output is a pydantic model, convert to dict
|
|
76
|
+
if hasattr(output, "model_dump"):
|
|
77
|
+
output = output.model_dump(mode="json")
|
|
78
|
+
data: dict[str, Any] = {"output": output}
|
|
79
|
+
try:
|
|
80
|
+
data["all_messages"] = _serialize_messages(result.all_messages())
|
|
81
|
+
except Exception:
|
|
82
|
+
data["all_messages"] = []
|
|
83
|
+
return data
|
|
84
|
+
|
|
85
|
+
|
|
72
86
|
def _run_id_for_agent(agent_name: str, prompt: str, run_id: str | None) -> str:
|
|
73
87
|
"""Generate a deterministic run ID from the agent name and prompt."""
|
|
74
88
|
if run_id:
|
|
@@ -207,7 +221,8 @@ class DurableAgent(Generic[AgentDepsT, OutputT]):
|
|
|
207
221
|
step_id="agent-run",
|
|
208
222
|
**kwargs,
|
|
209
223
|
)
|
|
210
|
-
|
|
224
|
+
output_type = getattr(self.agent, "_output_type", None)
|
|
225
|
+
return _AgentRunResult(result, output_type=output_type)
|
|
211
226
|
|
|
212
227
|
async def _do_model_request(
|
|
213
228
|
self,
|
|
@@ -225,7 +240,7 @@ class DurableAgent(Generic[AgentDepsT, OutputT]):
|
|
|
225
240
|
run_kwargs.update(kwargs)
|
|
226
241
|
|
|
227
242
|
result = await self.agent.run(prompt, **run_kwargs)
|
|
228
|
-
return
|
|
243
|
+
return _serialize_run_result(result)
|
|
229
244
|
|
|
230
245
|
async def _do_tool_call(
|
|
231
246
|
self,
|
|
@@ -268,15 +283,19 @@ class _AgentRunResult:
|
|
|
268
283
|
"""Wrapper that holds an agent RunResult and handles both live and
|
|
269
284
|
deserialized (dict) results transparently."""
|
|
270
285
|
|
|
271
|
-
def __init__(self, result: Any) -> None:
|
|
286
|
+
def __init__(self, result: Any, output_type: type | None = None) -> None:
|
|
272
287
|
self._result = result
|
|
288
|
+
self._output_type = output_type
|
|
273
289
|
|
|
274
290
|
@property
|
|
275
291
|
def output(self) -> Any:
|
|
276
292
|
if hasattr(self._result, "output"):
|
|
277
293
|
return self._result.output
|
|
278
294
|
if isinstance(self._result, dict):
|
|
279
|
-
|
|
295
|
+
raw = self._result.get("output")
|
|
296
|
+
if isinstance(raw, dict) and self._output_type and hasattr(self._output_type, "model_validate"):
|
|
297
|
+
return self._output_type.model_validate(raw)
|
|
298
|
+
return raw
|
|
280
299
|
return self._result
|
|
281
300
|
|
|
282
301
|
@property
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: python-durable
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.2
|
|
4
4
|
Summary: Lightweight workflow durability for Python — make any async workflow resumable after crashes with just a decorator.
|
|
5
5
|
Project-URL: Repository, https://github.com/WillemDeGroef/python-durable
|
|
6
6
|
Author: Willem
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
durable/__init__.py,sha256=CMNNJpWOyJHDKK9H2UidatvyDAb76UR4sbhEKIpBOCQ,2187
|
|
2
2
|
durable/backoff.py,sha256=o5p3hXfJ1YMwmEzjzukqW6inYezYGYnEi3_1YwnmDcU,1056
|
|
3
3
|
durable/context.py,sha256=greEK4jRz9RmVc5kHlmBjU3fisrsl2RCDDtGUPEiQM4,1324
|
|
4
|
-
durable/pydantic_ai.py,sha256=
|
|
4
|
+
durable/pydantic_ai.py,sha256=FM1P_Ss6_z-ATdVsQNTj_rGKQqiVT7qu88-_yfyRuQ8,10621
|
|
5
5
|
durable/redis_store.py,sha256=ShzNblDOoxTm5rEonbcwotEZmfZ8DYrCfx-7fMTUxAE,3536
|
|
6
6
|
durable/store.py,sha256=YvrVNFzYQGSlLR-TKnXS0b1tJzpY5zr_tkkKDH5sR1k,8769
|
|
7
7
|
durable/workflow.py,sha256=Q0boxwnquNJMueE8LeRlWg8yLxFr6m1I6RzOO3kmdB8,13192
|
|
8
|
-
python_durable-0.2.
|
|
9
|
-
python_durable-0.2.
|
|
10
|
-
python_durable-0.2.
|
|
11
|
-
python_durable-0.2.
|
|
8
|
+
python_durable-0.2.2.dist-info/METADATA,sha256=kmlOxo_kT7J4FlerHqd9UZW7_w-l4u8pVmO1I8XQTBs,10029
|
|
9
|
+
python_durable-0.2.2.dist-info/WHEEL,sha256=QccIxa26bgl1E6uMy58deGWi-0aeIkkangHcxk2kWfw,87
|
|
10
|
+
python_durable-0.2.2.dist-info/licenses/LICENSE,sha256=S5JKY7biEEYA0tC7Qr2hO-ppopDVnD8muKbaviRFqLk,1084
|
|
11
|
+
python_durable-0.2.2.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|