quantalogic 0.35.0__py3-none-any.whl → 0.50.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.
- quantalogic/__init__.py +0 -4
- quantalogic/agent.py +603 -363
- quantalogic/agent_config.py +233 -46
- quantalogic/agent_factory.py +34 -22
- quantalogic/coding_agent.py +16 -14
- quantalogic/config.py +2 -1
- quantalogic/console_print_events.py +4 -8
- quantalogic/console_print_token.py +2 -2
- quantalogic/docs_cli.py +15 -10
- quantalogic/event_emitter.py +258 -83
- quantalogic/flow/__init__.py +23 -0
- quantalogic/flow/flow.py +595 -0
- quantalogic/flow/flow_extractor.py +672 -0
- quantalogic/flow/flow_generator.py +89 -0
- quantalogic/flow/flow_manager.py +407 -0
- quantalogic/flow/flow_manager_schema.py +169 -0
- quantalogic/flow/flow_yaml.md +419 -0
- quantalogic/generative_model.py +109 -77
- quantalogic/get_model_info.py +5 -5
- quantalogic/interactive_text_editor.py +100 -73
- quantalogic/main.py +17 -21
- quantalogic/model_info_list.py +3 -3
- quantalogic/model_info_litellm.py +14 -14
- quantalogic/prompts.py +2 -1
- quantalogic/{llm.py → quantlitellm.py} +29 -39
- quantalogic/search_agent.py +4 -4
- quantalogic/server/models.py +4 -1
- quantalogic/task_file_reader.py +5 -5
- quantalogic/task_runner.py +20 -20
- quantalogic/tool_manager.py +10 -21
- quantalogic/tools/__init__.py +98 -68
- quantalogic/tools/composio/composio.py +416 -0
- quantalogic/tools/{generate_database_report_tool.py → database/generate_database_report_tool.py} +4 -9
- quantalogic/tools/database/sql_query_tool_advanced.py +261 -0
- quantalogic/tools/document_tools/markdown_to_docx_tool.py +620 -0
- quantalogic/tools/document_tools/markdown_to_epub_tool.py +438 -0
- quantalogic/tools/document_tools/markdown_to_html_tool.py +362 -0
- quantalogic/tools/document_tools/markdown_to_ipynb_tool.py +319 -0
- quantalogic/tools/document_tools/markdown_to_latex_tool.py +420 -0
- quantalogic/tools/document_tools/markdown_to_pdf_tool.py +623 -0
- quantalogic/tools/document_tools/markdown_to_pptx_tool.py +319 -0
- quantalogic/tools/duckduckgo_search_tool.py +2 -4
- quantalogic/tools/finance/alpha_vantage_tool.py +440 -0
- quantalogic/tools/finance/ccxt_tool.py +373 -0
- quantalogic/tools/finance/finance_llm_tool.py +387 -0
- quantalogic/tools/finance/google_finance.py +192 -0
- quantalogic/tools/finance/market_intelligence_tool.py +520 -0
- quantalogic/tools/finance/technical_analysis_tool.py +491 -0
- quantalogic/tools/finance/tradingview_tool.py +336 -0
- quantalogic/tools/finance/yahoo_finance.py +236 -0
- quantalogic/tools/git/bitbucket_clone_repo_tool.py +181 -0
- quantalogic/tools/git/bitbucket_operations_tool.py +326 -0
- quantalogic/tools/git/clone_repo_tool.py +189 -0
- quantalogic/tools/git/git_operations_tool.py +532 -0
- quantalogic/tools/google_packages/google_news_tool.py +480 -0
- quantalogic/tools/grep_app_tool.py +123 -186
- quantalogic/tools/{dalle_e.py → image_generation/dalle_e.py} +37 -27
- quantalogic/tools/jinja_tool.py +6 -10
- quantalogic/tools/language_handlers/__init__.py +22 -9
- quantalogic/tools/list_directory_tool.py +131 -42
- quantalogic/tools/llm_tool.py +45 -15
- quantalogic/tools/llm_vision_tool.py +59 -7
- quantalogic/tools/markitdown_tool.py +17 -5
- quantalogic/tools/nasa_packages/models.py +47 -0
- quantalogic/tools/nasa_packages/nasa_apod_tool.py +232 -0
- quantalogic/tools/nasa_packages/nasa_neows_tool.py +147 -0
- quantalogic/tools/nasa_packages/services.py +82 -0
- quantalogic/tools/presentation_tools/presentation_llm_tool.py +396 -0
- quantalogic/tools/product_hunt/product_hunt_tool.py +258 -0
- quantalogic/tools/product_hunt/services.py +63 -0
- quantalogic/tools/rag_tool/__init__.py +48 -0
- quantalogic/tools/rag_tool/document_metadata.py +15 -0
- quantalogic/tools/rag_tool/query_response.py +20 -0
- quantalogic/tools/rag_tool/rag_tool.py +566 -0
- quantalogic/tools/rag_tool/rag_tool_beta.py +264 -0
- quantalogic/tools/read_html_tool.py +24 -38
- quantalogic/tools/replace_in_file_tool.py +10 -10
- quantalogic/tools/safe_python_interpreter_tool.py +10 -24
- quantalogic/tools/search_definition_names.py +2 -2
- quantalogic/tools/sequence_tool.py +14 -23
- quantalogic/tools/sql_query_tool.py +17 -19
- quantalogic/tools/tool.py +39 -15
- quantalogic/tools/unified_diff_tool.py +1 -1
- quantalogic/tools/utilities/csv_processor_tool.py +234 -0
- quantalogic/tools/utilities/download_file_tool.py +179 -0
- quantalogic/tools/utilities/mermaid_validator_tool.py +661 -0
- quantalogic/tools/utils/__init__.py +1 -4
- quantalogic/tools/utils/create_sample_database.py +24 -38
- quantalogic/tools/utils/generate_database_report.py +74 -82
- quantalogic/tools/wikipedia_search_tool.py +17 -21
- quantalogic/utils/ask_user_validation.py +1 -1
- quantalogic/utils/async_utils.py +35 -0
- quantalogic/utils/check_version.py +3 -5
- quantalogic/utils/get_all_models.py +2 -1
- quantalogic/utils/git_ls.py +21 -7
- quantalogic/utils/lm_studio_model_info.py +9 -7
- quantalogic/utils/python_interpreter.py +113 -43
- quantalogic/utils/xml_utility.py +178 -0
- quantalogic/version_check.py +1 -1
- quantalogic/welcome_message.py +7 -7
- quantalogic/xml_parser.py +0 -1
- {quantalogic-0.35.0.dist-info → quantalogic-0.50.0.dist-info}/METADATA +40 -1
- quantalogic-0.50.0.dist-info/RECORD +148 -0
- quantalogic-0.35.0.dist-info/RECORD +0 -102
- {quantalogic-0.35.0.dist-info → quantalogic-0.50.0.dist-info}/LICENSE +0 -0
- {quantalogic-0.35.0.dist-info → quantalogic-0.50.0.dist-info}/WHEEL +0 -0
- {quantalogic-0.35.0.dist-info → quantalogic-0.50.0.dist-info}/entry_points.txt +0 -0
@@ -0,0 +1,419 @@
|
|
1
|
+
# Quantalogic Flow YAML DSL Specification
|
2
|
+
|
3
|
+
## 1. Introduction
|
4
|
+
|
5
|
+
The Quantalogic Flow YAML DSL (Domain Specific Language) offers a structured and human-readable way to define workflows. As of February 23, 2025, it provides a rich set of features for complex automation, including:
|
6
|
+
|
7
|
+
* **Function Execution**: Executes asynchronous Python functions, either embedded directly or sourced from PyPI packages, local files, or remote URLs.
|
8
|
+
* **Execution Flow**: Supports sequential, conditional, and parallel transitions between nodes.
|
9
|
+
* **Sub-Workflows**: Enables hierarchical workflows through nested sub-workflows.
|
10
|
+
* **LLM Integration**: Incorporates Large Language Model (LLM) nodes with plain text (`llm_node`) or structured output (`structured_llm_node`), using configurable prompts and parameters.
|
11
|
+
* **Context Management**: Maintains state across nodes using a shared context dictionary.
|
12
|
+
* **Robustness**: Provides configurable retries and timeouts for fault-tolerant execution.
|
13
|
+
* **Programmatic Control**: Managed via the `WorkflowManager` class for dynamic creation and execution.
|
14
|
+
|
15
|
+
This DSL seamlessly integrates with the `Workflow`, `WorkflowEngine`, and `WorkflowManager` classes from the `quantalogic.flow` package, and it leverages the `Nodes` class for LLM functionality to minimize redundancy.
|
16
|
+
|
17
|
+
## 2. Workflow Structure
|
18
|
+
|
19
|
+
A YAML workflow file consists of three main sections:
|
20
|
+
|
21
|
+
* **`functions`**: Defines Python functions used by nodes, supporting both inline code and external modules.
|
22
|
+
* **`nodes`**: Configures individual tasks, linking to functions, sub-workflows, or LLM setups.
|
23
|
+
* **`workflow`**: Specifies the execution flow, including the start node and transitions.
|
24
|
+
|
25
|
+
```yaml
|
26
|
+
functions:
|
27
|
+
# Function definitions
|
28
|
+
nodes:
|
29
|
+
# Node configurations
|
30
|
+
workflow:
|
31
|
+
# Start node and transitions
|
32
|
+
```
|
33
|
+
|
34
|
+
```mermaid
|
35
|
+
graph LR
|
36
|
+
A[YAML Workflow File] --> B(functions);
|
37
|
+
A --> C(nodes);
|
38
|
+
A --> D(workflow);
|
39
|
+
style A fill:#f9f,stroke:#333,stroke-width:2px
|
40
|
+
```
|
41
|
+
|
42
|
+
## 3. Functions
|
43
|
+
|
44
|
+
The `functions` section maps function names to their implementations, which can be embedded in the YAML or sourced externally from Python modules.
|
45
|
+
|
46
|
+
**Fields**
|
47
|
+
|
48
|
+
* `type` (string, required): Specifies the function source. Options:
|
49
|
+
* `"embedded"`: Inline Python code.
|
50
|
+
* `"external"`: Module-based function.
|
51
|
+
* `code` (string, optional): Multi-line asynchronous Python code for embedded functions. Required if `type: embedded`.
|
52
|
+
* `module` (string, optional): Source of the external module for external functions. Can be:
|
53
|
+
* A PyPI package name (e.g., `"requests"`, `"numpy"`).
|
54
|
+
* A local file path (e.g., `"/path/to/module.py"`).
|
55
|
+
* A remote URL (e.g., `"https://example.com/module.py"`). Required if `type: external`.
|
56
|
+
* `function` (string, optional): Name of the function within the module for external functions. Required if `type: external`.
|
57
|
+
|
58
|
+
**Rules**
|
59
|
+
|
60
|
+
* Embedded functions must be asynchronous (using `async def`) and match the dictionary key name.
|
61
|
+
* External functions require both `module` and `function` fields; `code` must not be present.
|
62
|
+
* For PyPI modules, ensure the package is installed in the Python environment (e.g., via `pip install <module>`).
|
63
|
+
|
64
|
+
**Examples**
|
65
|
+
|
66
|
+
* **Embedded Function**
|
67
|
+
|
68
|
+
```yaml
|
69
|
+
functions:
|
70
|
+
validate_order:
|
71
|
+
type: embedded
|
72
|
+
code: |
|
73
|
+
async def validate_order(order: dict) -> bool:
|
74
|
+
await asyncio.sleep(1)
|
75
|
+
return bool(order.get("items"))
|
76
|
+
```
|
77
|
+
|
78
|
+
* **External Function from PyPI**
|
79
|
+
|
80
|
+
```yaml
|
81
|
+
functions:
|
82
|
+
fetch_data:
|
83
|
+
type: external
|
84
|
+
module: requests
|
85
|
+
function: get
|
86
|
+
```
|
87
|
+
|
88
|
+
Note: Requires `pip install requests` if not already installed.
|
89
|
+
|
90
|
+
* **External Function from Local File**
|
91
|
+
|
92
|
+
```yaml
|
93
|
+
functions:
|
94
|
+
process_data:
|
95
|
+
type: external
|
96
|
+
module: /path/to/my_module.py
|
97
|
+
function: process
|
98
|
+
```
|
99
|
+
|
100
|
+
* **External Function from URL**
|
101
|
+
|
102
|
+
```yaml
|
103
|
+
functions:
|
104
|
+
analyze:
|
105
|
+
type: external
|
106
|
+
module: https://example.com/analyze.py
|
107
|
+
function: analyze_data
|
108
|
+
```
|
109
|
+
|
110
|
+
```mermaid
|
111
|
+
graph LR
|
112
|
+
A[Function Definition] --> B{Type: embedded/external};
|
113
|
+
B -- embedded --> C["Code (async def ...)"];
|
114
|
+
B -- external --> D[Module: PyPI, Path, or URL];
|
115
|
+
D --> E[Function Name];
|
116
|
+
style A fill:#ccf,stroke:#333,stroke-width:2px
|
117
|
+
```
|
118
|
+
|
119
|
+
## 4. Nodes
|
120
|
+
|
121
|
+
Nodes represent individual tasks within the workflow, configurable as function executions, sub-workflows, or LLM operations.
|
122
|
+
|
123
|
+
**Fields**
|
124
|
+
|
125
|
+
* `function` (string, optional): References a function from the `functions` section. Mutually exclusive with `sub_workflow` and `llm_config`.
|
126
|
+
* `sub_workflow` (object, optional): Defines a nested workflow. Mutually exclusive with `function` and `llm_config`.
|
127
|
+
* `start` (string, required): Starting node of the sub-workflow.
|
128
|
+
* `transitions` (list): Transition rules (see Workflow section).
|
129
|
+
* `llm_config` (object, optional): Configures an LLM-based node. Mutually exclusive with `function` and `sub_workflow`.
|
130
|
+
* `model` (string, optional, default: `"gpt-3.5-turbo"`): LLM model (e.g., `"gemini/gemini-2.0-flash"`, `"gro k/xai"`).
|
131
|
+
* `system_prompt` (string, optional): Defines the LLM’s role or context.
|
132
|
+
* `prompt_template` (string, required, default: `"{{ input }}"`): Jinja2 template for the user prompt (e.g., `"Summarize {{ text }}"`).
|
133
|
+
* `temperature` (float, optional, default: `0.7`): Randomness control (`0.0` to `1.0`).
|
134
|
+
* `max_tokens` (integer, optional, default: `2000`): Maximum response tokens.
|
135
|
+
* `top_p` (float, optional, default: `1.0`): Nucleus sampling (`0.0` to `1.0`).
|
136
|
+
* `presence_penalty` (float, optional, default: `0.0`): Penalizes repetition (`-2.0` to `2.0`).
|
137
|
+
* `frequency_penalty` (float, optional, default: `0.0`): Reduces word repetition (`-2.0` to `2.0`).
|
138
|
+
* `stop` (list of strings, optional): Stop sequences (e.g., `["\n"]`).
|
139
|
+
* `response_model` (string, optional): Pydantic model path for structured output (e.g., `"my_module:OrderDetails"`). If present, uses `structured_llm_node`; otherwise, uses `llm_node`.
|
140
|
+
* `api_key` (string, optional): Custom API key for the LLM provider.
|
141
|
+
* `output` (string, optional): Context key for the node’s result. Defaults to `"<node_name>_result"` for function or LLM nodes if unspecified.
|
142
|
+
* `retries` (integer, optional, default: `3`): Number of retry attempts on failure (≥ `0`).
|
143
|
+
* `delay` (float, optional, default: `1.0`): Delay between retries in seconds (≥ `0`).
|
144
|
+
* `timeout` (float or null, optional, default: `null`): Execution timeout in seconds (≥ `0` or `null` for no timeout).
|
145
|
+
* `parallel` (boolean, optional, default: `false`): Enables parallel execution with other nodes.
|
146
|
+
|
147
|
+
**Rules**
|
148
|
+
|
149
|
+
* Each node must specify exactly one of `function`, `sub_workflow`, or `llm_config`.
|
150
|
+
* For `sub_workflow`, `output` is optional if the sub-workflow sets multiple context keys; inputs are derived from the start node’s requirements.
|
151
|
+
* For `llm_config`, inputs are extracted from `prompt_template` placeholders (e.g., `{{ text }}` implies `text` as an input).
|
152
|
+
|
153
|
+
**Examples**
|
154
|
+
|
155
|
+
* **Function Node**
|
156
|
+
|
157
|
+
```yaml
|
158
|
+
nodes:
|
159
|
+
validate:
|
160
|
+
function: validate_order
|
161
|
+
output: is_valid
|
162
|
+
retries: 2
|
163
|
+
delay: 0.5
|
164
|
+
timeout: 5.0
|
165
|
+
```
|
166
|
+
|
167
|
+
* **Sub-Workflow Node**
|
168
|
+
|
169
|
+
```yaml
|
170
|
+
nodes:
|
171
|
+
payment_shipping:
|
172
|
+
sub_workflow:
|
173
|
+
start: payment
|
174
|
+
transitions:
|
175
|
+
- from: payment
|
176
|
+
to: shipping
|
177
|
+
output: shipping_confirmation
|
178
|
+
```
|
179
|
+
|
180
|
+
* **Plain LLM Node**
|
181
|
+
|
182
|
+
```yaml
|
183
|
+
nodes:
|
184
|
+
summarize:
|
185
|
+
llm_config:
|
186
|
+
model: "gro k/xai"
|
187
|
+
system_prompt: "You are a concise summarizer."
|
188
|
+
prompt_template: "Summarize this text: {{ text }}"
|
189
|
+
temperature: 0.5
|
190
|
+
max_tokens: 50
|
191
|
+
output: summary
|
192
|
+
```
|
193
|
+
|
194
|
+
* **Structured LLM Node**
|
195
|
+
|
196
|
+
```yaml
|
197
|
+
nodes:
|
198
|
+
check_inventory:
|
199
|
+
llm_config:
|
200
|
+
model: "gemini/gemini-2.0-flash"
|
201
|
+
system_prompt: "Check inventory status."
|
202
|
+
prompt_template: "Are {{ items }} in stock?"
|
203
|
+
response_model: "my_module:InventoryStatus"
|
204
|
+
output: inventory_status
|
205
|
+
```
|
206
|
+
|
207
|
+
```mermaid
|
208
|
+
graph LR
|
209
|
+
A[Node Definition] --> B{Choice: function, sub_workflow, llm_config};
|
210
|
+
B -- function --> C[Function Name];
|
211
|
+
B -- sub_workflow --> D[Start Node & Transitions];
|
212
|
+
B -- llm_config --> E[LLM Configuration];
|
213
|
+
style A fill:#ccf,stroke:#333,stroke-width:2px
|
214
|
+
```
|
215
|
+
|
216
|
+
## 5. Workflow
|
217
|
+
|
218
|
+
The `workflow` section defines the top-level execution flow.
|
219
|
+
|
220
|
+
**Fields**
|
221
|
+
|
222
|
+
* `start` (string, optional): Name of the starting node.
|
223
|
+
* `transitions` (list, required): List of transition rules.
|
224
|
+
|
225
|
+
**Transition Fields**
|
226
|
+
|
227
|
+
* `from` (string, required): Source node.
|
228
|
+
* `to` (string or list, required): Target node(s). String for sequential, list for parallel execution.
|
229
|
+
* `condition` (string, optional): Python expression using `ctx` (e.g., `"ctx.get('in_stock')"`). Transition occurs if `True`.
|
230
|
+
|
231
|
+
**Examples**
|
232
|
+
|
233
|
+
* **Sequential Transition**
|
234
|
+
|
235
|
+
```yaml
|
236
|
+
workflow:
|
237
|
+
start: validate
|
238
|
+
transitions:
|
239
|
+
- from: validate
|
240
|
+
to: check_inventory
|
241
|
+
```
|
242
|
+
|
243
|
+
* **Conditional Transition**
|
244
|
+
|
245
|
+
```yaml
|
246
|
+
workflow:
|
247
|
+
start: check_inventory
|
248
|
+
transitions:
|
249
|
+
- from: check_inventory
|
250
|
+
to: payment_shipping
|
251
|
+
condition: "ctx.get('inventory_status').in_stock"
|
252
|
+
```
|
253
|
+
|
254
|
+
* **Parallel Transition**
|
255
|
+
|
256
|
+
```yaml
|
257
|
+
workflow:
|
258
|
+
start: payment_shipping
|
259
|
+
transitions:
|
260
|
+
- from: payment_shipping
|
261
|
+
to: [update_status, notify_customer]
|
262
|
+
```
|
263
|
+
|
264
|
+
```mermaid
|
265
|
+
graph LR
|
266
|
+
A[Workflow Definition] --> B(Start Node);
|
267
|
+
A --> C(Transitions);
|
268
|
+
C --> D{From Node};
|
269
|
+
D --> E{To Nodes};
|
270
|
+
E -- Sequential --> F[Single Node];
|
271
|
+
E -- Parallel --> G[List of Nodes];
|
272
|
+
C --> H{Condition Optional};
|
273
|
+
style A fill:#ccf,stroke:#333,stroke-width:2px
|
274
|
+
```
|
275
|
+
|
276
|
+
## 6. Context
|
277
|
+
|
278
|
+
The context (`ctx`) is a dictionary shared across the workflow and sub-workflows, storing node outputs. Examples:
|
279
|
+
|
280
|
+
* Function node: `ctx["is_valid"] = True`.
|
281
|
+
* Plain LLM node: `ctx["summary"] = "Brief text"`.
|
282
|
+
* Structured LLM node: `ctx["inventory_status"] = InventoryStatus(items=["item1"], in_stock=True)`.
|
283
|
+
|
284
|
+
## 7. Execution Flow
|
285
|
+
|
286
|
+
The `WorkflowEngine` executes the workflow as follows:
|
287
|
+
|
288
|
+
1. Begins at `workflow.start`.
|
289
|
+
2. Executes nodes, updating `ctx`:
|
290
|
+
* **Function Nodes**: Calls the referenced function, storing the result in `output`.
|
291
|
+
* **Sub-Workflow Nodes**: Runs the nested workflow, merging its context into the parent’s.
|
292
|
+
* **LLM Nodes**: Uses `Nodes.llm_node` for text output or `Nodes.structured_llm_node` for structured output via `litellm` and `instructor`.
|
293
|
+
3. Evaluates transitions:
|
294
|
+
* Conditions (if present) are checked against `ctx`.
|
295
|
+
4. Executes the next node(s) sequentially or in parallel based on `to`.
|
296
|
+
5. Continues until no further transitions remain.
|
297
|
+
|
298
|
+
## 8. WorkflowManager
|
299
|
+
|
300
|
+
The `WorkflowManager` class provides programmatic control over workflows:
|
301
|
+
|
302
|
+
* **Node Management**: Add, update, or remove nodes.
|
303
|
+
* **Transition Management**: Define execution flow.
|
304
|
+
* **Function Registration**: Embed or link to external functions.
|
305
|
+
* **YAML I/O**: Load/save workflows from/to YAML files.
|
306
|
+
* **Instantiation**: Builds a `Workflow` object with support for PyPI modules.
|
307
|
+
|
308
|
+
**Example**
|
309
|
+
|
310
|
+
```python
|
311
|
+
manager = WorkflowManager()
|
312
|
+
manager.add_function("fetch", "external", module="requests", function="get")
|
313
|
+
manager.add_node("start", function="fetch", output="response")
|
314
|
+
manager.set_start_node("start")
|
315
|
+
manager.save_to_yaml("workflow.yaml")
|
316
|
+
```
|
317
|
+
|
318
|
+
If `requests` is missing, the manager raises:
|
319
|
+
|
320
|
+
```text
|
321
|
+
Failed to import module 'requests': No module named 'requests'. This may be a PyPI package. Ensure it is installed using 'pip install requests' or check if the module name is correct.
|
322
|
+
```
|
323
|
+
|
324
|
+
```mermaid
|
325
|
+
graph LR
|
326
|
+
A[WorkflowManager] --> B(Add/Update/Remove Nodes & Transitions);
|
327
|
+
A --> C(Load/Save YAML);
|
328
|
+
A --> D(Instantiate Workflow);
|
329
|
+
style A fill:#ccf,stroke:#333,stroke-width:2px
|
330
|
+
```
|
331
|
+
|
332
|
+
## 9. Examples
|
333
|
+
|
334
|
+
**Example 1: Simple Workflow with PyPI Module**
|
335
|
+
|
336
|
+
```yaml
|
337
|
+
functions:
|
338
|
+
fetch_page:
|
339
|
+
type: external
|
340
|
+
module: requests
|
341
|
+
function: get
|
342
|
+
nodes:
|
343
|
+
fetch:
|
344
|
+
function: fetch_page
|
345
|
+
output: page_content
|
346
|
+
workflow:
|
347
|
+
start: fetch
|
348
|
+
transitions: []
|
349
|
+
```
|
350
|
+
|
351
|
+
Execution with `ctx = {"url": "https://example.com"}`:
|
352
|
+
|
353
|
+
`fetch` → `ctx["page_content"] = <Response object>` (assuming `requests` is installed).
|
354
|
+
|
355
|
+
**Example 2: E-commerce Workflow**
|
356
|
+
|
357
|
+
```yaml
|
358
|
+
functions:
|
359
|
+
validate_order:
|
360
|
+
type: embedded
|
361
|
+
code: |
|
362
|
+
async def validate_order(order: dict) -> bool:
|
363
|
+
await asyncio.sleep(1)
|
364
|
+
return bool(order.get("items"))
|
365
|
+
process_payment:
|
366
|
+
type: external
|
367
|
+
module: stripe
|
368
|
+
function: create_charge
|
369
|
+
nodes:
|
370
|
+
validate:
|
371
|
+
function: validate_order
|
372
|
+
output: is_valid
|
373
|
+
inventory:
|
374
|
+
llm_config:
|
375
|
+
model: "gemini/gemini-2.0-flash"
|
376
|
+
system_prompt: "Check inventory."
|
377
|
+
prompt_template: "Are {{ items }} in stock?"
|
378
|
+
response_model: "my_module:InventoryStatus"
|
379
|
+
output: inventory_status
|
380
|
+
payment:
|
381
|
+
function: process_payment
|
382
|
+
output: payment_status
|
383
|
+
notify:
|
384
|
+
llm_config:
|
385
|
+
prompt_template: "Notify: Order {{ order_id }} processed."
|
386
|
+
output: notification
|
387
|
+
workflow:
|
388
|
+
start: validate
|
389
|
+
transitions:
|
390
|
+
- from: validate
|
391
|
+
to: inventory
|
392
|
+
- from: inventory
|
393
|
+
to: payment
|
394
|
+
condition: "ctx.get('inventory_status').in_stock"
|
395
|
+
- from: payment
|
396
|
+
to: notify
|
397
|
+
```
|
398
|
+
|
399
|
+
Execution with `ctx = {"order": {"items": ["item1"], "order_id": "123"}}`:
|
400
|
+
|
401
|
+
* `validate` → `ctx["is_valid"] = True`.
|
402
|
+
* `inventory` → `ctx["inventory_status"] = InventoryStatus(...)`.
|
403
|
+
* `payment` → `ctx["payment_status"] = <Stripe response>` (requires `pip install stripe`).
|
404
|
+
* `notify` → `ctx["notification"] = "Notify: Order 123 processed."`.
|
405
|
+
|
406
|
+
```mermaid
|
407
|
+
graph LR
|
408
|
+
A[validate] --> B[inventory];
|
409
|
+
B -- "ctx.get('inventory_status').in_stock" --> C[payment];
|
410
|
+
C --> D[notify];
|
411
|
+
style A fill:#afa,stroke:#333,stroke-width:2px
|
412
|
+
style B fill:#afa,stroke:#333,stroke-width:2px
|
413
|
+
style C fill:#afa,stroke:#333,stroke-width:2px
|
414
|
+
style D fill:#afa,stroke:#333,stroke-width:2px
|
415
|
+
```
|
416
|
+
|
417
|
+
## 10. Conclusion
|
418
|
+
|
419
|
+
The Quantalogic Flow YAML DSL, as of February 23, 2025, provides a flexible and powerful framework for defining workflows. Enhanced support for PyPI modules via the `module` field in `functions` ensures seamless integration with external libraries, with clear error messages guiding users to install missing packages (e.g., `pip install requests`). Combined with sub-workflows, LLM nodes, and robust execution controls, it supports a wide range of applications, from simple tasks to complex, AI-driven processes, all manageable through the `WorkflowManager`.
|