penguiflow 1.0.2__py3-none-any.whl → 1.0.3__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 penguiflow might be problematic. Click here for more details.

penguiflow/__init__.py CHANGED
@@ -15,6 +15,7 @@ from .node import Node, NodePolicy
15
15
  from .patterns import join_k, map_concurrent, predicate_router, union_router
16
16
  from .registry import ModelRegistry
17
17
  from .types import WM, FinalAnswer, Headers, Message, PlanStep, Thought
18
+ from .viz import flow_to_mermaid
18
19
 
19
20
  __all__ = [
20
21
  "__version__",
@@ -37,7 +38,8 @@ __all__ = [
37
38
  "join_k",
38
39
  "predicate_router",
39
40
  "union_router",
41
+ "flow_to_mermaid",
40
42
  "create",
41
43
  ]
42
44
 
43
- __version__ = "1.0.2"
45
+ __version__ = "1.0.3"
penguiflow/viz.py CHANGED
@@ -2,4 +2,75 @@
2
2
 
3
3
  from __future__ import annotations
4
4
 
5
- __all__: list[str] = []
5
+ import re
6
+ from typing import TYPE_CHECKING
7
+
8
+ from .core import Endpoint
9
+ from .node import Node
10
+
11
+ if TYPE_CHECKING: # pragma: no cover - type checking only
12
+ from .core import PenguiFlow
13
+
14
+ __all__ = ["flow_to_mermaid"]
15
+
16
+
17
+ def flow_to_mermaid(flow: PenguiFlow, *, direction: str = "TD") -> str:
18
+ """Render the flow graph as a Mermaid diagram string.
19
+
20
+ Parameters
21
+ ----------
22
+ flow:
23
+ The `PenguiFlow` instance to visualize.
24
+ direction:
25
+ Mermaid graph direction ("TD", "LR", etc.). Defaults to top-down.
26
+ """
27
+
28
+ lines: list[str] = [f"graph {direction}"]
29
+ nodes: set[object] = set()
30
+
31
+ for floe in flow._floes: # noqa: SLF001 - visualization accesses internals by design
32
+ if floe.source is not None:
33
+ nodes.add(floe.source)
34
+ if floe.target is not None:
35
+ nodes.add(floe.target)
36
+
37
+ id_lookup: dict[object, str] = {}
38
+ used_ids: set[str] = set()
39
+
40
+ for entity in nodes:
41
+ label = _display_label(entity)
42
+ node_id = _unique_id(label, used_ids)
43
+ used_ids.add(node_id)
44
+ id_lookup[entity] = node_id
45
+ lines.append(f" {node_id}[\"{label}\"]")
46
+
47
+ for floe in flow._floes: # noqa: SLF001
48
+ source = floe.source
49
+ target = floe.target
50
+ if source is None or target is None:
51
+ continue
52
+ src_id = id_lookup.get(source)
53
+ tgt_id = id_lookup.get(target)
54
+ if src_id is None or tgt_id is None:
55
+ continue
56
+ lines.append(f" {src_id} --> {tgt_id}")
57
+
58
+ return "\n".join(lines)
59
+
60
+
61
+ def _display_label(entity: object) -> str:
62
+ if isinstance(entity, Node):
63
+ return entity.name or entity.node_id
64
+ if isinstance(entity, Endpoint):
65
+ return entity.name
66
+ return str(entity)
67
+
68
+
69
+ def _unique_id(label: str, used: set[str]) -> str:
70
+ base = re.sub(r"[^0-9A-Za-z_]", "_", label) or "node"
71
+ candidate = base
72
+ index = 1
73
+ while candidate in used:
74
+ index += 1
75
+ candidate = f"{base}_{index}"
76
+ return candidate
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: penguiflow
3
- Version: 1.0.2
3
+ Version: 1.0.3
4
4
  Summary: Async agent orchestration primitives.
5
5
  Author: PenguiFlow Team
6
6
  License: MIT License
@@ -99,7 +99,7 @@ from penguiflow.node import Node
99
99
  class QueryOut(BaseModel):
100
100
  topic: str
101
101
 
102
- async def triage(m: QueryIn) -> QueryOut:
102
+ async def triage(msg: QueryIn, ctx) -> QueryOut:
103
103
  return QueryOut(topic="metrics")
104
104
 
105
105
  triage_node = Node(triage, name="triage")
@@ -328,6 +328,19 @@ flow focused on high-level orchestration logic.
328
328
 
329
329
  ---
330
330
 
331
+ ### Visualization
332
+
333
+ Need a quick view of the flow topology? Call `flow_to_mermaid(flow)` to render the graph
334
+ as a Mermaid diagram ready for Markdown or docs tools:
335
+
336
+ ```python
337
+ from penguiflow import flow_to_mermaid
338
+
339
+ print(flow_to_mermaid(flow, direction="LR"))
340
+ ```
341
+
342
+ ---
343
+
331
344
  ## 🛡️ Reliability & Observability
332
345
 
333
346
  * **NodePolicy**: set validation scope plus per-node timeout, retries, and backoff curves.
@@ -346,6 +359,14 @@ flow focused on high-level orchestration logic.
346
359
 
347
360
  ---
348
361
 
362
+ ## 📊 Benchmarks
363
+
364
+ Lightweight benchmarks live under `benchmarks/`. Run them via `uv run python benchmarks/<name>.py`
365
+ to capture baselines for fan-out throughput, retry/timeout overhead, and controller
366
+ playbook latency. Copy them into product repos to watch for regressions over time.
367
+
368
+ ---
369
+
349
370
  ## 🔮 Roadmap
350
371
 
351
372
  * **v1 (current)**: safe core runtime, type-safety, retries, timeouts, routing, controller loops, playbooks via examples.
@@ -1,13 +1,13 @@
1
- penguiflow/__init__.py,sha256=BIBAYJZtOHQ7AZMBWD0g7d1RTCR9qWLQGwcUuKa5GMo,874
1
+ penguiflow/__init__.py,sha256=fiQsp6-xYG2UjvuIhu71zvEiTeAjdfEjtoLRwZ8wROs,930
2
2
  penguiflow/core.py,sha256=fO5GXF7Hih-gEcUPbyXVJilgUmwbvd72j337r5oOWME,20908
3
3
  penguiflow/middlewares.py,sha256=LUlK4FrMScK3oaNSrAYNw3s4KcAZ716DTLAUqvsOkL8,319
4
4
  penguiflow/node.py,sha256=0NOs3rU6t1tHNNwwJopqzM2ufGcp82JpzhckynWBRqs,3563
5
5
  penguiflow/patterns.py,sha256=Ivuuy0on0OMsdYd5DRFZm1EgujXKPEaIIMH0ZWlJ1s0,4199
6
6
  penguiflow/registry.py,sha256=4lrGDMFjM7c8pfZFc_YG0YHg-F80JyF4c-j0UbAf150,1419
7
7
  penguiflow/types.py,sha256=QV2JvB_QnohfBATSaviPWm0HSR9B6dTc3UOwFIYyaqg,1154
8
- penguiflow/viz.py,sha256=_puIEJevq2DrfNuydm3DG1V1o4PgICxd5pA-Es_IyWY,112
9
- penguiflow-1.0.2.dist-info/licenses/LICENSE,sha256=JSvodvLXxSct_kI9IBsZOBpVKoESQTB_AGbkClwZ7HI,1065
10
- penguiflow-1.0.2.dist-info/METADATA,sha256=SBuhdqSVKIwo9_vVV2bW2IsmGiia84q59ESqHl8zgR0,13090
11
- penguiflow-1.0.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
12
- penguiflow-1.0.2.dist-info/top_level.txt,sha256=F-5jgzPP4Mo_ErgtzGDFJdRT4CIfFjFBnxxcn-RpWBU,11
13
- penguiflow-1.0.2.dist-info/RECORD,,
8
+ penguiflow/viz.py,sha256=B9T2O5A6nHBLn7JuEeujqDC6ZcwP5s6M2rpsUrj5Ul0,2091
9
+ penguiflow-1.0.3.dist-info/licenses/LICENSE,sha256=JSvodvLXxSct_kI9IBsZOBpVKoESQTB_AGbkClwZ7HI,1065
10
+ penguiflow-1.0.3.dist-info/METADATA,sha256=GISwzSiycpzXy0kmoP3mWeMAeutgNITeTKVGz2YRb1A,13658
11
+ penguiflow-1.0.3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
12
+ penguiflow-1.0.3.dist-info/top_level.txt,sha256=F-5jgzPP4Mo_ErgtzGDFJdRT4CIfFjFBnxxcn-RpWBU,11
13
+ penguiflow-1.0.3.dist-info/RECORD,,