flatagents 0.1.8__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.
- flatagents/__init__.py +93 -0
- flatagents/assets/__init__.py +0 -0
- flatagents/assets/flatagent.d.ts +181 -0
- flatagents/assets/flatagent.schema.json +211 -0
- flatagents/assets/flatagent.slim.d.ts +51 -0
- flatagents/assets/flatmachine.d.ts +176 -0
- flatagents/assets/flatmachine.schema.json +405 -0
- flatagents/assets/flatmachine.slim.d.ts +47 -0
- flatagents/baseagent.py +811 -0
- flatagents/execution.py +471 -0
- flatagents/expressions/__init__.py +60 -0
- flatagents/expressions/cel.py +101 -0
- flatagents/expressions/simple.py +166 -0
- flatagents/flatagent.py +702 -0
- flatagents/flatmachine.py +482 -0
- flatagents/hooks.py +270 -0
- flatagents/validation.py +141 -0
- flatagents-0.1.8.dist-info/METADATA +287 -0
- flatagents-0.1.8.dist-info/RECORD +20 -0
- flatagents-0.1.8.dist-info/WHEEL +4 -0
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* FlatMachine Configuration Schema v0.1.0
|
|
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 (e.g., "0.1.0")
|
|
15
|
+
* data - The machine configuration
|
|
16
|
+
* metadata - Extensibility layer
|
|
17
|
+
*
|
|
18
|
+
* DATA FIELDS:
|
|
19
|
+
* ------------
|
|
20
|
+
* name - Machine identifier
|
|
21
|
+
* expression_engine - "simple" (default) or "cel"
|
|
22
|
+
* context - Initial context values (Jinja2 templates)
|
|
23
|
+
* agents - Map of agent name to config file path or inline config
|
|
24
|
+
* states - Map of state name to state definition
|
|
25
|
+
* settings - Optional settings (hooks, etc.)
|
|
26
|
+
*
|
|
27
|
+
* STATE FIELDS:
|
|
28
|
+
* -------------
|
|
29
|
+
* type - "initial" or "final" (optional)
|
|
30
|
+
* agent - Agent name to execute (from agents map)
|
|
31
|
+
* execution - Execution type config: {type: "retry", backoffs: [...], jitter: 0.1}
|
|
32
|
+
* on_error - Error handling: "error_state" or {default: "...", ErrorType: "..."}
|
|
33
|
+
* action - Hook action to execute
|
|
34
|
+
* input - Input mapping (Jinja2 templates)
|
|
35
|
+
* output_to_context - Map agent output to context (Jinja2 templates)
|
|
36
|
+
* output - Final output (for final states)
|
|
37
|
+
* transitions - Ordered list of transitions
|
|
38
|
+
*
|
|
39
|
+
* TRANSITION FIELDS:
|
|
40
|
+
* ------------------
|
|
41
|
+
* condition - Expression to evaluate (optional, default: always true)
|
|
42
|
+
* to - Target state name
|
|
43
|
+
*
|
|
44
|
+
* EXPRESSION SYNTAX (Simple Mode):
|
|
45
|
+
* --------------------------------
|
|
46
|
+
* Comparisons: ==, !=, <, <=, >, >=
|
|
47
|
+
* Boolean: and, or, not
|
|
48
|
+
* Field access: context.field, input.field, output.field
|
|
49
|
+
* Literals: "string", 42, true, false, null
|
|
50
|
+
*
|
|
51
|
+
* Example: "context.score >= 8 and context.round < 4"
|
|
52
|
+
*
|
|
53
|
+
* EXPRESSION SYNTAX (CEL Mode):
|
|
54
|
+
* -----------------------------
|
|
55
|
+
* All simple syntax, plus:
|
|
56
|
+
* List macros: context.items.all(i, i > 0)
|
|
57
|
+
* String methods: context.name.startsWith("test")
|
|
58
|
+
* Timestamps: context.created > now - duration("24h")
|
|
59
|
+
*
|
|
60
|
+
* EXAMPLE CONFIGURATION:
|
|
61
|
+
* ----------------------
|
|
62
|
+
*
|
|
63
|
+
* spec: flatmachine
|
|
64
|
+
* spec_version: "0.1.0"
|
|
65
|
+
*
|
|
66
|
+
* data:
|
|
67
|
+
* name: writer-critic-loop
|
|
68
|
+
*
|
|
69
|
+
* context:
|
|
70
|
+
* product: "{{ input.product }}"
|
|
71
|
+
* score: 0
|
|
72
|
+
* round: 0
|
|
73
|
+
*
|
|
74
|
+
* agents:
|
|
75
|
+
* writer: ./writer.yml
|
|
76
|
+
* critic: ./critic.yml
|
|
77
|
+
*
|
|
78
|
+
* states:
|
|
79
|
+
* start:
|
|
80
|
+
* type: initial
|
|
81
|
+
* transitions:
|
|
82
|
+
* - to: write
|
|
83
|
+
*
|
|
84
|
+
* write:
|
|
85
|
+
* agent: writer
|
|
86
|
+
* execution:
|
|
87
|
+
* type: retry
|
|
88
|
+
* backoffs: [2, 8, 16, 35]
|
|
89
|
+
* jitter: 0.1
|
|
90
|
+
* on_error: error_state
|
|
91
|
+
* input:
|
|
92
|
+
* product: "{{ context.product }}"
|
|
93
|
+
* output_to_context:
|
|
94
|
+
* tagline: "{{ output.tagline }}"
|
|
95
|
+
* transitions:
|
|
96
|
+
* - to: review
|
|
97
|
+
*
|
|
98
|
+
* review:
|
|
99
|
+
* agent: critic
|
|
100
|
+
* input:
|
|
101
|
+
* tagline: "{{ context.tagline }}"
|
|
102
|
+
* output_to_context:
|
|
103
|
+
* score: "{{ output.score }}"
|
|
104
|
+
* round: "{{ context.round + 1 }}"
|
|
105
|
+
* transitions:
|
|
106
|
+
* - condition: "context.score >= 8"
|
|
107
|
+
* to: done
|
|
108
|
+
* - to: write
|
|
109
|
+
*
|
|
110
|
+
* done:
|
|
111
|
+
* type: final
|
|
112
|
+
* output:
|
|
113
|
+
* tagline: "{{ context.tagline }}"
|
|
114
|
+
* score: "{{ context.score }}"
|
|
115
|
+
*
|
|
116
|
+
* metadata:
|
|
117
|
+
* description: "Iterative writer-critic loop"
|
|
118
|
+
*/
|
|
119
|
+
|
|
120
|
+
export interface MachineWrapper {
|
|
121
|
+
spec: "flatmachine";
|
|
122
|
+
spec_version: string;
|
|
123
|
+
data: MachineData;
|
|
124
|
+
metadata?: Record<string, any>;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export interface MachineData {
|
|
128
|
+
name?: string;
|
|
129
|
+
expression_engine?: "simple" | "cel";
|
|
130
|
+
context?: Record<string, any>;
|
|
131
|
+
agents?: Record<string, string | AgentWrapper>;
|
|
132
|
+
states: Record<string, StateDefinition>;
|
|
133
|
+
settings?: MachineSettings;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export interface MachineSettings {
|
|
137
|
+
hooks?: string; // Python module path
|
|
138
|
+
max_steps?: number;
|
|
139
|
+
[key: string]: any;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export interface StateDefinition {
|
|
143
|
+
type?: "initial" | "final";
|
|
144
|
+
agent?: string;
|
|
145
|
+
action?: string;
|
|
146
|
+
execution?: ExecutionConfig;
|
|
147
|
+
on_error?: string | Record<string, string>; // Simple: "error_state" or Granular: {default: "...", ErrorType: "..."}
|
|
148
|
+
input?: Record<string, any>;
|
|
149
|
+
output_to_context?: Record<string, string>;
|
|
150
|
+
output?: Record<string, any>;
|
|
151
|
+
transitions?: Transition[];
|
|
152
|
+
tool_loop?: boolean;
|
|
153
|
+
sampling?: "single" | "multi";
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export interface ExecutionConfig {
|
|
157
|
+
type: "default" | "retry" | "parallel" | "mdap_voting";
|
|
158
|
+
// Retry config
|
|
159
|
+
backoffs?: number[]; // Delay array in seconds, e.g., [2, 8, 16, 35]
|
|
160
|
+
jitter?: number; // Random variation factor, e.g., 0.1 for ±10%
|
|
161
|
+
// Parallel config
|
|
162
|
+
n_samples?: number;
|
|
163
|
+
// MDAP voting config
|
|
164
|
+
k_margin?: number;
|
|
165
|
+
max_candidates?: number;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export interface Transition {
|
|
169
|
+
condition?: string;
|
|
170
|
+
to: string;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
import { AgentWrapper, OutputSchema, ModelConfig } from "./flatagent";
|
|
174
|
+
export { AgentWrapper, OutputSchema };
|
|
175
|
+
|
|
176
|
+
export type FlatmachineConfig = MachineWrapper;
|
|
@@ -0,0 +1,405 @@
|
|
|
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
|
+
"description": "FlatMachine Configuration Schema v0.1.0 =============================================\n\nA machine defines how agents are connected and executed: states, transitions, conditions, and loops.\n\nWhile flatagents defines WHAT each agent is (model + prompts + output schema), flatmachines defines HOW agents are connected and executed.\n\nSTRUCTURE:\n---------- spec - Fixed string \"flatmachine\" spec_version - Semver string (e.g., \"0.1.0\") data - The machine configuration metadata - Extensibility layer\n\nDATA FIELDS:\n------------ name - Machine identifier expression_engine - \"simple\" (default) or \"cel\" context - Initial context values (Jinja2 templates) agents - Map of agent name to config file path or inline config states - Map of state name to state definition settings - Optional settings (hooks, etc.)\n\nSTATE FIELDS:\n------------- type - \"initial\" or \"final\" (optional) agent - Agent name to execute (from agents map) execution - Execution type config: {type: \"retry\", backoffs: [...], jitter: 0.1} on_error - Error handling: \"error_state\" or {default: \"...\", ErrorType: \"...\"} action - Hook action to execute input - Input mapping (Jinja2 templates) output_to_context - Map agent output to context (Jinja2 templates) output - Final output (for final states) transitions - Ordered list of transitions\n\nTRANSITION FIELDS:\n------------------ condition - Expression to evaluate (optional, default: always true) to - Target state name\n\nEXPRESSION SYNTAX (Simple Mode):\n-------------------------------- Comparisons: ==, !=, <, <=, >, >= Boolean: and, or, not Field access: context.field, input.field, output.field Literals: \"string\", 42, true, false, null\n\nExample: \"context.score >= 8 and context.round < 4\"\n\nEXPRESSION SYNTAX (CEL Mode):\n----------------------------- All simple syntax, plus: List macros: context.items.all(i, i > 0) String methods: context.name.startsWith(\"test\") Timestamps: context.created > now - duration(\"24h\")\n\nEXAMPLE CONFIGURATION:\n----------------------\n\n spec: flatmachine spec_version: \"0.1.0\"\n\n data: name: writer-critic-loop\n\n context: product: \"{{ input.product }}\" score: 0 round: 0\n\n agents: writer: ./writer.yml critic: ./critic.yml\n\n states: start: type: initial transitions: - to: write\n\n write: agent: writer execution: type: retry backoffs: [2, 8, 16, 35] jitter: 0.1 on_error: error_state input: product: \"{{ context.product }}\" output_to_context: tagline: \"{{ output.tagline }}\" transitions: - to: review\n\n review: agent: critic input: tagline: \"{{ context.tagline }}\" output_to_context: score: \"{{ output.score }}\" round: \"{{ context.round + 1 }}\" transitions: - condition: \"context.score >= 8\" to: done - to: write\n\n done: type: final output: tagline: \"{{ context.tagline }}\" score: \"{{ context.score }}\"\n\n metadata: description: \"Iterative writer-critic loop\""
|
|
29
|
+
},
|
|
30
|
+
"MachineData": {
|
|
31
|
+
"type": "object",
|
|
32
|
+
"properties": {
|
|
33
|
+
"name": {
|
|
34
|
+
"type": "string"
|
|
35
|
+
},
|
|
36
|
+
"expression_engine": {
|
|
37
|
+
"type": "string",
|
|
38
|
+
"enum": [
|
|
39
|
+
"simple",
|
|
40
|
+
"cel"
|
|
41
|
+
]
|
|
42
|
+
},
|
|
43
|
+
"context": {
|
|
44
|
+
"type": "object"
|
|
45
|
+
},
|
|
46
|
+
"agents": {
|
|
47
|
+
"type": "object",
|
|
48
|
+
"additionalProperties": {
|
|
49
|
+
"anyOf": [
|
|
50
|
+
{
|
|
51
|
+
"type": "string"
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
"$ref": "#/definitions/AgentWrapper"
|
|
55
|
+
}
|
|
56
|
+
]
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
"states": {
|
|
60
|
+
"type": "object",
|
|
61
|
+
"additionalProperties": {
|
|
62
|
+
"$ref": "#/definitions/StateDefinition"
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
"settings": {
|
|
66
|
+
"$ref": "#/definitions/MachineSettings"
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
"required": [
|
|
70
|
+
"states"
|
|
71
|
+
],
|
|
72
|
+
"additionalProperties": false
|
|
73
|
+
},
|
|
74
|
+
"AgentWrapper": {
|
|
75
|
+
"type": "object",
|
|
76
|
+
"properties": {
|
|
77
|
+
"spec": {
|
|
78
|
+
"type": "string",
|
|
79
|
+
"const": "flatagent"
|
|
80
|
+
},
|
|
81
|
+
"spec_version": {
|
|
82
|
+
"type": "string"
|
|
83
|
+
},
|
|
84
|
+
"data": {
|
|
85
|
+
"$ref": "#/definitions/AgentData"
|
|
86
|
+
},
|
|
87
|
+
"metadata": {
|
|
88
|
+
"type": "object"
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
"required": [
|
|
92
|
+
"spec",
|
|
93
|
+
"spec_version",
|
|
94
|
+
"data"
|
|
95
|
+
],
|
|
96
|
+
"additionalProperties": false,
|
|
97
|
+
"description": "FlatAgents Configuration Schema v0.6.0 =============================================\n\nAn agent is a single LLM call: model + prompts + output schema. Workflows handle composition, branching, and loops.\n\nSTRUCTURE:\n---------- spec - Fixed string \"flatagents\" spec_version - Semver string (e.g., \"0.1.0\") data - The agent configuration metadata - Extensibility layer (runners ignore unrecognized keys)\n\nDATA FIELDS:\n------------ name - Agent identifier (inferred from filename if omitted) model - LLM configuration system - System prompt (Jinja2 template) user - User prompt template (Jinja2) instruction_suffix - Optional instruction appended after user prompt output - Output schema (what fields we want) mcp - Optional MCP (Model Context Protocol) configuration\n\nMCP FIELDS:\n----------- servers - Map of server name to MCPServerDef tool_filter - Optional allow/deny lists using \"server:tool\" format tool_prompt - Jinja2 template for tool prompt (uses {{ tools }} variable)\n\nMODEL FIELDS:\n------------- name - Model name (e.g., \"gpt-4\", \"zai-glm-4.6\") provider - Provider name (e.g., \"openai\", \"anthropic\", \"cerebras\") temperature - Sampling temperature (0.0 to 2.0) max_tokens - Maximum tokens to generate top_p - Nucleus sampling parameter frequency_penalty - Frequency penalty (-2.0 to 2.0) presence_penalty - Presence penalty (-2.0 to 2.0)\n\nOUTPUT FIELD DEFINITION:\n------------------------ type - Field type: str, int, float, bool, json, list, object description - Description (used for structured output / tool calls) enum - Allowed values (for enum-like fields) required - Whether the field is required (default: true) items - For list type: the type of items properties - For object type: nested properties\n\nTEMPLATE SYNTAX:\n---------------- Prompts use Jinja2 templating. Available variables: - input.* - Values passed to the agent at runtime\n\nExample: \"Question: {{ input.question }}\"\n\nEXAMPLE CONFIGURATION:\n----------------------\n\n spec: flatagents spec_version: \"0.6.0\"\n\n data: name: critic\n\n model: provider: cerebras name: zai-glm-4.6 temperature: 0.5\n\n system: | Act as a ruthless critic. Analyze drafts for errors. Rate severity as: High, Medium, or Low.\n\n user: | Question: {{ input.question }} Draft: {{ input.draft }}\n\n output: critique: type: str description: \"Specific errors found in the draft\" severity: type: str description: \"Error severity\" enum: [\"High\", \"Medium\", \"Low\"]\n\n metadata: description: \"Critiques draft answers\" tags: [\"reflection\", \"qa\"]\n\nMCPCONFIG:\n---------- MCP (Model Context Protocol) configuration. Defines MCP servers and tool filtering rules. servers - MCP server definitions, keyed by server name tool_filter - Optional tool filtering rules tool_prompt - Jinja2 template for tool prompt injection. Available variables: tools (list of discovered tools) Example: \"{% for tool in tools %}{{ tool.name }}: {{ tool.description }}{% endfor %}\"\n\nMCPSERVERDEF:\n------------- MCP server definition. Supports stdio transport (command) or HTTP transport (server_url). Stdio transport: command - Command to start the MCP server (e.g., \"npx\", \"python\") args - Arguments for the command env - Environment variables for the server process HTTP transport: server_url - Base URL of the MCP server (e.g., \"http://localhost:8000\") headers - HTTP headers (e.g., for authentication) timeout - Request timeout in seconds\n\nTOOLFILTER:\n----------- Tool filtering rules using \"server:tool\" format. Supports wildcards: \"server:*\" matches all tools from a server. allow - Tools to allow (if specified, only these are included) deny - Tools to deny (takes precedence over allow)"
|
|
98
|
+
},
|
|
99
|
+
"AgentData": {
|
|
100
|
+
"type": "object",
|
|
101
|
+
"properties": {
|
|
102
|
+
"name": {
|
|
103
|
+
"type": "string"
|
|
104
|
+
},
|
|
105
|
+
"model": {
|
|
106
|
+
"$ref": "#/definitions/ModelConfig"
|
|
107
|
+
},
|
|
108
|
+
"system": {
|
|
109
|
+
"type": "string"
|
|
110
|
+
},
|
|
111
|
+
"user": {
|
|
112
|
+
"type": "string"
|
|
113
|
+
},
|
|
114
|
+
"instruction_suffix": {
|
|
115
|
+
"type": "string"
|
|
116
|
+
},
|
|
117
|
+
"output": {
|
|
118
|
+
"$ref": "#/definitions/OutputSchema"
|
|
119
|
+
},
|
|
120
|
+
"mcp": {
|
|
121
|
+
"$ref": "#/definitions/MCPConfig"
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
"required": [
|
|
125
|
+
"model",
|
|
126
|
+
"system",
|
|
127
|
+
"user"
|
|
128
|
+
],
|
|
129
|
+
"additionalProperties": false
|
|
130
|
+
},
|
|
131
|
+
"ModelConfig": {
|
|
132
|
+
"type": "object",
|
|
133
|
+
"properties": {
|
|
134
|
+
"name": {
|
|
135
|
+
"type": "string"
|
|
136
|
+
},
|
|
137
|
+
"provider": {
|
|
138
|
+
"type": "string"
|
|
139
|
+
},
|
|
140
|
+
"temperature": {
|
|
141
|
+
"type": "number"
|
|
142
|
+
},
|
|
143
|
+
"max_tokens": {
|
|
144
|
+
"type": "number"
|
|
145
|
+
},
|
|
146
|
+
"top_p": {
|
|
147
|
+
"type": "number"
|
|
148
|
+
},
|
|
149
|
+
"frequency_penalty": {
|
|
150
|
+
"type": "number"
|
|
151
|
+
},
|
|
152
|
+
"presence_penalty": {
|
|
153
|
+
"type": "number"
|
|
154
|
+
}
|
|
155
|
+
},
|
|
156
|
+
"required": [
|
|
157
|
+
"name"
|
|
158
|
+
],
|
|
159
|
+
"additionalProperties": false
|
|
160
|
+
},
|
|
161
|
+
"OutputSchema": {
|
|
162
|
+
"type": "object",
|
|
163
|
+
"additionalProperties": {
|
|
164
|
+
"$ref": "#/definitions/OutputFieldDef"
|
|
165
|
+
}
|
|
166
|
+
},
|
|
167
|
+
"OutputFieldDef": {
|
|
168
|
+
"type": "object",
|
|
169
|
+
"properties": {
|
|
170
|
+
"type": {
|
|
171
|
+
"type": "string",
|
|
172
|
+
"enum": [
|
|
173
|
+
"str",
|
|
174
|
+
"int",
|
|
175
|
+
"float",
|
|
176
|
+
"bool",
|
|
177
|
+
"json",
|
|
178
|
+
"list",
|
|
179
|
+
"object"
|
|
180
|
+
]
|
|
181
|
+
},
|
|
182
|
+
"description": {
|
|
183
|
+
"type": "string"
|
|
184
|
+
},
|
|
185
|
+
"enum": {
|
|
186
|
+
"type": "array",
|
|
187
|
+
"items": {
|
|
188
|
+
"type": "string"
|
|
189
|
+
}
|
|
190
|
+
},
|
|
191
|
+
"required": {
|
|
192
|
+
"type": "boolean"
|
|
193
|
+
},
|
|
194
|
+
"items": {
|
|
195
|
+
"$ref": "#/definitions/OutputFieldDef"
|
|
196
|
+
},
|
|
197
|
+
"properties": {
|
|
198
|
+
"$ref": "#/definitions/OutputSchema"
|
|
199
|
+
}
|
|
200
|
+
},
|
|
201
|
+
"required": [
|
|
202
|
+
"type"
|
|
203
|
+
],
|
|
204
|
+
"additionalProperties": false
|
|
205
|
+
},
|
|
206
|
+
"MCPConfig": {
|
|
207
|
+
"type": "object",
|
|
208
|
+
"properties": {
|
|
209
|
+
"servers": {
|
|
210
|
+
"type": "object",
|
|
211
|
+
"additionalProperties": {
|
|
212
|
+
"$ref": "#/definitions/MCPServerDef"
|
|
213
|
+
}
|
|
214
|
+
},
|
|
215
|
+
"tool_filter": {
|
|
216
|
+
"$ref": "#/definitions/ToolFilter"
|
|
217
|
+
},
|
|
218
|
+
"tool_prompt": {
|
|
219
|
+
"type": "string"
|
|
220
|
+
}
|
|
221
|
+
},
|
|
222
|
+
"required": [
|
|
223
|
+
"servers",
|
|
224
|
+
"tool_prompt"
|
|
225
|
+
],
|
|
226
|
+
"additionalProperties": false
|
|
227
|
+
},
|
|
228
|
+
"MCPServerDef": {
|
|
229
|
+
"type": "object",
|
|
230
|
+
"properties": {
|
|
231
|
+
"command": {
|
|
232
|
+
"type": "string"
|
|
233
|
+
},
|
|
234
|
+
"args": {
|
|
235
|
+
"type": "array",
|
|
236
|
+
"items": {
|
|
237
|
+
"type": "string"
|
|
238
|
+
}
|
|
239
|
+
},
|
|
240
|
+
"env": {
|
|
241
|
+
"type": "object",
|
|
242
|
+
"additionalProperties": {
|
|
243
|
+
"type": "string"
|
|
244
|
+
}
|
|
245
|
+
},
|
|
246
|
+
"server_url": {
|
|
247
|
+
"type": "string"
|
|
248
|
+
},
|
|
249
|
+
"headers": {
|
|
250
|
+
"type": "object",
|
|
251
|
+
"additionalProperties": {
|
|
252
|
+
"type": "string"
|
|
253
|
+
}
|
|
254
|
+
},
|
|
255
|
+
"timeout": {
|
|
256
|
+
"type": "number"
|
|
257
|
+
}
|
|
258
|
+
},
|
|
259
|
+
"additionalProperties": false
|
|
260
|
+
},
|
|
261
|
+
"ToolFilter": {
|
|
262
|
+
"type": "object",
|
|
263
|
+
"properties": {
|
|
264
|
+
"allow": {
|
|
265
|
+
"type": "array",
|
|
266
|
+
"items": {
|
|
267
|
+
"type": "string"
|
|
268
|
+
}
|
|
269
|
+
},
|
|
270
|
+
"deny": {
|
|
271
|
+
"type": "array",
|
|
272
|
+
"items": {
|
|
273
|
+
"type": "string"
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
},
|
|
277
|
+
"additionalProperties": false
|
|
278
|
+
},
|
|
279
|
+
"StateDefinition": {
|
|
280
|
+
"type": "object",
|
|
281
|
+
"properties": {
|
|
282
|
+
"type": {
|
|
283
|
+
"type": "string",
|
|
284
|
+
"enum": [
|
|
285
|
+
"initial",
|
|
286
|
+
"final"
|
|
287
|
+
]
|
|
288
|
+
},
|
|
289
|
+
"agent": {
|
|
290
|
+
"type": "string"
|
|
291
|
+
},
|
|
292
|
+
"action": {
|
|
293
|
+
"type": "string"
|
|
294
|
+
},
|
|
295
|
+
"execution": {
|
|
296
|
+
"$ref": "#/definitions/ExecutionConfig"
|
|
297
|
+
},
|
|
298
|
+
"on_error": {
|
|
299
|
+
"anyOf": [
|
|
300
|
+
{
|
|
301
|
+
"type": "string"
|
|
302
|
+
},
|
|
303
|
+
{
|
|
304
|
+
"type": "object",
|
|
305
|
+
"additionalProperties": {
|
|
306
|
+
"type": "string"
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
]
|
|
310
|
+
},
|
|
311
|
+
"input": {
|
|
312
|
+
"type": "object"
|
|
313
|
+
},
|
|
314
|
+
"output_to_context": {
|
|
315
|
+
"type": "object",
|
|
316
|
+
"additionalProperties": {
|
|
317
|
+
"type": "string"
|
|
318
|
+
}
|
|
319
|
+
},
|
|
320
|
+
"output": {
|
|
321
|
+
"type": "object"
|
|
322
|
+
},
|
|
323
|
+
"transitions": {
|
|
324
|
+
"type": "array",
|
|
325
|
+
"items": {
|
|
326
|
+
"$ref": "#/definitions/Transition"
|
|
327
|
+
}
|
|
328
|
+
},
|
|
329
|
+
"tool_loop": {
|
|
330
|
+
"type": "boolean"
|
|
331
|
+
},
|
|
332
|
+
"sampling": {
|
|
333
|
+
"type": "string",
|
|
334
|
+
"enum": [
|
|
335
|
+
"single",
|
|
336
|
+
"multi"
|
|
337
|
+
]
|
|
338
|
+
}
|
|
339
|
+
},
|
|
340
|
+
"additionalProperties": false
|
|
341
|
+
},
|
|
342
|
+
"ExecutionConfig": {
|
|
343
|
+
"type": "object",
|
|
344
|
+
"properties": {
|
|
345
|
+
"type": {
|
|
346
|
+
"type": "string",
|
|
347
|
+
"enum": [
|
|
348
|
+
"default",
|
|
349
|
+
"retry",
|
|
350
|
+
"parallel",
|
|
351
|
+
"mdap_voting"
|
|
352
|
+
]
|
|
353
|
+
},
|
|
354
|
+
"backoffs": {
|
|
355
|
+
"type": "array",
|
|
356
|
+
"items": {
|
|
357
|
+
"type": "number"
|
|
358
|
+
}
|
|
359
|
+
},
|
|
360
|
+
"jitter": {
|
|
361
|
+
"type": "number"
|
|
362
|
+
},
|
|
363
|
+
"n_samples": {
|
|
364
|
+
"type": "number"
|
|
365
|
+
},
|
|
366
|
+
"k_margin": {
|
|
367
|
+
"type": "number"
|
|
368
|
+
},
|
|
369
|
+
"max_candidates": {
|
|
370
|
+
"type": "number"
|
|
371
|
+
}
|
|
372
|
+
},
|
|
373
|
+
"required": [
|
|
374
|
+
"type"
|
|
375
|
+
],
|
|
376
|
+
"additionalProperties": false
|
|
377
|
+
},
|
|
378
|
+
"Transition": {
|
|
379
|
+
"type": "object",
|
|
380
|
+
"properties": {
|
|
381
|
+
"condition": {
|
|
382
|
+
"type": "string"
|
|
383
|
+
},
|
|
384
|
+
"to": {
|
|
385
|
+
"type": "string"
|
|
386
|
+
}
|
|
387
|
+
},
|
|
388
|
+
"required": [
|
|
389
|
+
"to"
|
|
390
|
+
],
|
|
391
|
+
"additionalProperties": false
|
|
392
|
+
},
|
|
393
|
+
"MachineSettings": {
|
|
394
|
+
"type": "object",
|
|
395
|
+
"properties": {
|
|
396
|
+
"hooks": {
|
|
397
|
+
"type": "string"
|
|
398
|
+
},
|
|
399
|
+
"max_steps": {
|
|
400
|
+
"type": "number"
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
export interface MachineWrapper {
|
|
2
|
+
spec: "flatmachine";
|
|
3
|
+
spec_version: string;
|
|
4
|
+
data: MachineData;
|
|
5
|
+
metadata?: Record<string, any>;
|
|
6
|
+
}
|
|
7
|
+
export interface MachineData {
|
|
8
|
+
name?: string;
|
|
9
|
+
expression_engine?: "simple" | "cel";
|
|
10
|
+
context?: Record<string, any>;
|
|
11
|
+
agents?: Record<string, string | AgentWrapper>;
|
|
12
|
+
states: Record<string, StateDefinition>;
|
|
13
|
+
settings?: MachineSettings;
|
|
14
|
+
}
|
|
15
|
+
export interface MachineSettings {
|
|
16
|
+
hooks?: string;
|
|
17
|
+
max_steps?: number;
|
|
18
|
+
[key: string]: any;
|
|
19
|
+
}
|
|
20
|
+
export interface StateDefinition {
|
|
21
|
+
type?: "initial" | "final";
|
|
22
|
+
agent?: string;
|
|
23
|
+
action?: string;
|
|
24
|
+
execution?: ExecutionConfig;
|
|
25
|
+
on_error?: string | Record<string, string>;
|
|
26
|
+
input?: Record<string, any>;
|
|
27
|
+
output_to_context?: Record<string, string>;
|
|
28
|
+
output?: Record<string, any>;
|
|
29
|
+
transitions?: Transition[];
|
|
30
|
+
tool_loop?: boolean;
|
|
31
|
+
sampling?: "single" | "multi";
|
|
32
|
+
}
|
|
33
|
+
export interface ExecutionConfig {
|
|
34
|
+
type: "default" | "retry" | "parallel" | "mdap_voting";
|
|
35
|
+
backoffs?: number[];
|
|
36
|
+
jitter?: number;
|
|
37
|
+
n_samples?: number;
|
|
38
|
+
k_margin?: number;
|
|
39
|
+
max_candidates?: number;
|
|
40
|
+
}
|
|
41
|
+
export interface Transition {
|
|
42
|
+
condition?: string;
|
|
43
|
+
to: string;
|
|
44
|
+
}
|
|
45
|
+
import { AgentWrapper, OutputSchema, ModelConfig } from "./flatagent";
|
|
46
|
+
export { AgentWrapper, OutputSchema };
|
|
47
|
+
export type FlatmachineConfig = MachineWrapper;
|