loom-workflow 0.3.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,21 @@
1
+ """Contracts for checking graphs against graph schemas."""
2
+
3
+ from ..core import Contract, ContractResult, Result
4
+ from .schema import GraphSchema
5
+
6
+
7
+ class GraphSchemaContract(Contract):
8
+ """Accept results whose output is valid for one :class:`GraphSchema`."""
9
+
10
+ def __init__(self, schema: GraphSchema, *, name: str | None = None):
11
+ super().__init__(name=name or f"valid-{schema.name}")
12
+ self.schema = schema
13
+
14
+ def evaluate(self, result: Result) -> ContractResult:
15
+ report = self.schema.validate(result.output)
16
+ return ContractResult(
17
+ passed=report.ok,
18
+ output=result.output,
19
+ failures=[str(issue) for issue in report.errors],
20
+ metrics={"errors": len(report.errors), "issues": len(report.issues)},
21
+ )
@@ -0,0 +1,221 @@
1
+ Metadata-Version: 2.4
2
+ Name: loom-workflow
3
+ Version: 0.3.0
4
+ Summary: Task orchestration, contracts
5
+ Requires-Python: >=3.10
6
+ Description-Content-Type: text/markdown
7
+ Requires-Dist: pydantic>=2
8
+ Requires-Dist: pydantic-ai>=1
9
+
10
+ # Loom
11
+
12
+ Loom provides small, domain-neutral building blocks for executing Tasks,
13
+ composing them in Pipelines, and verifying their results with Contracts. It is
14
+ designed to keep an AI-generated Task bounded and independently verifiable.
15
+
16
+ Graph-IR support currently lives in `loom.graphite`. It is intentionally
17
+ separate from the orchestration core and can later move to Graphite without
18
+ affecting users of `loom.core`, such as Artisan.
19
+
20
+ ## Architecture
21
+
22
+ ```text
23
+ AI-generated or human-written Task
24
+ |
25
+ v
26
+ TaskResult
27
+ |
28
+ v
29
+ Pipeline composes Tasks and returns PipelineResult
30
+ |
31
+ v
32
+ Verifier evaluates Contracts for the selected result
33
+ ```
34
+
35
+ `TaskResult` and `PipelineResult` both extend `Result`. A Contract evaluates
36
+ the explicit result supplied to it; it does not own or run a Pipeline.
37
+
38
+ ## Core API
39
+
40
+ ```python
41
+ from loom.core import (
42
+ Contract,
43
+ ContractResult,
44
+ Pipeline,
45
+ PipelineResult,
46
+ Result,
47
+ Task,
48
+ TaskResult,
49
+ Verifier,
50
+ )
51
+ ```
52
+
53
+ A Task is the smallest executable unit of domain work:
54
+
55
+ ```python
56
+ class NormalizeTask(Task):
57
+ def __init__(self):
58
+ super().__init__(name="normalize")
59
+
60
+ def execute(self, artifact) -> TaskResult:
61
+ changed = normalize(artifact)
62
+ return TaskResult(output=artifact, modified=changed)
63
+ ```
64
+
65
+ A Pipeline owns sequencing, branching, and fixed-point repetition. The default
66
+ iteration limit is configured in its constructor and can be overridden for one
67
+ call to `repeat()`.
68
+
69
+ ```python
70
+ class CompilerPipeline(Pipeline):
71
+ def __init__(self, lower_task):
72
+ super().__init__(name="compile", max_iterations=1000)
73
+ self.lower_task = lower_task
74
+
75
+ def execute(self, graph) -> PipelineResult:
76
+ lower_result = self.repeat(self.lower_task, graph)
77
+ return PipelineResult(
78
+ output=graph,
79
+ modified=lower_result.modified,
80
+ task_results={"lower": lower_result},
81
+ )
82
+ ```
83
+
84
+ `repeat()` stops when its Task returns `modified=False`. Its result metadata
85
+ records the iteration count and whether it converged.
86
+
87
+ ## Contracts and verification
88
+
89
+ Contracts judge a result after a Task or Pipeline has executed. A caller can
90
+ invoke a Verifier explicitly, or a domain-specific Pipeline can do so as part
91
+ of its own orchestration. Contracts can validate an AI-generated Task directly,
92
+ a whole Pipeline result, or a selected Task result from a Pipeline result.
93
+
94
+ ```python
95
+ task_result = candidate_task.execute(input)
96
+ checks = Verifier([candidate_contract]).verify(task_result)
97
+
98
+ pipeline_result = pipeline.execute(input)
99
+ checks = Verifier([end_to_end_contract]).verify(pipeline_result)
100
+ checks = Verifier([candidate_contract]).verify(
101
+ pipeline_result.task_results["candidate"]
102
+ )
103
+ ```
104
+
105
+ A Contract implements `evaluate(result: Result) -> ContractResult`. The
106
+ Verifier keeps all normal failures so they can be used as feedback for the next
107
+ agent revision.
108
+
109
+ ## Graphite support
110
+
111
+ `loom.graphite` provides the current Heterograph-specific implementation:
112
+
113
+ ```python
114
+ from loom.graphite import (
115
+ DfsMatchStrategy,
116
+ GraphProcessor,
117
+ GraphSchema,
118
+ GraphSchemaContract,
119
+ IsoMatchStrategy,
120
+ )
121
+ ```
122
+
123
+ - `GraphProcessor` matches AQL patterns and performs in-place graph rewrites.
124
+ - `GraphSchema` defines and validates typed Heterograph IRs.
125
+ - `GraphSchemaContract` validates the output of any `Result` against a graph
126
+ schema.
127
+
128
+ For example:
129
+
130
+ ```python
131
+ processor = GraphProcessor(snapshot=False)
132
+ result = processor.run(
133
+ graph,
134
+ select="a => b => c",
135
+ rewrite="a => c",
136
+ )
137
+ ```
138
+
139
+ Graphite Tasks call `GraphProcessor` directly. Loom core does not define an
140
+ Action abstraction and does not require a graph or an IR.
141
+
142
+ ## Agent workflow
143
+
144
+ `loom.agent` provides a restricted interface for an external agent to develop
145
+ and revise selected Task implementations. The agent receives an
146
+ `AgentContext`, which exposes the pipeline runner, the names of editable tasks,
147
+ and their forge locations. It does not receive the pipeline implementation or
148
+ the human-written contracts.
149
+
150
+ ```python
151
+ from pathlib import Path
152
+
153
+ from loom.agent import AgentLoop, PipelineRunner
154
+
155
+ runner = PipelineRunner(
156
+ LoweringPipeline,
157
+ editable_tasks={"lower-dense"},
158
+ forge={
159
+ "lower-dense": Path("examples/agent/forge/lower_dense_task.py"),
160
+ },
161
+ )
162
+ result = AgentLoop(runner).run(input_value, agent)
163
+ ```
164
+
165
+ The pipeline merges its builtin task factories with the agent-provided
166
+ factories. Only the explicitly editable task slots can be replaced. Each
167
+ attempt loads the candidate task from the forge and executes the unchanged
168
+ pipeline and contracts.
169
+
170
+ Task exceptions are passed to the agent as normal exceptions. Contract
171
+ failures are raised by `Verifier` as `ContractException`, carrying the
172
+ execution result and contract results. An agent can use this feedback to
173
+ revise the forged task and retry until the contracts pass or the loop reaches
174
+ its attempt limit.
175
+
176
+ The lowering integration example is in `examples/agent`. Its forge currently
177
+ contains an intentionally disabled OP-IR update so the contract-failure path
178
+ can be exercised; uncomment those lines to restore the successful task.
179
+
180
+ ### Pydantic AI task generation
181
+
182
+ Select a provider, model, and the task names that `TaskGen` may revise:
183
+
184
+ ```bash
185
+ pip install loom-workflow
186
+ ```
187
+
188
+ ```python
189
+ from loom.agent import PydanticAIProvider, TaskGen
190
+
191
+ agent = TaskGen(
192
+ provider=PydanticAIProvider(provider="openai", model="gpt-5.6-sol"),
193
+ tasks={"lower-dense"},
194
+ )
195
+ result = AgentLoop(runner).run(input_value, agent)
196
+ ```
197
+
198
+ `TaskGen` sends only the selected forge module and execution feedback to its
199
+ provider. It writes the returned replacement module into that forge path and
200
+ returns a factory for the next pipeline attempt. `PydanticAIProvider` owns the
201
+ provider-specific model routing; another backend can implement `Provider`
202
+ without changing `TaskGen`.
203
+
204
+ ## Examples
205
+
206
+ Loom requires Python 3.10+ and Heterograph for the Graphite examples. Create
207
+ the supplied environment:
208
+
209
+ ```bash
210
+ conda env create -f examples/environment.yml
211
+ conda activate loom-examples
212
+ ```
213
+
214
+ Run the examples from the repository root:
215
+
216
+ ```bash
217
+ python examples/validation/main.py
218
+ python examples/processor_tests/main.py
219
+ python examples/lowering/main.py
220
+ python examples/agent/main.py
221
+ ```
@@ -0,0 +1,20 @@
1
+ loom/__init__.py,sha256=vj0KQu4J34O4vYzrSyYu72cRFVzwgVKLJ7uupnFwjQs,414
2
+ loom/agent/__init__.py,sha256=GIrHJ0oFOiRyL1jRzm8wVfpop8VT_XfcckCsRx66ytc,420
3
+ loom/agent/loop.py,sha256=BHie-RQUdEkknqyXsxlqi_GRIXqsKzMiarRelw8hCm4,4728
4
+ loom/agent/provider.py,sha256=4ide-oTiW6rez3EL0ERPG1bt8bOIiqX0xKl_3UxSOi8,2452
5
+ loom/agent/task_gen.py,sha256=Vk9tLZlHBgW2GOXjBqEXXZxGkpmMAFXx9SpMk2j4_E8,4282
6
+ loom/core/__init__.py,sha256=f74CTfUSy-gIvAzSzpcrnxsCcFLS_yyLD2xEYtPqJCE,420
7
+ loom/core/contract.py,sha256=fOTsMHMJTbw7Iiev-iUv5XFe2vyOGkA0qIC1kaCKBbE,3481
8
+ loom/core/pipeline.py,sha256=mbxMJ_yA9UD3Bmfvh8p9Z01aUtLNCC_Io7ZuLpvhbZA,4375
9
+ loom/core/result.py,sha256=7Em1vhPEKFNqh6uAppSNlVFKAQTHnvO7Tm9r1_0Yz-4,1165
10
+ loom/core/task.py,sha256=yPGvPkdixvPCqb7OChKKqq10wvj0Bhoep3E3Gx1GHcg,1023
11
+ loom/graphite/__init__.py,sha256=QgHFXHgLUcNL1naaKsVDouRnl039pK55w_qF0E3fYhY,508
12
+ loom/graphite/match_strategy.py,sha256=BmP3QoLgl0hBuHz9zjaZ3G15HDn2qFi0oUO8v-g76Og,4101
13
+ loom/graphite/processor.py,sha256=Z4BMuT_PUzyRKRgc9ZKu9BNY2Yh_xZTDdN_xfXmUjH0,15124
14
+ loom/graphite/schema.py,sha256=Bis0YMZvGnl5tc1haxzpYjAKUDgSqB-gw7Ig8Y4RO0A,7473
15
+ loom/graphite/schema_constraints.py,sha256=ZpAozrUSu7DRZfok76czXmnsTeIuhihryTLY8oOu0ls,1222
16
+ loom/graphite/schema_contract.py,sha256=TQyv9iYWZnhxR7Q2iOC6cs9B9_kgOHBZ3Jm2IeXJ6Bs,786
17
+ loom_workflow-0.3.0.dist-info/METADATA,sha256=hjMa3KMSH3vOXUTi4t3uH7Yei1rC6U-mOwuKgcBTF7o,6520
18
+ loom_workflow-0.3.0.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
19
+ loom_workflow-0.3.0.dist-info/top_level.txt,sha256=cAfRgAuCuit-cU9iBrf0bS4ovvmq-URykNd9fmYMojg,5
20
+ loom_workflow-0.3.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.0.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1 @@
1
+ loom