flatagents 0.4.1__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,210 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema#",
3
+ "$ref": "#/definitions/AgentWrapper",
4
+ "definitions": {
5
+ "AgentWrapper": {
6
+ "type": "object",
7
+ "properties": {
8
+ "spec": {
9
+ "type": "string",
10
+ "const": "flatagent"
11
+ },
12
+ "spec_version": {
13
+ "type": "string"
14
+ },
15
+ "data": {
16
+ "$ref": "#/definitions/AgentData"
17
+ },
18
+ "metadata": {
19
+ "type": "object"
20
+ }
21
+ },
22
+ "required": [
23
+ "spec",
24
+ "spec_version",
25
+ "data"
26
+ ],
27
+ "additionalProperties": false
28
+ },
29
+ "AgentData": {
30
+ "type": "object",
31
+ "properties": {
32
+ "name": {
33
+ "type": "string"
34
+ },
35
+ "model": {
36
+ "$ref": "#/definitions/ModelConfig"
37
+ },
38
+ "system": {
39
+ "type": "string"
40
+ },
41
+ "user": {
42
+ "type": "string"
43
+ },
44
+ "instruction_suffix": {
45
+ "type": "string"
46
+ },
47
+ "output": {
48
+ "$ref": "#/definitions/OutputSchema"
49
+ },
50
+ "mcp": {
51
+ "$ref": "#/definitions/MCPConfig"
52
+ }
53
+ },
54
+ "required": [
55
+ "model",
56
+ "system",
57
+ "user"
58
+ ],
59
+ "additionalProperties": false
60
+ },
61
+ "ModelConfig": {
62
+ "type": "object",
63
+ "properties": {
64
+ "name": {
65
+ "type": "string"
66
+ },
67
+ "provider": {
68
+ "type": "string"
69
+ },
70
+ "temperature": {
71
+ "type": "number"
72
+ },
73
+ "max_tokens": {
74
+ "type": "number"
75
+ },
76
+ "top_p": {
77
+ "type": "number"
78
+ },
79
+ "frequency_penalty": {
80
+ "type": "number"
81
+ },
82
+ "presence_penalty": {
83
+ "type": "number"
84
+ }
85
+ },
86
+ "required": [
87
+ "name"
88
+ ],
89
+ "additionalProperties": false
90
+ },
91
+ "OutputSchema": {
92
+ "type": "object",
93
+ "additionalProperties": {
94
+ "$ref": "#/definitions/OutputFieldDef"
95
+ }
96
+ },
97
+ "OutputFieldDef": {
98
+ "type": "object",
99
+ "properties": {
100
+ "type": {
101
+ "type": "string",
102
+ "enum": [
103
+ "str",
104
+ "int",
105
+ "float",
106
+ "bool",
107
+ "json",
108
+ "list",
109
+ "object"
110
+ ]
111
+ },
112
+ "description": {
113
+ "type": "string"
114
+ },
115
+ "enum": {
116
+ "type": "array",
117
+ "items": {
118
+ "type": "string"
119
+ }
120
+ },
121
+ "required": {
122
+ "type": "boolean"
123
+ },
124
+ "items": {
125
+ "$ref": "#/definitions/OutputFieldDef"
126
+ },
127
+ "properties": {
128
+ "$ref": "#/definitions/OutputSchema"
129
+ }
130
+ },
131
+ "required": [
132
+ "type"
133
+ ],
134
+ "additionalProperties": false
135
+ },
136
+ "MCPConfig": {
137
+ "type": "object",
138
+ "properties": {
139
+ "servers": {
140
+ "type": "object",
141
+ "additionalProperties": {
142
+ "$ref": "#/definitions/MCPServerDef"
143
+ }
144
+ },
145
+ "tool_filter": {
146
+ "$ref": "#/definitions/ToolFilter"
147
+ },
148
+ "tool_prompt": {
149
+ "type": "string"
150
+ }
151
+ },
152
+ "required": [
153
+ "servers",
154
+ "tool_prompt"
155
+ ],
156
+ "additionalProperties": false
157
+ },
158
+ "MCPServerDef": {
159
+ "type": "object",
160
+ "properties": {
161
+ "command": {
162
+ "type": "string"
163
+ },
164
+ "args": {
165
+ "type": "array",
166
+ "items": {
167
+ "type": "string"
168
+ }
169
+ },
170
+ "env": {
171
+ "type": "object",
172
+ "additionalProperties": {
173
+ "type": "string"
174
+ }
175
+ },
176
+ "server_url": {
177
+ "type": "string"
178
+ },
179
+ "headers": {
180
+ "type": "object",
181
+ "additionalProperties": {
182
+ "type": "string"
183
+ }
184
+ },
185
+ "timeout": {
186
+ "type": "number"
187
+ }
188
+ },
189
+ "additionalProperties": false
190
+ },
191
+ "ToolFilter": {
192
+ "type": "object",
193
+ "properties": {
194
+ "allow": {
195
+ "type": "array",
196
+ "items": {
197
+ "type": "string"
198
+ }
199
+ },
200
+ "deny": {
201
+ "type": "array",
202
+ "items": {
203
+ "type": "string"
204
+ }
205
+ }
206
+ },
207
+ "additionalProperties": false
208
+ }
209
+ }
210
+ }
@@ -0,0 +1,52 @@
1
+ export const SPEC_VERSION = "0.6.0";
2
+ export interface AgentWrapper {
3
+ spec: "flatagent";
4
+ spec_version: string;
5
+ data: AgentData;
6
+ metadata?: Record<string, any>;
7
+ }
8
+ export interface AgentData {
9
+ name?: string;
10
+ model: ModelConfig;
11
+ system: string;
12
+ user: string;
13
+ instruction_suffix?: string;
14
+ output?: OutputSchema;
15
+ mcp?: MCPConfig;
16
+ }
17
+ export interface MCPConfig {
18
+ servers: Record<string, MCPServerDef>;
19
+ tool_filter?: ToolFilter;
20
+ tool_prompt: string;
21
+ }
22
+ export interface MCPServerDef {
23
+ command?: string;
24
+ args?: string[];
25
+ env?: Record<string, string>;
26
+ server_url?: string;
27
+ headers?: Record<string, string>;
28
+ timeout?: number;
29
+ }
30
+ export interface ToolFilter {
31
+ allow?: string[];
32
+ deny?: string[];
33
+ }
34
+ export interface ModelConfig {
35
+ name: string;
36
+ provider?: string;
37
+ temperature?: number;
38
+ max_tokens?: number;
39
+ top_p?: number;
40
+ frequency_penalty?: number;
41
+ presence_penalty?: number;
42
+ }
43
+ export type OutputSchema = Record<string, OutputFieldDef>;
44
+ export interface OutputFieldDef {
45
+ type: "str" | "int" | "float" | "bool" | "json" | "list" | "object";
46
+ description?: string;
47
+ enum?: string[];
48
+ required?: boolean;
49
+ items?: OutputFieldDef;
50
+ properties?: OutputSchema;
51
+ }
52
+ export type FlatagentsConfig = AgentWrapper;
@@ -0,0 +1,363 @@
1
+ /**
2
+ * FlatMachine Configuration Schema
3
+ * ================================
4
+ *
5
+ * A machine defines how agents are connected and executed:
6
+ * states, transitions, conditions, and loops.
7
+ *
8
+ * While flatagents defines WHAT each agent is (model + prompts + output schema),
9
+ * flatmachines defines HOW agents are connected and executed.
10
+ *
11
+ * STRUCTURE:
12
+ * ----------
13
+ * spec - Fixed string "flatmachine"
14
+ * spec_version - Semver string
15
+ * data - The machine configuration
16
+ * metadata - Extensibility layer
17
+ *
18
+ * DERIVED SCHEMAS:
19
+ * ----------------
20
+ * This file (/flatmachine.d.ts) is the SOURCE OF TRUTH for all FlatMachine schemas.
21
+ * Other schemas (JSON Schema, etc.) are DERIVED from this file using scripts.
22
+ * See: /scripts/generate-spec-assets.ts
23
+ *
24
+ * DATA FIELDS:
25
+ * ------------
26
+ * name - Machine identifier
27
+ * expression_engine - "simple" (default) or "cel"
28
+ * context - Initial context values (Jinja2 templates)
29
+ * agents - Map of agent name to config file path or inline config
30
+ * machines - Map of machine name to config file path or inline config
31
+ * states - Map of state name to state definition
32
+ * settings - Optional settings (hooks, etc.)
33
+ *
34
+ * STATE FIELDS:
35
+ * -------------
36
+ * type - "initial" or "final" (optional)
37
+ * agent - Agent name to execute (from agents map)
38
+ * machine - Machine name or array for parallel execution (from machines map)
39
+ * execution - Execution type config: {type: "retry", backoffs: [...], jitter: 0.1}
40
+ * on_error - Error handling: "error_state" or {default: "...", ErrorType: "..."}
41
+ * action - Hook action to execute
42
+ * input - Input mapping (Jinja2 templates)
43
+ * output_to_context - Map agent output to context (Jinja2 templates)
44
+ * output - Final output (for final states)
45
+ * transitions - Ordered list of transitions
46
+ *
47
+ * PARALLEL EXECUTION (v0.4.0):
48
+ * ----------------------------
49
+ * machine - Can be string[] for parallel machine invocation
50
+ * foreach - Jinja2 expression yielding array for dynamic parallelism
51
+ * as - Variable name for current item in foreach (default: "item")
52
+ * key - Jinja2 expression for result key (optional, results array if omitted)
53
+ * mode - Completion semantics: "settled" (default) or "any"
54
+ * timeout - Timeout in seconds (0 = never)
55
+ * launch - Machine(s) to start fire-and-forget
56
+ * launch_input - Input for launched machines
57
+ *
58
+ * NOTE: Only `machine` supports parallel invocation (string[]), not `agent`.
59
+ * Machines are self-healing with checkpoint/resume and error handling.
60
+ * Agents are raw LLM calls that can fail without recovery. Wrap agents in
61
+ * machines to get retry logic, checkpointing, and proper failure handling
62
+ * before running them in parallel.
63
+ *
64
+ * RUNTIME MODEL (v0.4.0):
65
+ * -----------------------
66
+ * All machine invocations are launches. Communication via result backend.
67
+ *
68
+ * machine: child → launch + blocking read
69
+ * machine: [a,b,c] → launch all + wait for all
70
+ * launch: child → launch only, no read
71
+ *
72
+ * URI Scheme: flatagents://{execution_id}/[checkpoint|result]
73
+ *
74
+ * Parent generates child's execution_id, passes it to child. Child writes
75
+ * result to its URI. Parent reads from known URI. No direct messaging.
76
+ *
77
+ * Local SDKs may optimize blocking reads as function returns (in-memory backend).
78
+ * This decouples output from read, enabling both local and distributed execution.
79
+ *
80
+ * Launch intents are checkpointed before execution (outbox pattern).
81
+ * On resume, SDK checks if launched machine exists before re-launching.
82
+ *
83
+ * TRANSITION FIELDS:
84
+ * ------------------
85
+ * condition - Expression to evaluate (optional, default: always true)
86
+ * to - Target state name
87
+ *
88
+ * EXPRESSION SYNTAX (Simple Mode):
89
+ * --------------------------------
90
+ * Comparisons: ==, !=, <, <=, >, >=
91
+ * Boolean: and, or, not
92
+ * Field access: context.field, input.field, output.field
93
+ * Literals: "string", 42, true, false, null
94
+ *
95
+ * Example: "context.score >= 8 and context.round < 4"
96
+ *
97
+ * EXPRESSION SYNTAX (CEL Mode):
98
+ * -----------------------------
99
+ * All simple syntax, plus:
100
+ * List macros: context.items.all(i, i > 0)
101
+ * String methods: context.name.startsWith("test")
102
+ * Timestamps: context.created > now - duration("24h")
103
+ *
104
+ * EXAMPLE CONFIGURATION:
105
+ * ----------------------
106
+ *
107
+ * spec: flatmachine
108
+ * spec_version: "0.4.0"
109
+ *
110
+ * data:
111
+ * name: writer-critic-loop
112
+ *
113
+ * context:
114
+ * product: "{{ input.product }}"
115
+ * score: 0
116
+ * round: 0
117
+ *
118
+ * agents:
119
+ * writer: ./writer.yml
120
+ * critic: ./critic.yml
121
+ *
122
+ * states:
123
+ * start:
124
+ * type: initial
125
+ * transitions:
126
+ * - to: write
127
+ *
128
+ * write:
129
+ * agent: writer
130
+ * execution:
131
+ * type: retry
132
+ * backoffs: [2, 8, 16, 35]
133
+ * jitter: 0.1
134
+ * on_error: error_state
135
+ * input:
136
+ * product: "{{ context.product }}"
137
+ * output_to_context:
138
+ * tagline: "{{ output.tagline }}"
139
+ * transitions:
140
+ * - to: review
141
+ *
142
+ * review:
143
+ * agent: critic
144
+ * input:
145
+ * tagline: "{{ context.tagline }}"
146
+ * output_to_context:
147
+ * score: "{{ output.score }}"
148
+ * round: "{{ context.round + 1 }}"
149
+ * transitions:
150
+ * - condition: "context.score >= 8"
151
+ * to: done
152
+ * - to: write
153
+ *
154
+ * done:
155
+ * type: final
156
+ * output:
157
+ * tagline: "{{ context.tagline }}"
158
+ *
159
+ * metadata:
160
+ * description: "Iterative writer-critic loop"
161
+ *
162
+ * PARALLEL EXECUTION EXAMPLE:
163
+ * ---------------------------
164
+ *
165
+ * states:
166
+ * parallel_review:
167
+ * machine: [legal_review, tech_review, finance_review]
168
+ * input:
169
+ * document: "{{ context.document }}"
170
+ * mode: settled
171
+ * timeout: 120
172
+ * output_to_context:
173
+ * reviews: "{{ output }}"
174
+ * transitions:
175
+ * - to: synthesize
176
+ *
177
+ * DYNAMIC PARALLELISM EXAMPLE:
178
+ * ----------------------------
179
+ *
180
+ * states:
181
+ * process_all:
182
+ * foreach: "{{ context.documents }}"
183
+ * as: doc
184
+ * key: "{{ doc.id }}"
185
+ * machine: doc_processor
186
+ * input:
187
+ * document: "{{ doc }}"
188
+ * mode: settled
189
+ * output_to_context:
190
+ * results: "{{ output }}"
191
+ * transitions:
192
+ * - to: aggregate
193
+ *
194
+ * LAUNCH (FIRE-AND-FORGET) EXAMPLE:
195
+ * ---------------------------------
196
+ *
197
+ * states:
198
+ * kickoff:
199
+ * launch: expensive_analysis
200
+ * launch_input:
201
+ * document: "{{ context.document }}"
202
+ * result_address: "results/{{ context.job_id }}"
203
+ * transitions:
204
+ * - to: continue_immediately
205
+ *
206
+ * PERSISTENCE (v0.2.0):
207
+ * --------------------
208
+ * MachineSnapshot - Wire format for checkpoints (execution_id, state, context, step)
209
+ * PersistenceConfig - Backend config: {enabled: true, backend: "local"|"memory"}
210
+ * checkpoint_on - Events to checkpoint: ["machine_start", "execute", "machine_end"]
211
+ *
212
+ * MACHINE LAUNCHING:
213
+ * ------------------
214
+ * States can launch peer machines via `machine:` field
215
+ * MachineReference - {path: "./peer.yml"} or {inline: {...}}
216
+ */
217
+
218
+ export const SPEC_VERSION = "0.4.0";
219
+
220
+ /**
221
+ * URI Scheme for FlatAgents
222
+ *
223
+ * Format: flatagents://{execution_id}[/{path}]
224
+ *
225
+ * Paths:
226
+ * /checkpoint - Machine state for resume
227
+ * /result - Final output after completion
228
+ *
229
+ * Examples:
230
+ * flatagents://550e8400-e29b-41d4-a716-446655440000/checkpoint
231
+ * flatagents://550e8400-e29b-41d4-a716-446655440000/result
232
+ *
233
+ * Each machine execution has a unique_id. Parent generates child's ID
234
+ * before launching, enabling parent to know where to read results without
235
+ * any child-to-parent messaging.
236
+ */
237
+
238
+ export interface MachineWrapper {
239
+ spec: "flatmachine";
240
+ spec_version: string;
241
+ data: MachineData;
242
+ metadata?: Record<string, any>;
243
+ }
244
+
245
+ export interface MachineData {
246
+ name?: string;
247
+ expression_engine?: "simple" | "cel";
248
+ context?: Record<string, any>;
249
+ agents?: Record<string, string | AgentWrapper>;
250
+ machines?: Record<string, string | MachineWrapper>;
251
+ states: Record<string, StateDefinition>;
252
+ settings?: MachineSettings;
253
+ persistence?: PersistenceConfig;
254
+ }
255
+
256
+ export interface MachineSettings {
257
+ hooks?: string;
258
+ max_steps?: number;
259
+ parallel_fallback?: "sequential" | "error";
260
+ [key: string]: any;
261
+ }
262
+
263
+ export interface StateDefinition {
264
+ type?: "initial" | "final";
265
+ agent?: string;
266
+ machine?: string | string[] | MachineInput[];
267
+ action?: string;
268
+ execution?: ExecutionConfig;
269
+ on_error?: string | Record<string, string>;
270
+ input?: Record<string, any>;
271
+ output_to_context?: Record<string, any>;
272
+ output?: Record<string, any>;
273
+ transitions?: Transition[];
274
+ tool_loop?: boolean;
275
+ sampling?: "single" | "multi";
276
+
277
+ // Dynamic parallelism (v0.4.0)
278
+ foreach?: string;
279
+ as?: string;
280
+ key?: string;
281
+
282
+ // Parallel options (v0.4.0)
283
+ mode?: "settled" | "any";
284
+ timeout?: number;
285
+
286
+ // Fire-and-forget (v0.4.0)
287
+ launch?: string | string[];
288
+ launch_input?: Record<string, any>;
289
+ }
290
+
291
+ /**
292
+ * Per-machine input configuration for parallel execution.
293
+ * Use when different machines need different inputs.
294
+ */
295
+ export interface MachineInput {
296
+ name: string;
297
+ input?: Record<string, any>;
298
+ }
299
+
300
+ export interface ExecutionConfig {
301
+ type: "default" | "retry" | "parallel" | "mdap_voting";
302
+ // Retry config
303
+ backoffs?: number[];
304
+ jitter?: number;
305
+ // Parallel config
306
+ n_samples?: number;
307
+ // MDAP voting config
308
+ k_margin?: number;
309
+ max_candidates?: number;
310
+ }
311
+
312
+ export interface Transition {
313
+ condition?: string;
314
+ to: string;
315
+ }
316
+
317
+ import { AgentWrapper, OutputSchema, ModelConfig } from "./flatagent";
318
+ export { AgentWrapper, OutputSchema };
319
+
320
+ export type FlatmachineConfig = MachineWrapper;
321
+
322
+ /**
323
+ * Launch intent for outbox pattern.
324
+ * Recorded in checkpoint before launching to ensure exactly-once semantics.
325
+ */
326
+ export interface LaunchIntent {
327
+ execution_id: string;
328
+ machine: string;
329
+ input: Record<string, any>;
330
+ launched: boolean;
331
+ }
332
+
333
+ export interface MachineSnapshot {
334
+ execution_id: string;
335
+ machine_name: string;
336
+ spec_version: string;
337
+ current_state: string;
338
+ context: Record<string, any>;
339
+ step: number;
340
+ created_at: string;
341
+ event?: string;
342
+ output?: Record<string, any>;
343
+ total_api_calls?: number;
344
+ total_cost?: number;
345
+
346
+ // Lineage (v0.4.0)
347
+ parent_execution_id?: string;
348
+
349
+ // Outbox pattern (v0.4.0)
350
+ pending_launches?: LaunchIntent[];
351
+ }
352
+
353
+ export interface PersistenceConfig {
354
+ enabled: boolean;
355
+ backend: "local" | "redis" | "memory" | string;
356
+ checkpoint_on?: string[];
357
+ [key: string]: any;
358
+ }
359
+
360
+ export interface MachineReference {
361
+ path?: string;
362
+ inline?: MachineWrapper;
363
+ }