@memgrafter/flatagents 2.0.0 → 2.2.0

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.
package/MACHINES.md CHANGED
@@ -22,7 +22,7 @@
22
22
  ```yaml
23
23
  # profiles.yml — agents reference by name
24
24
  spec: flatprofiles
25
- spec_version: "2.0.0"
25
+ spec_version: "2.2.0"
26
26
  data:
27
27
  model_profiles:
28
28
  fast: { provider: cerebras, name: zai-glm-4.6, temperature: 0.6 }
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Define LLM agents in YAML. Run them anywhere.
4
4
 
5
- **For LLM/machine readers:** see [MACHINES.md](./MACHINES.md) for comprehensive reference.
5
+ **For LLM/machine readers:** see [MACHINES.md](https://github.com/memgrafter/flatagents/blob/main/MACHINES.md) for comprehensive reference.
6
6
 
7
7
  ## Why?
8
8
 
@@ -35,19 +35,19 @@ Use FlatAgent alone for simple tasks. Use FlatMachine when you need multi-step w
35
35
 
36
36
  | Example | What it demonstrates |
37
37
  |---------|---------------------|
38
- | [helloworld](./sdk/examples/helloworld/python) | Minimal setup — single agent, single state machine |
39
- | [writer_critic](./sdk/examples/writer_critic/python) | Multi-agent loop — writer drafts, critic reviews, iterates |
40
- | [story_writer](./sdk/examples/story_writer/python) | Multi-step creative workflow with chapter generation |
41
- | [human-in-the-loop](./sdk/examples/human-in-the-loop/python) | Pause execution for human approval via hooks |
42
- | [error_handling](./sdk/examples/error_handling/python) | Error recovery and retry patterns at state machine level |
43
- | [dynamic_agent](./sdk/examples/dynamic_agent/python) | On-the-fly agent generation from runtime context |
44
- | [character_card](./sdk/examples/character_card/python) | Loading agent config from character card format |
45
- | [mdap](./sdk/examples/mdap/python) | MDAP voting execution — multi-sample consensus |
46
- | [gepa_self_optimizer](./sdk/examples/gepa_self_optimizer/python) | Self-optimizing prompts via reflection and critique |
47
- | [research_paper_analysis](./sdk/examples/research_paper_analysis/python) | Document analysis with structured extraction |
48
- | [multi_paper_synthesizer](./sdk/examples/multi_paper_synthesizer/python) | Cross-document synthesis with dynamic machine launching |
49
- | [support_triage_json](./sdk/examples/support_triage_json/python) | JSON input/output with classification pipeline |
50
- | [parallelism](./sdk/examples/parallelism/python) | Parallel machines, dynamic foreach, fire-and-forget launches |
38
+ | [helloworld](https://github.com/memgrafter/flatagents/tree/main/sdk/examples/helloworld/python) | Minimal setup — single agent, single state machine |
39
+ | [writer_critic](https://github.com/memgrafter/flatagents/tree/main/sdk/examples/writer_critic/python) | Multi-agent loop — writer drafts, critic reviews, iterates |
40
+ | [story_writer](https://github.com/memgrafter/flatagents/tree/main/sdk/examples/story_writer/python) | Multi-step creative workflow with chapter generation |
41
+ | [human-in-the-loop](https://github.com/memgrafter/flatagents/tree/main/sdk/examples/human-in-the-loop/python) | Pause execution for human approval via hooks |
42
+ | [error_handling](https://github.com/memgrafter/flatagents/tree/main/sdk/examples/error_handling/python) | Error recovery and retry patterns at state machine level |
43
+ | [dynamic_agent](https://github.com/memgrafter/flatagents/tree/main/sdk/examples/dynamic_agent/python) | On-the-fly agent generation from runtime context |
44
+ | [character_card](https://github.com/memgrafter/flatagents/tree/main/sdk/examples/character_card/python) | Loading agent config from character card format |
45
+ | [mdap](https://github.com/memgrafter/flatagents/tree/main/sdk/examples/mdap/python) | MDAP voting execution — multi-sample consensus |
46
+ | [gepa_self_optimizer](https://github.com/memgrafter/flatagents/tree/main/sdk/examples/gepa_self_optimizer/python) | Self-optimizing prompts via reflection and critique |
47
+ | [research_paper_analysis](https://github.com/memgrafter/flatagents/tree/main/sdk/examples/research_paper_analysis/python) | Document analysis with structured extraction |
48
+ | [multi_paper_synthesizer](https://github.com/memgrafter/flatagents/tree/main/sdk/examples/multi_paper_synthesizer/python) | Cross-document synthesis with dynamic machine launching |
49
+ | [support_triage_json](https://github.com/memgrafter/flatagents/tree/main/sdk/examples/support_triage_json/python) | JSON input/output with classification pipeline |
50
+ | [parallelism](https://github.com/memgrafter/flatagents/tree/main/sdk/examples/parallelism/python) | Parallel machines, dynamic foreach, fire-and-forget launches |
51
51
 
52
52
  ## Quick Start
53
53
 
@@ -167,7 +167,7 @@ Use `enum: [...]` to constrain string values.
167
167
 
168
168
  ## Multi-Agent Workflows
169
169
 
170
- For orchestration, use FlatMachine ([full docs in MACHINES.md](./MACHINES.md)):
170
+ For orchestration, use FlatMachine ([full docs in MACHINES.md](https://github.com/memgrafter/flatagents/blob/main/MACHINES.md)):
171
171
 
172
172
  ```python
173
173
  from flatagents import FlatMachine
@@ -182,7 +182,7 @@ FlatMachine provides: state transitions, conditional branching, loops, retry wit
182
182
 
183
183
  - Checkpoint and restore
184
184
  - Python SDK (TypeScript SDK in progress)
185
- - [MACHINES.md](./MACHINES.md) — LLM-optimized reference docs
185
+ - [MACHINES.md](https://github.com/memgrafter/flatagents/blob/main/MACHINES.md) — LLM-optimized reference docs
186
186
  - Decider agents and machines
187
187
  - On-the-fly agent and machine definitions
188
188
  - Webhook hooks for remote state machine handling
@@ -206,9 +206,9 @@ FlatMachine provides: state transitions, conditional branching, loops, retry wit
206
206
  ## Specs
207
207
 
208
208
  TypeScript definitions are the source of truth:
209
- - [`flatagent.d.ts`](./flatagent.d.ts)
210
- - [`flatmachine.d.ts`](./flatmachine.d.ts)
211
- - [`profiles.d.ts`](./profiles.d.ts)
209
+ - [`flatagent.d.ts`](https://github.com/memgrafter/flatagents/blob/main/flatagent.d.ts)
210
+ - [`flatmachine.d.ts`](https://github.com/memgrafter/flatagents/blob/main/flatmachine.d.ts)
211
+ - [`profiles.d.ts`](https://github.com/memgrafter/flatagents/blob/main/profiles.d.ts)
212
212
 
213
213
  ## Python SDK
214
214
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@memgrafter/flatagents",
3
- "version": "2.0.0",
3
+ "version": "2.2.0",
4
4
  "description": "TypeScript SDK for FlatAgents - Declarative LLM orchestration with YAML",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -149,7 +149,7 @@
149
149
  * The profile field specifies which profile name to use as base.
150
150
  */
151
151
 
152
- export const SPEC_VERSION = "2.0.0";
152
+ export const SPEC_VERSION = "2.2.0";
153
153
 
154
154
  export interface AgentWrapper {
155
155
  spec: "flatagent";
@@ -1,4 +1,4 @@
1
- export const SPEC_VERSION = "2.0.0";
1
+ export const SPEC_VERSION = "2.2.0";
2
2
  export interface AgentWrapper {
3
3
  spec: "flatagent";
4
4
  spec_version: string;
@@ -570,6 +570,26 @@ export interface MachineSnapshot {
570
570
  waiting_channel?: string;
571
571
  }
572
572
 
573
+ export interface SnapshotRuntime {
574
+ /**
575
+ * Clone a persisted machine state under a new execution ID.
576
+ *
577
+ * Reference implementation (SDK-specific internals may vary):
578
+ * 1) Deep-copy the source snapshot
579
+ * 2) Set execution_id = new_execution_id
580
+ * 3) Set created_at = current UTC ISO timestamp
581
+ * 4) Set parent_execution_id = source.execution_id
582
+ * 5) Drop pending_launches (avoid duplicate child ownership)
583
+ * 6) Persist under new_execution_id via checkpoint manager/backend
584
+ * 7) Return the cloned snapshot
585
+ */
586
+ clone_snapshot(
587
+ snapshot: MachineSnapshot,
588
+ new_execution_id: string,
589
+ persistence: PersistenceBackend
590
+ ): Promise<MachineSnapshot>;
591
+ }
592
+
573
593
  export interface LaunchIntent {
574
594
  execution_id: string;
575
595
  machine: string;
@@ -780,7 +800,7 @@ export interface BackendConfig {
780
800
  aws_region?: string;
781
801
  }
782
802
 
783
- export const SPEC_VERSION = "2.0.0";
803
+ export const SPEC_VERSION = "2.2.0";
784
804
 
785
805
  export interface SDKRuntimeWrapper {
786
806
  spec: "flatagents-runtime";
@@ -795,6 +815,7 @@ export interface SDKRuntimeWrapper {
795
815
  machine_invoker?: MachineInvoker;
796
816
  backend_config?: BackendConfig;
797
817
  machine_snapshot?: MachineSnapshot;
818
+ snapshot_runtime?: SnapshotRuntime;
798
819
  registration_backend?: RegistrationBackend;
799
820
  work_backend?: WorkBackend;
800
821
  signal_backend?: SignalBackend;
@@ -11,7 +11,7 @@
11
11
  },
12
12
  "spec_version": {
13
13
  "type": "string",
14
- "const": "2.0.0"
14
+ "const": "2.2.0"
15
15
  },
16
16
  "execution_lock": {
17
17
  "$ref": "#/definitions/ExecutionLock"
@@ -43,6 +43,9 @@
43
43
  "machine_snapshot": {
44
44
  "$ref": "#/definitions/MachineSnapshot"
45
45
  },
46
+ "snapshot_runtime": {
47
+ "$ref": "#/definitions/SnapshotRuntime"
48
+ },
46
49
  "registration_backend": {
47
50
  "$ref": "#/definitions/RegistrationBackend"
48
51
  },
@@ -320,6 +323,10 @@
320
323
  ],
321
324
  "additionalProperties": false
322
325
  },
326
+ "SnapshotRuntime": {
327
+ "type": "object",
328
+ "additionalProperties": false
329
+ },
323
330
  "RegistrationBackend": {
324
331
  "type": "object",
325
332
  "additionalProperties": false
@@ -168,6 +168,9 @@ export interface MachineSnapshot {
168
168
  pending_launches?: LaunchIntent[];
169
169
  waiting_channel?: string;
170
170
  }
171
+ export interface SnapshotRuntime {
172
+ clone_snapshot(snapshot: MachineSnapshot, new_execution_id: string, persistence: PersistenceBackend): Promise<MachineSnapshot>;
173
+ }
171
174
  export interface LaunchIntent {
172
175
  execution_id: string;
173
176
  machine: string;
@@ -249,7 +252,7 @@ export interface BackendConfig {
249
252
  dynamodb_table?: string;
250
253
  aws_region?: string;
251
254
  }
252
- export const SPEC_VERSION = "2.0.0";
255
+ export const SPEC_VERSION = "2.2.0";
253
256
  export interface SDKRuntimeWrapper {
254
257
  spec: "flatagents-runtime";
255
258
  spec_version: typeof SPEC_VERSION;
@@ -263,6 +266,7 @@ export interface SDKRuntimeWrapper {
263
266
  machine_invoker?: MachineInvoker;
264
267
  backend_config?: BackendConfig;
265
268
  machine_snapshot?: MachineSnapshot;
269
+ snapshot_runtime?: SnapshotRuntime;
266
270
  registration_backend?: RegistrationBackend;
267
271
  work_backend?: WorkBackend;
268
272
  signal_backend?: SignalBackend;
@@ -311,12 +311,15 @@
311
311
  * MACHINE SNAPSHOT:
312
312
  * -----------------
313
313
  * Wire format for checkpoints.
314
+ * context.machine - Runtime-owned metadata (execution_id, step, state, cost/calls)
315
+ * Rebuilt from live machine state on each step/resume.
314
316
  * parent_execution_id - Lineage tracking (v0.4.0)
315
317
  * pending_launches - Outbox pattern (v0.4.0)
316
318
  * waiting_channel - Signal channel this machine is blocked on (v1.2.0)
319
+ * config_hash - Content-addressed machine config key for cross-SDK resume (v2.1.0)
317
320
  */
318
321
 
319
- export const SPEC_VERSION = "2.0.0";
322
+ export const SPEC_VERSION = "2.2.0";
320
323
 
321
324
  export interface MachineWrapper {
322
325
  spec: "flatmachine";
@@ -325,10 +328,26 @@ export interface MachineWrapper {
325
328
  metadata?: Record<string, any>;
326
329
  }
327
330
 
331
+ /** Runtime-owned metadata injected at context.machine */
332
+ export interface MachineRuntimeMetadata {
333
+ execution_id: string;
334
+ machine_name: string;
335
+ parent_execution_id?: string;
336
+ spec_version: string;
337
+ step: number;
338
+ current_state: string;
339
+ total_api_calls: number;
340
+ total_cost: number;
341
+ }
342
+
328
343
  export interface MachineData {
329
344
  name?: string;
330
345
  expression_engine?: "simple" | "cel";
331
- context?: Record<string, any>;
346
+ /**
347
+ * Initial user context. Runtime reserves `context.machine` and overwrites
348
+ * it each step/resume with MachineRuntimeMetadata.
349
+ */
350
+ context?: Record<string, any> & { machine?: MachineRuntimeMetadata };
332
351
  agents?: Record<string, AgentRef>;
333
352
  machines?: Record<string, string | MachineWrapper>;
334
353
  states: Record<string, StateDefinition>;
@@ -427,7 +446,7 @@ export interface MachineSnapshot {
427
446
  machine_name: string;
428
447
  spec_version: string;
429
448
  current_state: string;
430
- context: Record<string, any>;
449
+ context: Record<string, any> & { machine?: MachineRuntimeMetadata };
431
450
  step: number;
432
451
  created_at: string;
433
452
  event?: string;
@@ -443,6 +462,7 @@ export interface MachineSnapshot {
443
462
  tool_calls_count: number;
444
463
  loop_cost: number;
445
464
  };
465
+ config_hash?: string;
446
466
  }
447
467
 
448
468
  export interface PersistenceConfig {
@@ -40,7 +40,13 @@
40
40
  ]
41
41
  },
42
42
  "context": {
43
- "type": "object"
43
+ "type": "object",
44
+ "properties": {
45
+ "machine": {
46
+ "$ref": "#/definitions/MachineRuntimeMetadata"
47
+ }
48
+ },
49
+ "description": "Initial user context. Runtime reserves `context.machine` and overwrites it each step/resume with MachineRuntimeMetadata."
44
50
  },
45
51
  "agents": {
46
52
  "type": "object",
@@ -82,6 +88,46 @@
82
88
  ],
83
89
  "additionalProperties": false
84
90
  },
91
+ "MachineRuntimeMetadata": {
92
+ "type": "object",
93
+ "properties": {
94
+ "execution_id": {
95
+ "type": "string"
96
+ },
97
+ "machine_name": {
98
+ "type": "string"
99
+ },
100
+ "parent_execution_id": {
101
+ "type": "string"
102
+ },
103
+ "spec_version": {
104
+ "type": "string"
105
+ },
106
+ "step": {
107
+ "type": "number"
108
+ },
109
+ "current_state": {
110
+ "type": "string"
111
+ },
112
+ "total_api_calls": {
113
+ "type": "number"
114
+ },
115
+ "total_cost": {
116
+ "type": "number"
117
+ }
118
+ },
119
+ "required": [
120
+ "execution_id",
121
+ "machine_name",
122
+ "spec_version",
123
+ "step",
124
+ "current_state",
125
+ "total_api_calls",
126
+ "total_cost"
127
+ ],
128
+ "additionalProperties": false,
129
+ "description": "Runtime-owned metadata injected at context.machine"
130
+ },
85
131
  "AgentRef": {
86
132
  "anyOf": [
87
133
  {
@@ -1,14 +1,26 @@
1
- export const SPEC_VERSION = "2.0.0";
1
+ export const SPEC_VERSION = "2.2.0";
2
2
  export interface MachineWrapper {
3
3
  spec: "flatmachine";
4
4
  spec_version: string;
5
5
  data: MachineData;
6
6
  metadata?: Record<string, any>;
7
7
  }
8
+ export interface MachineRuntimeMetadata {
9
+ execution_id: string;
10
+ machine_name: string;
11
+ parent_execution_id?: string;
12
+ spec_version: string;
13
+ step: number;
14
+ current_state: string;
15
+ total_api_calls: number;
16
+ total_cost: number;
17
+ }
8
18
  export interface MachineData {
9
19
  name?: string;
10
20
  expression_engine?: "simple" | "cel";
11
- context?: Record<string, any>;
21
+ context?: Record<string, any> & {
22
+ machine?: MachineRuntimeMetadata;
23
+ };
12
24
  agents?: Record<string, AgentRef>;
13
25
  machines?: Record<string, string | MachineWrapper>;
14
26
  states: Record<string, StateDefinition>;
@@ -93,7 +105,9 @@ export interface MachineSnapshot {
93
105
  machine_name: string;
94
106
  spec_version: string;
95
107
  current_state: string;
96
- context: Record<string, any>;
108
+ context: Record<string, any> & {
109
+ machine?: MachineRuntimeMetadata;
110
+ };
97
111
  step: number;
98
112
  created_at: string;
99
113
  event?: string;
@@ -109,6 +123,7 @@ export interface MachineSnapshot {
109
123
  tool_calls_count: number;
110
124
  loop_cost: number;
111
125
  };
126
+ config_hash?: string;
112
127
  }
113
128
  export interface PersistenceConfig {
114
129
  enabled: boolean;
@@ -108,7 +108,7 @@
108
108
  * stream - Enable streaming responses (default: false)
109
109
  */
110
110
 
111
- export const SPEC_VERSION = "2.0.0";
111
+ export const SPEC_VERSION = "2.2.0";
112
112
 
113
113
  export interface ProfilesWrapper {
114
114
  spec: "flatprofiles";
@@ -1,4 +1,4 @@
1
- export const SPEC_VERSION = "2.0.0";
1
+ export const SPEC_VERSION = "2.2.0";
2
2
  export interface ProfilesWrapper {
3
3
  spec: "flatprofiles";
4
4
  spec_version: string;