flatmachines 1.0.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.
Files changed (41) hide show
  1. flatmachines/__init__.py +136 -0
  2. flatmachines/actions.py +408 -0
  3. flatmachines/adapters/__init__.py +38 -0
  4. flatmachines/adapters/flatagent.py +86 -0
  5. flatmachines/adapters/pi_agent_bridge.py +127 -0
  6. flatmachines/adapters/pi_agent_runner.mjs +99 -0
  7. flatmachines/adapters/smolagents.py +125 -0
  8. flatmachines/agents.py +144 -0
  9. flatmachines/assets/MACHINES.md +141 -0
  10. flatmachines/assets/README.md +11 -0
  11. flatmachines/assets/__init__.py +0 -0
  12. flatmachines/assets/flatagent.d.ts +219 -0
  13. flatmachines/assets/flatagent.schema.json +271 -0
  14. flatmachines/assets/flatagent.slim.d.ts +58 -0
  15. flatmachines/assets/flatagents-runtime.d.ts +523 -0
  16. flatmachines/assets/flatagents-runtime.schema.json +281 -0
  17. flatmachines/assets/flatagents-runtime.slim.d.ts +187 -0
  18. flatmachines/assets/flatmachine.d.ts +403 -0
  19. flatmachines/assets/flatmachine.schema.json +620 -0
  20. flatmachines/assets/flatmachine.slim.d.ts +106 -0
  21. flatmachines/assets/profiles.d.ts +140 -0
  22. flatmachines/assets/profiles.schema.json +93 -0
  23. flatmachines/assets/profiles.slim.d.ts +26 -0
  24. flatmachines/backends.py +222 -0
  25. flatmachines/distributed.py +835 -0
  26. flatmachines/distributed_hooks.py +351 -0
  27. flatmachines/execution.py +638 -0
  28. flatmachines/expressions/__init__.py +60 -0
  29. flatmachines/expressions/cel.py +101 -0
  30. flatmachines/expressions/simple.py +166 -0
  31. flatmachines/flatmachine.py +1263 -0
  32. flatmachines/hooks.py +381 -0
  33. flatmachines/locking.py +69 -0
  34. flatmachines/monitoring.py +505 -0
  35. flatmachines/persistence.py +213 -0
  36. flatmachines/run.py +117 -0
  37. flatmachines/utils.py +166 -0
  38. flatmachines/validation.py +79 -0
  39. flatmachines-1.0.0.dist-info/METADATA +390 -0
  40. flatmachines-1.0.0.dist-info/RECORD +41 -0
  41. flatmachines-1.0.0.dist-info/WHEEL +4 -0
@@ -0,0 +1,620 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema#",
3
+ "$ref": "#/definitions/MachineWrapper",
4
+ "definitions": {
5
+ "MachineWrapper": {
6
+ "type": "object",
7
+ "properties": {
8
+ "spec": {
9
+ "type": "string",
10
+ "const": "flatmachine"
11
+ },
12
+ "spec_version": {
13
+ "type": "string"
14
+ },
15
+ "data": {
16
+ "$ref": "#/definitions/MachineData"
17
+ },
18
+ "metadata": {
19
+ "type": "object"
20
+ }
21
+ },
22
+ "required": [
23
+ "spec",
24
+ "spec_version",
25
+ "data"
26
+ ],
27
+ "additionalProperties": false
28
+ },
29
+ "MachineData": {
30
+ "type": "object",
31
+ "properties": {
32
+ "name": {
33
+ "type": "string"
34
+ },
35
+ "expression_engine": {
36
+ "type": "string",
37
+ "enum": [
38
+ "simple",
39
+ "cel"
40
+ ]
41
+ },
42
+ "context": {
43
+ "type": "object"
44
+ },
45
+ "agents": {
46
+ "type": "object",
47
+ "additionalProperties": {
48
+ "$ref": "#/definitions/AgentRef"
49
+ }
50
+ },
51
+ "machines": {
52
+ "type": "object",
53
+ "additionalProperties": {
54
+ "anyOf": [
55
+ {
56
+ "type": "string"
57
+ },
58
+ {
59
+ "$ref": "#/definitions/MachineWrapper"
60
+ }
61
+ ]
62
+ }
63
+ },
64
+ "states": {
65
+ "type": "object",
66
+ "additionalProperties": {
67
+ "$ref": "#/definitions/StateDefinition"
68
+ }
69
+ },
70
+ "settings": {
71
+ "$ref": "#/definitions/MachineSettings"
72
+ },
73
+ "persistence": {
74
+ "$ref": "#/definitions/PersistenceConfig"
75
+ },
76
+ "hooks": {
77
+ "$ref": "#/definitions/HooksConfig"
78
+ }
79
+ },
80
+ "required": [
81
+ "states"
82
+ ],
83
+ "additionalProperties": false
84
+ },
85
+ "AgentRef": {
86
+ "anyOf": [
87
+ {
88
+ "type": "string"
89
+ },
90
+ {
91
+ "$ref": "#/definitions/AgentWrapper"
92
+ },
93
+ {
94
+ "$ref": "#/definitions/AgentRefConfig"
95
+ }
96
+ ]
97
+ },
98
+ "AgentWrapper": {
99
+ "type": "object",
100
+ "properties": {
101
+ "spec": {
102
+ "type": "string",
103
+ "const": "flatagent"
104
+ },
105
+ "spec_version": {
106
+ "type": "string"
107
+ },
108
+ "data": {
109
+ "$ref": "#/definitions/AgentData"
110
+ },
111
+ "metadata": {
112
+ "type": "object"
113
+ }
114
+ },
115
+ "required": [
116
+ "spec",
117
+ "spec_version",
118
+ "data"
119
+ ],
120
+ "additionalProperties": false
121
+ },
122
+ "AgentData": {
123
+ "type": "object",
124
+ "properties": {
125
+ "name": {
126
+ "type": "string"
127
+ },
128
+ "model": {
129
+ "anyOf": [
130
+ {
131
+ "type": "string"
132
+ },
133
+ {
134
+ "$ref": "#/definitions/ModelConfig"
135
+ },
136
+ {
137
+ "$ref": "#/definitions/ProfiledModelConfig"
138
+ }
139
+ ]
140
+ },
141
+ "system": {
142
+ "type": "string"
143
+ },
144
+ "user": {
145
+ "type": "string"
146
+ },
147
+ "instruction_suffix": {
148
+ "type": "string"
149
+ },
150
+ "output": {
151
+ "$ref": "#/definitions/OutputSchema"
152
+ },
153
+ "mcp": {
154
+ "$ref": "#/definitions/MCPConfig"
155
+ }
156
+ },
157
+ "required": [
158
+ "model",
159
+ "system",
160
+ "user"
161
+ ],
162
+ "additionalProperties": false
163
+ },
164
+ "ModelConfig": {
165
+ "type": "object",
166
+ "properties": {
167
+ "name": {
168
+ "type": "string"
169
+ },
170
+ "provider": {
171
+ "type": "string"
172
+ },
173
+ "temperature": {
174
+ "type": "number"
175
+ },
176
+ "max_tokens": {
177
+ "type": "number"
178
+ },
179
+ "top_p": {
180
+ "type": "number"
181
+ },
182
+ "top_k": {
183
+ "type": "number"
184
+ },
185
+ "frequency_penalty": {
186
+ "type": "number"
187
+ },
188
+ "presence_penalty": {
189
+ "type": "number"
190
+ },
191
+ "seed": {
192
+ "type": "number"
193
+ },
194
+ "base_url": {
195
+ "type": "string"
196
+ }
197
+ },
198
+ "required": [
199
+ "name"
200
+ ],
201
+ "additionalProperties": false
202
+ },
203
+ "ProfiledModelConfig": {
204
+ "type": "object",
205
+ "properties": {
206
+ "name": {
207
+ "type": "string"
208
+ },
209
+ "provider": {
210
+ "type": "string"
211
+ },
212
+ "temperature": {
213
+ "type": "number"
214
+ },
215
+ "max_tokens": {
216
+ "type": "number"
217
+ },
218
+ "top_p": {
219
+ "type": "number"
220
+ },
221
+ "top_k": {
222
+ "type": "number"
223
+ },
224
+ "frequency_penalty": {
225
+ "type": "number"
226
+ },
227
+ "presence_penalty": {
228
+ "type": "number"
229
+ },
230
+ "seed": {
231
+ "type": "number"
232
+ },
233
+ "base_url": {
234
+ "type": "string"
235
+ },
236
+ "profile": {
237
+ "type": "string"
238
+ }
239
+ },
240
+ "required": [
241
+ "profile"
242
+ ],
243
+ "additionalProperties": false
244
+ },
245
+ "OutputSchema": {
246
+ "type": "object",
247
+ "additionalProperties": {
248
+ "$ref": "#/definitions/OutputFieldDef"
249
+ }
250
+ },
251
+ "OutputFieldDef": {
252
+ "type": "object",
253
+ "properties": {
254
+ "type": {
255
+ "type": "string",
256
+ "enum": [
257
+ "str",
258
+ "int",
259
+ "float",
260
+ "bool",
261
+ "json",
262
+ "list",
263
+ "object"
264
+ ]
265
+ },
266
+ "description": {
267
+ "type": "string"
268
+ },
269
+ "enum": {
270
+ "type": "array",
271
+ "items": {
272
+ "type": "string"
273
+ }
274
+ },
275
+ "required": {
276
+ "type": "boolean"
277
+ },
278
+ "items": {
279
+ "$ref": "#/definitions/OutputFieldDef"
280
+ },
281
+ "properties": {
282
+ "$ref": "#/definitions/OutputSchema"
283
+ }
284
+ },
285
+ "required": [
286
+ "type"
287
+ ],
288
+ "additionalProperties": false
289
+ },
290
+ "MCPConfig": {
291
+ "type": "object",
292
+ "properties": {
293
+ "servers": {
294
+ "type": "object",
295
+ "additionalProperties": {
296
+ "$ref": "#/definitions/MCPServerDef"
297
+ }
298
+ },
299
+ "tool_filter": {
300
+ "$ref": "#/definitions/ToolFilter"
301
+ },
302
+ "tool_prompt": {
303
+ "type": "string"
304
+ }
305
+ },
306
+ "required": [
307
+ "servers",
308
+ "tool_prompt"
309
+ ],
310
+ "additionalProperties": false
311
+ },
312
+ "MCPServerDef": {
313
+ "type": "object",
314
+ "properties": {
315
+ "command": {
316
+ "type": "string"
317
+ },
318
+ "args": {
319
+ "type": "array",
320
+ "items": {
321
+ "type": "string"
322
+ }
323
+ },
324
+ "env": {
325
+ "type": "object",
326
+ "additionalProperties": {
327
+ "type": "string"
328
+ }
329
+ },
330
+ "server_url": {
331
+ "type": "string"
332
+ },
333
+ "headers": {
334
+ "type": "object",
335
+ "additionalProperties": {
336
+ "type": "string"
337
+ }
338
+ },
339
+ "timeout": {
340
+ "type": "number"
341
+ }
342
+ },
343
+ "additionalProperties": false
344
+ },
345
+ "ToolFilter": {
346
+ "type": "object",
347
+ "properties": {
348
+ "allow": {
349
+ "type": "array",
350
+ "items": {
351
+ "type": "string"
352
+ }
353
+ },
354
+ "deny": {
355
+ "type": "array",
356
+ "items": {
357
+ "type": "string"
358
+ }
359
+ }
360
+ },
361
+ "additionalProperties": false
362
+ },
363
+ "AgentRefConfig": {
364
+ "type": "object",
365
+ "properties": {
366
+ "type": {
367
+ "type": "string"
368
+ },
369
+ "ref": {
370
+ "type": "string"
371
+ },
372
+ "config": {
373
+ "type": "object"
374
+ }
375
+ },
376
+ "required": [
377
+ "type"
378
+ ],
379
+ "additionalProperties": false
380
+ },
381
+ "StateDefinition": {
382
+ "type": "object",
383
+ "properties": {
384
+ "type": {
385
+ "type": "string",
386
+ "enum": [
387
+ "initial",
388
+ "final"
389
+ ]
390
+ },
391
+ "agent": {
392
+ "type": "string"
393
+ },
394
+ "machine": {
395
+ "anyOf": [
396
+ {
397
+ "type": "string"
398
+ },
399
+ {
400
+ "type": "array",
401
+ "items": {
402
+ "type": "string"
403
+ }
404
+ },
405
+ {
406
+ "type": "array",
407
+ "items": {
408
+ "$ref": "#/definitions/MachineInput"
409
+ }
410
+ }
411
+ ]
412
+ },
413
+ "action": {
414
+ "type": "string"
415
+ },
416
+ "execution": {
417
+ "$ref": "#/definitions/ExecutionConfig"
418
+ },
419
+ "on_error": {
420
+ "anyOf": [
421
+ {
422
+ "type": "string"
423
+ },
424
+ {
425
+ "type": "object",
426
+ "additionalProperties": {
427
+ "type": "string"
428
+ }
429
+ }
430
+ ]
431
+ },
432
+ "input": {
433
+ "type": "object"
434
+ },
435
+ "output_to_context": {
436
+ "type": "object"
437
+ },
438
+ "output": {
439
+ "type": "object"
440
+ },
441
+ "transitions": {
442
+ "type": "array",
443
+ "items": {
444
+ "$ref": "#/definitions/Transition"
445
+ }
446
+ },
447
+ "tool_loop": {
448
+ "type": "boolean"
449
+ },
450
+ "sampling": {
451
+ "type": "string",
452
+ "enum": [
453
+ "single",
454
+ "multi"
455
+ ]
456
+ },
457
+ "foreach": {
458
+ "type": "string"
459
+ },
460
+ "as": {
461
+ "type": "string"
462
+ },
463
+ "key": {
464
+ "type": "string"
465
+ },
466
+ "mode": {
467
+ "type": "string",
468
+ "enum": [
469
+ "settled",
470
+ "any"
471
+ ]
472
+ },
473
+ "timeout": {
474
+ "type": "number"
475
+ },
476
+ "launch": {
477
+ "anyOf": [
478
+ {
479
+ "type": "string"
480
+ },
481
+ {
482
+ "type": "array",
483
+ "items": {
484
+ "type": "string"
485
+ }
486
+ }
487
+ ]
488
+ },
489
+ "launch_input": {
490
+ "type": "object"
491
+ }
492
+ },
493
+ "additionalProperties": false
494
+ },
495
+ "MachineInput": {
496
+ "type": "object",
497
+ "properties": {
498
+ "name": {
499
+ "type": "string"
500
+ },
501
+ "input": {
502
+ "type": "object"
503
+ }
504
+ },
505
+ "required": [
506
+ "name"
507
+ ],
508
+ "additionalProperties": false
509
+ },
510
+ "ExecutionConfig": {
511
+ "type": "object",
512
+ "properties": {
513
+ "type": {
514
+ "type": "string",
515
+ "enum": [
516
+ "default",
517
+ "retry",
518
+ "parallel",
519
+ "mdap_voting"
520
+ ]
521
+ },
522
+ "backoffs": {
523
+ "type": "array",
524
+ "items": {
525
+ "type": "number"
526
+ }
527
+ },
528
+ "jitter": {
529
+ "type": "number"
530
+ },
531
+ "n_samples": {
532
+ "type": "number"
533
+ },
534
+ "k_margin": {
535
+ "type": "number"
536
+ },
537
+ "max_candidates": {
538
+ "type": "number"
539
+ }
540
+ },
541
+ "required": [
542
+ "type"
543
+ ],
544
+ "additionalProperties": false
545
+ },
546
+ "Transition": {
547
+ "type": "object",
548
+ "properties": {
549
+ "condition": {
550
+ "type": "string"
551
+ },
552
+ "to": {
553
+ "type": "string"
554
+ }
555
+ },
556
+ "required": [
557
+ "to"
558
+ ],
559
+ "additionalProperties": false
560
+ },
561
+ "MachineSettings": {
562
+ "type": "object",
563
+ "properties": {
564
+ "max_steps": {
565
+ "type": "number"
566
+ },
567
+ "parallel_fallback": {
568
+ "type": "string",
569
+ "enum": [
570
+ "sequential",
571
+ "error"
572
+ ]
573
+ }
574
+ }
575
+ },
576
+ "PersistenceConfig": {
577
+ "type": "object",
578
+ "properties": {
579
+ "enabled": {
580
+ "type": "boolean"
581
+ },
582
+ "backend": {
583
+ "type": "string"
584
+ },
585
+ "checkpoint_on": {
586
+ "type": "array",
587
+ "items": {
588
+ "type": "string"
589
+ }
590
+ }
591
+ },
592
+ "required": [
593
+ "enabled",
594
+ "backend"
595
+ ]
596
+ },
597
+ "HooksConfig": {
598
+ "type": "object",
599
+ "properties": {
600
+ "file": {
601
+ "type": "string"
602
+ },
603
+ "module": {
604
+ "type": "string"
605
+ },
606
+ "class": {
607
+ "type": "string"
608
+ },
609
+ "args": {
610
+ "type": "object"
611
+ }
612
+ },
613
+ "required": [
614
+ "class"
615
+ ],
616
+ "additionalProperties": false,
617
+ "description": "Configuration for loading hooks from file or module.\n\nFile-based (preferred for self-contained skills): hooks: file: \"./hooks.py\" class: \"MyHooks\" args: working_dir: \".\"\n\nModule-based (for installed packages): hooks: module: \"mypackage.hooks\" class: \"MyHooks\" args: api_key: \"{{ input.api_key }}\"\n\nFields: file - Path to Python file containing hooks class (relative to machine.yml) module - Python module path to import class - Class name to instantiate (required) args - Arguments to pass to hooks constructor"
618
+ }
619
+ }
620
+ }
@@ -0,0 +1,106 @@
1
+ export const SPEC_VERSION = "1.0.0";
2
+ export interface MachineWrapper {
3
+ spec: "flatmachine";
4
+ spec_version: string;
5
+ data: MachineData;
6
+ metadata?: Record<string, any>;
7
+ }
8
+ export interface MachineData {
9
+ name?: string;
10
+ expression_engine?: "simple" | "cel";
11
+ context?: Record<string, any>;
12
+ agents?: Record<string, AgentRef>;
13
+ machines?: Record<string, string | MachineWrapper>;
14
+ states: Record<string, StateDefinition>;
15
+ settings?: MachineSettings;
16
+ persistence?: PersistenceConfig;
17
+ hooks?: HooksConfig;
18
+ }
19
+ export interface AgentRefConfig {
20
+ type: string;
21
+ ref?: string;
22
+ config?: Record<string, any>;
23
+ }
24
+ export type AgentRef = string | AgentWrapper | AgentRefConfig;
25
+ export interface HooksConfig {
26
+ file?: string;
27
+ module?: string;
28
+ class: string;
29
+ args?: Record<string, any>;
30
+ }
31
+ export interface MachineSettings {
32
+ max_steps?: number;
33
+ parallel_fallback?: "sequential" | "error";
34
+ [key: string]: any;
35
+ }
36
+ export interface StateDefinition {
37
+ type?: "initial" | "final";
38
+ agent?: string;
39
+ machine?: string | string[] | MachineInput[];
40
+ action?: string;
41
+ execution?: ExecutionConfig;
42
+ on_error?: string | Record<string, string>;
43
+ input?: Record<string, any>;
44
+ output_to_context?: Record<string, any>;
45
+ output?: Record<string, any>;
46
+ transitions?: Transition[];
47
+ tool_loop?: boolean;
48
+ sampling?: "single" | "multi";
49
+ foreach?: string;
50
+ as?: string;
51
+ key?: string;
52
+ mode?: "settled" | "any";
53
+ timeout?: number;
54
+ launch?: string | string[];
55
+ launch_input?: Record<string, any>;
56
+ }
57
+ export interface MachineInput {
58
+ name: string;
59
+ input?: Record<string, any>;
60
+ }
61
+ export interface ExecutionConfig {
62
+ type: "default" | "retry" | "parallel" | "mdap_voting";
63
+ backoffs?: number[];
64
+ jitter?: number;
65
+ n_samples?: number;
66
+ k_margin?: number;
67
+ max_candidates?: number;
68
+ }
69
+ export interface Transition {
70
+ condition?: string;
71
+ to: string;
72
+ }
73
+ import { AgentWrapper, OutputSchema, ModelConfig } from "./flatagent";
74
+ export { AgentWrapper, OutputSchema };
75
+ export type FlatmachineConfig = MachineWrapper;
76
+ export interface LaunchIntent {
77
+ execution_id: string;
78
+ machine: string;
79
+ input: Record<string, any>;
80
+ launched: boolean;
81
+ }
82
+ export interface MachineSnapshot {
83
+ execution_id: string;
84
+ machine_name: string;
85
+ spec_version: string;
86
+ current_state: string;
87
+ context: Record<string, any>;
88
+ step: number;
89
+ created_at: string;
90
+ event?: string;
91
+ output?: Record<string, any>;
92
+ total_api_calls?: number;
93
+ total_cost?: number;
94
+ parent_execution_id?: string;
95
+ pending_launches?: LaunchIntent[];
96
+ }
97
+ export interface PersistenceConfig {
98
+ enabled: boolean;
99
+ backend: "local" | "redis" | "memory" | string;
100
+ checkpoint_on?: string[];
101
+ [key: string]: any;
102
+ }
103
+ export interface MachineReference {
104
+ path?: string;
105
+ inline?: MachineWrapper;
106
+ }