|
Csilk 0.2.1
A lightweight, high-performance C HTTP web framework
|
AI Workflow engine implementation with WAL persistence, Tracing, Tools, Monitoring, and Budgeting. More...
#include "csilk/app/workflow.h"#include <ctype.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <time.h>#include <uv.h>#include "cJSON.h"#include "csilk/app/workflow_wal.h"#include "csilk/core/internal.h"#include <sys/stat.h>#include <unistd.h>
Data Structures | |
| struct | csilk_ai_meta_t |
| AI metadata attached to workflow node outputs for token tracking and budget enforcement. More... | |
| struct | csilk_wf_tool_entry_t |
| A registered workflow tool (function-calling capability exposed to AI nodes). Tools are invoked in parallel via the libuv thread pool during AI node execution. More... | |
| struct | csilk_wf_edge_t |
| struct | csilk_wf_node_t |
| A single node in a workflow DAG. Each node wraps a handler function with optional edges, error handling, dynamic routing, and timeout support. More... | |
| struct | csilk_wf_t |
| Workflow definition: a DAG of processing nodes connected by conditional or unconditional edges. Each node runs a handler function on the libuv thread pool. Supports persistence via WAL, real-time monitoring via WebSocket, tool registration for AI nodes, and budget (token/TTL) limits. More... | |
| struct | csilk_wf_ctx_t |
| Workflow execution context — per-run state tracking all node progress, scheduling, memory, and budget enforcement. Created by csilk_wf_run_ext_internal() and freed by cleanup_ctx(). More... | |
| struct | node_work_t |
| Per-node-execution state passed through libuv work requests. Allocated in execute_node(), freed in after_worker_cb(). More... | |
| struct | sub_tool_work_t |
| Per-tool-call context for parallel tool execution within an AI node. Each tool call runs on its own libuv thread-pool worker. More... | |
| struct | stream_ctx_t |
Macros | |
| #define | MAX_WORKFLOW_STEPS 1000 |
Functions | |
| static void | execute_node (csilk_wf_ctx_t *ctx, csilk_wf_node_t *node, csilk_data_t *input) |
| Internal: enqueue a workflow node for execution on the libuv thread pool. | |
| static void | cleanup_ctx (csilk_wf_ctx_t *ctx) |
| Internal: free a workflow execution context and all resources. | |
| static void | after_worker_cb (uv_work_t *req, int status) |
| static void | register_active_ctx (csilk_wf_t *wf, csilk_wf_ctx_t *ctx) |
| static void | unregister_active_ctx (csilk_wf_t *wf, csilk_wf_ctx_t *ctx) |
| static csilk_wf_ctx_t * | find_active_ctx (csilk_wf_t *wf, const char *exec_id) |
| static const char * | csilk_wf_run_ext_internal (csilk_wf_t *wf, csilk_data_t *input, void(*callback)(csilk_data_t *), void(*trace_cb)(csilk_data_t *, csilk_wf_trace_t *)) |
| static void | serve_ui_handler (csilk_ctx_t *c) |
| void | csilk_wf_serve_ui (csilk_app_t *app, const char *path) |
| Register a default route to serve the workflow dashboard. | |
| csilk_wf_t * | csilk_wf_new (const char *name) |
| Create a new AI workflow instance. | |
| static void | ai_config_free (void *ptr) |
| static void | node_free (csilk_wf_node_t *node) |
| void | csilk_wf_free (csilk_wf_t *wf) |
| Deallocate a workflow and all its nodes. | |
| csilk_wf_node_t * | csilk_wf_add (csilk_wf_t *wf, const char *id, csilk_wf_handler_t handler, void *user_data) |
| Add a node to the workflow. | |
| void | csilk_wf_node_set_entry (csilk_wf_node_t *node, int is_entry) |
| Mark a node as an entry point for the workflow. | |
| static void | node_add_edge (csilk_wf_node_t *from, const char *condition, csilk_wf_node_t *to, int is_loop) |
| void | csilk_wf_bind (csilk_wf_node_t *from, csilk_wf_node_t *to) |
| Bind two nodes sequentially (default routing). | |
| void | csilk_wf_on (csilk_wf_node_t *from, const char *condition, csilk_wf_node_t *to) |
| Add a conditional route between nodes. | |
| void | csilk_wf_on_loop (csilk_wf_node_t *from, const char *condition, csilk_wf_node_t *to) |
| Add a loop-back / feedback route between nodes. | |
| void | csilk_wf_on_error (csilk_wf_node_t *from, csilk_wf_node_t *target) |
| Add an error fallback route. | |
| void | csilk_wf_route (csilk_wf_node_t *node, csilk_wf_router_t router) |
| Set a dynamic router for a node. | |
| void | csilk_wf_node_set_join (csilk_wf_node_t *node, csilk_wf_join_policy_t policy) |
| Set the join policy for a node. | |
| void | csilk_wf_set_persistence (csilk_wf_t *wf, const char *wal_dir) |
| Enable WAL persistence for a workflow definition. | |
| void | csilk_wf_register_monitor (csilk_wf_t *wf, csilk_ctx_t *c) |
| Register a WebSocket connection to receive live workflow updates. | |
| static void | _wf_broadcast (csilk_wf_t *wf, const char *event, const char *node_id, const char *payload) |
| void | csilk_wf_set_budget (csilk_wf_t *wf, int max_tokens) |
| Set a maximum token budget for the workflow. | |
| void | csilk_wf_node_set_timeout (csilk_wf_node_t *node, int timeout_ms) |
| Set a timeout for a specific node. | |
| void | csilk_wf_set_ttl (csilk_wf_t *wf, int ttl_sec) |
| Set a global TTL for the workflow execution. | |
| void | csilk_wf_node_set_interactive (csilk_wf_node_t *node, int is_interactive) |
| Mark a node as interactive (requires human signal to proceed). | |
| void | csilk_wf_node_set_schema (csilk_wf_node_t *node, const char *schema) |
| Set an expected JSON Schema for a node's output. | |
| void | csilk_wf_node_set_retry (csilk_wf_node_t *node, int max_retries, int retry_delay_ms) |
| Set automatic retry policy for a specific node. | |
| static csilk_data_t * | remote_pass_handler (csilk_wf_ctx_t *ctx, csilk_data_t *input, void *user_data) |
| void | csilk_wf_node_set_remote (csilk_wf_node_t *node, int is_remote) |
| Mark a node for remote execution via MQ. | |
| static void | on_remote_result (csilk_mq_ctx_t *m_ctx) |
| void | csilk_wf_enable_distributed (csilk_wf_t *wf, csilk_mq_t *mq) |
| Enable distributed execution by bridging workflow with an MQ. | |
| void * | csilk_wf_alloc (csilk_wf_ctx_t *ctx, size_t size) |
| Allocate memory from the workflow arena. | |
| char * | csilk_wf_strdup (csilk_wf_ctx_t *ctx, const char *s) |
| Duplicate a string using the workflow arena. | |
| csilk_data_t * | csilk_wf_data_new (csilk_wf_ctx_t *ctx, const char *type, void *value) |
| Allocate a new data container managed by the workflow arena. | |
| static char * | _csilk_json_get_path (csilk_wf_ctx_t *ctx, cJSON *root, const char *path) |
| Internal: traverse a cJSON tree following a dot-separated path. | |
| static char * | apply_filter (csilk_wf_ctx_t *ctx, const char *filter, char *val) |
| Internal: resolve template expressions in a prompt string. | |
| static char * | resolve_templates (csilk_wf_ctx_t *ctx, const char *template) |
| static void | sub_worker_cb (uv_work_t *req) |
| libuv thread-pool work callback for tool execution. Looks up the tool by name in the workflow's tool registry and calls its function with the arguments from the AI tool call. | |
| static void | after_sub_worker_cb (uv_work_t *req, int status) |
| libuv after-work callback for tool execution. Decrements the shared pending counter and signals the condition variable to wake the main AI node handler thread. | |
| static void | on_ai_stream (const char *chunk, void *user_data) |
| static csilk_data_t * | ai_node_handler (csilk_wf_ctx_t *ctx, csilk_data_t *input, void *user_data) |
| Built-in handler for AI workflow nodes. | |
| csilk_wf_node_t * | csilk_wf_add_ai (csilk_wf_t *wf, const char *id, const csilk_ai_config_t *config) |
| Add a built-in AI node with template support. | |
| void | csilk_wf_register_tool (csilk_wf_t *wf, const char *name, const char *description, const char *parameters_json, csilk_wf_tool_fn fn, void *user_data) |
| Register a tool that AI nodes can call. | |
| csilk_wf_node_t * | csilk_wf_get_node (csilk_wf_t *wf, const char *id) |
| Look up a workflow node by its string ID. | |
| char * | csilk_wf_to_mermaid (csilk_wf_t *wf) |
| Export the workflow graph as a Mermaid string. | |
| char * | csilk_wf_trace_to_json (const csilk_wf_trace_t *trace) |
| Convert a trace object to a JSON string. | |
| void | csilk_wf_trace_free (csilk_wf_trace_t *trace) |
| Free a trace object. | |
| static void | cleanup_ctx_now (csilk_wf_ctx_t *ctx) |
| static void | on_ttl_timer_close (uv_handle_t *handle) |
| static void | wal_log_event (csilk_wf_ctx_t *ctx, csilk_wf_event_type_t type, const char *node_id, csilk_data_t *data) |
| Internal: persist a workflow event to the Write-Ahead Log. | |
| static void | worker_cb (uv_work_t *req) |
| libuv thread-pool work callback — executes a workflow node's handler on a background thread. | |
| static void | on_retry_timer (uv_timer_t *handle) |
| libuv after-work callback — processes node completion on the main loop thread. | |
| static void | on_work_timer_close (uv_handle_t *handle) |
| static void | free_work (node_work_t *work) |
| static void | on_node_timeout (uv_timer_t *handle) |
| libuv timer callback — marks a node as timed out. Sets the is_timed_out flag on the node_work_t, which causes after_worker_cb to treat the output as NULL even if the handler eventually completes. | |
| const char * | csilk_wf_run (csilk_wf_t *wf, csilk_data_t *input, void(*callback)(csilk_data_t *result)) |
| Run the workflow asynchronously. | |
| void | csilk_wf_run_traced (csilk_wf_t *wf, csilk_data_t *input, void(*callback)(csilk_data_t *result, csilk_wf_trace_t *trace)) |
| Run workflow and generate a trace. | |
| static void | on_workflow_ttl (uv_timer_t *handle) |
| void | csilk_wf_resume (csilk_wf_t *wf, const char *exec_id, void(*callback)(csilk_data_t *result)) |
| Resume an interrupted workflow execution from a WAL file. | |
| void | csilk_wf_signal_continue (csilk_wf_t *wf, const char *exec_id, csilk_data_t *input, void(*callback)(csilk_data_t *result)) |
| Signal a paused workflow to continue. | |
Variables | |
| static csilk_wf_t * | g_distributed_wfs [32] |
| static size_t | g_distributed_wf_count = 0 |
AI Workflow engine implementation with WAL persistence, Tracing, Tools, Monitoring, and Budgeting.
| struct csilk_ai_meta_t |
| struct csilk_wf_tool_entry_t |
A registered workflow tool (function-calling capability exposed to AI nodes). Tools are invoked in parallel via the libuv thread pool during AI node execution.
| Data Fields | ||
|---|---|---|
| char * | description |
Description for the AI model's tool schema. |
| csilk_wf_tool_fn | fn |
Tool implementation callback. |
| char * | name |
Tool name (e.g., "get_weather"). |
| char * | parameters_json |
JSON schema string for tool parameters. |
| void * | user_data |
Opaque context for the callback. |
| struct csilk_wf_edge_t |
| struct csilk_wf_s |
Workflow definition: a DAG of processing nodes connected by conditional or unconditional edges. Each node runs a handler function on the libuv thread pool. Supports persistence via WAL, real-time monitoring via WebSocket, tool registration for AI nodes, and budget (token/TTL) limits.
Opaque handle for a workflow instance.

| Data Fields | ||
|---|---|---|
| size_t | active_context_capacity | |
| size_t | active_context_count | |
| csilk_wf_ctx_t ** | active_contexts | |
| uv_mutex_t | ctx_mutex | |
| uv_loop_t * | loop |
libuv event loop for thread-pool scheduling. |
| int | max_tokens |
Maximum total tokens across all AI calls (0 = unlimited). |
| size_t | monitor_capacity |
Allocated monitor array capacity. |
| size_t | monitor_count |
Number of active monitors. |
| uv_mutex_t | monitor_mutex |
Protects the monitor array. |
| csilk_ctx_t ** | monitors |
WebSocket monitoring connections. |
| csilk_mq_t * | mq |
Optional MQ for distributed execution. |
| char * | name |
Human-readable workflow name. |
| size_t | node_capacity |
Allocated node array capacity. |
| size_t | node_count |
Number of registered nodes. |
| csilk_wf_node_t ** | nodes |
Array of node pointers. |
| size_t | tool_capacity |
Allocated tool array capacity. |
| size_t | tool_count |
Number of registered tools. |
| csilk_wf_tool_entry_t * | tools |
Registered tool definitions. |
| int | ttl_sec |
Workflow Time-To-Live in seconds (0 = no limit). |
| char * | wal_dir |
WAL directory path (NULL = no persistence). |
| struct node_work_t |
Per-node-execution state passed through libuv work requests. Allocated in execute_node(), freed in after_worker_cb().

| Data Fields | ||
|---|---|---|
| csilk_wf_ctx_t * | ctx |
Workflow execution context. |
| csilk_data_t * | input |
Input data to the node's handler. |
| int | is_timed_out |
Flag set by timer if node exceeds timeout_ms. |
| csilk_wf_node_t * | node |
The node being executed. |
| uv_timer_t | node_timer |
Per-node timeout or retry delay timer. |
| csilk_data_t * | output |
Output data from the handler (set by worker_cb). |
| uv_work_t | req |
libuv work request (must be first for cast). |
| int | retry_count |
Current retry attempt. |
| int | timer_closing |
Non-zero once uv_close is called on node_timer. |
| csilk_wf_trace_node_t * | trace_node |
Trace record for this node (NULL if not tracing). |
| struct sub_tool_work_t |
Per-tool-call context for parallel tool execution within an AI node. Each tool call runs on its own libuv thread-pool worker.

| Data Fields | ||
|---|---|---|
| uv_cond_t * | cond |
Shared condition variable for completion. |
| csilk_wf_ctx_t * | ctx |
Workflow context (for tool registry lookup). |
| uv_mutex_t * | mutex |
Shared mutex for the pending counter. |
| int * | pending |
Shared atomic-like pending count. |
| char * | result |
Tool output string (allocated by tool fn). |
| csilk_ai_tool_call_t * | tc |
Tool call arguments from the AI response. |
| #define MAX_WORKFLOW_STEPS 1000 |
|
static |
Internal: traverse a cJSON tree following a dot-separated path.
Algorithm:
| ctx | Workflow context (for arena allocation). |
| root | Root cJSON node to start traversal from. |
| path | Dot-separated path (e.g., "user.address.city"). |
|
static |
|
static |
libuv after-work callback for tool execution. Decrements the shared pending counter and signals the condition variable to wake the main AI node handler thread.
|
static |
|
static |
|
static |
Built-in handler for AI workflow nodes.
Algorithm:
| ctx | Workflow execution context. |
| input | Ignored (AI prompts come from config templates). |
| user_data | Pointer to csilk_ai_config_t with model, prompt, etc. |
|
static |
Internal: resolve template expressions in a prompt string.
Template syntax: {{node_id.value}} -> raw value output from a node {{node_id.value.path.to}} -> JSONPath into a node's JSON output {{input.value}} -> the workflow's initial input {{input.value.path.to}} -> JSONPath into the initial input
Algorithm:
| ctx | Workflow execution context. |
| template | Template string with {{...}} placeholders. |
|
static |
Internal: free a workflow execution context and all resources.
Stops and closes the TTL timer if active, destroys all mutexes, frees the memory arena, node tracking arrays, WAL path, and the context struct itself.
| ctx | The execution context to clean up (may be NULL). |
|
static |
| csilk_wf_node_t * csilk_wf_add | ( | csilk_wf_t * | wf, |
| const char * | id, | ||
| csilk_wf_handler_t | handler, | ||
| void * | user_data | ||
| ) |
Add a node to the workflow.
| wf | Workflow handle. |
| id | Unique ID for the node. |
| handler | Function to execute. |
| user_data | Opaque pointer passed to the handler. |
| csilk_wf_node_t * csilk_wf_add_ai | ( | csilk_wf_t * | wf, |
| const char * | id, | ||
| const csilk_ai_config_t * | config | ||
| ) |
Add a built-in AI node with template support.
| wf | Workflow handle. |
| id | Unique ID. |
| config | AI configuration (copied internally). |
| void * csilk_wf_alloc | ( | csilk_wf_ctx_t * | ctx, |
| size_t | size | ||
| ) |
Allocate memory from the workflow arena.
| ctx | Execution context. |
| size | Number of bytes. |
| void csilk_wf_bind | ( | csilk_wf_node_t * | from, |
| csilk_wf_node_t * | to | ||
| ) |
Bind two nodes sequentially (default routing).
| from | Source node. |
| to | Destination node. |
| csilk_data_t * csilk_wf_data_new | ( | csilk_wf_ctx_t * | ctx, |
| const char * | type, | ||
| void * | value | ||
| ) |
Allocate a new data container managed by the workflow arena.
| ctx | Execution context. |
| type | Data type identifier (copied). |
| value | Pointer to the data. |
| void csilk_wf_enable_distributed | ( | csilk_wf_t * | wf, |
| csilk_mq_t * | mq | ||
| ) |
Enable distributed execution by bridging workflow with an MQ.
| wf | Workflow handle. |
| mq | MQ handle for task distribution. |
| void csilk_wf_free | ( | csilk_wf_t * | wf | ) |
Deallocate a workflow and all its nodes.
| wf | Workflow handle. |
| csilk_wf_node_t * csilk_wf_get_node | ( | csilk_wf_t * | wf, |
| const char * | id | ||
| ) |
Look up a workflow node by its string ID.
Get a node by ID.
| wf | The workflow instance. |
| id | Node identifier (set in csilk_wf_add()). |
| csilk_wf_t * csilk_wf_new | ( | const char * | name | ) |
Create a new AI workflow instance.
| name | Descriptive name for the workflow. |
| void csilk_wf_node_set_entry | ( | csilk_wf_node_t * | node, |
| int | is_entry | ||
| ) |
Mark a node as an entry point for the workflow.
| node | Node handle. |
| is_entry | Non-zero to mark as entry, 0 to unmark. |
| void csilk_wf_node_set_interactive | ( | csilk_wf_node_t * | node, |
| int | is_interactive | ||
| ) |
Mark a node as interactive (requires human signal to proceed).
| node | Node handle. |
| is_interactive | Non-zero to enable interactive mode. |
| void csilk_wf_node_set_join | ( | csilk_wf_node_t * | node, |
| csilk_wf_join_policy_t | policy | ||
| ) |
Set the join policy for a node.
| node | Node handle. |
| policy | AND (default) or OR. |
| void csilk_wf_node_set_remote | ( | csilk_wf_node_t * | node, |
| int | is_remote | ||
| ) |
Mark a node for remote execution via MQ.
| node | Node handle. |
| is_remote | Non-zero to offload to remote worker. |
| void csilk_wf_node_set_retry | ( | csilk_wf_node_t * | node, |
| int | max_retries, | ||
| int | retry_delay_ms | ||
| ) |
Set automatic retry policy for a specific node.
| node | Node handle. |
| max_retries | Maximum number of retry attempts. |
| retry_delay_ms | Delay before each retry. |
| void csilk_wf_node_set_schema | ( | csilk_wf_node_t * | node, |
| const char * | schema | ||
| ) |
Set an expected JSON Schema for a node's output.
| node | Node handle. |
| schema | JSON Schema string (NULL to disable). |
| void csilk_wf_node_set_timeout | ( | csilk_wf_node_t * | node, |
| int | timeout_ms | ||
| ) |
Set a timeout for a specific node.
| node | Node handle. |
| timeout_ms | Timeout in milliseconds (0 for no timeout). |
| void csilk_wf_on | ( | csilk_wf_node_t * | from, |
| const char * | condition, | ||
| csilk_wf_node_t * | to | ||
| ) |
Add a conditional route between nodes.
| from | Source node. |
| condition | Result string that triggers this route (e.g., "fail"). |
| to | Destination node. |
| void csilk_wf_on_error | ( | csilk_wf_node_t * | from, |
| csilk_wf_node_t * | target | ||
| ) |
Add an error fallback route.
| from | Source node. |
| target | Destination node triggered if the source handler fails. |
| void csilk_wf_on_loop | ( | csilk_wf_node_t * | from, |
| const char * | condition, | ||
| csilk_wf_node_t * | to | ||
| ) |
Add a loop-back / feedback route between nodes.
| from | Source node. |
| condition | Result string that triggers this route. |
| to | Destination node (typically an earlier node). |
| void csilk_wf_register_monitor | ( | csilk_wf_t * | wf, |
| csilk_ctx_t * | c | ||
| ) |
Register a WebSocket connection to receive live workflow updates.
| wf | Workflow handle. |
| c | Request context (must be upgraded to WebSocket). |
| void csilk_wf_register_tool | ( | csilk_wf_t * | wf, |
| const char * | name, | ||
| const char * | description, | ||
| const char * | parameters_json, | ||
| csilk_wf_tool_fn | fn, | ||
| void * | user_data | ||
| ) |
Register a tool that AI nodes can call.
| wf | Workflow handle. |
| name | Function name exposed to the LLM. |
| description | Description of what the tool does. |
| parameters_json | JSON Schema string for the arguments. |
| fn | C function to execute. |
| user_data | Context for the function. |
| void csilk_wf_resume | ( | csilk_wf_t * | wf, |
| const char * | exec_id, | ||
| void(*)(csilk_data_t *result) | callback | ||
| ) |
Resume an interrupted workflow execution from a WAL file.
| wf | Workflow definition. |
| exec_id | The execution ID to resume. |
| callback | Callback for when the resumed workflow finishes. |
| void csilk_wf_route | ( | csilk_wf_node_t * | node, |
| csilk_wf_router_t | router | ||
| ) |
Set a dynamic router for a node.
| node | Node handle. |
| router | Function that determines the next node based on output. |
| const char * csilk_wf_run | ( | csilk_wf_t * | wf, |
| csilk_data_t * | input, | ||
| void(*)(csilk_data_t *result) | callback | ||
| ) |
Run the workflow asynchronously.
| wf | Workflow handle. |
| input | Initial input data. |
| callback | Callback invoked when the workflow completes or exits. |
|
static |
| void csilk_wf_run_traced | ( | csilk_wf_t * | wf, |
| csilk_data_t * | input, | ||
| void(*)(csilk_data_t *result, csilk_wf_trace_t *trace) | callback | ||
| ) |
Run workflow and generate a trace.
| wf | Workflow handle. |
| input | Initial input. |
| callback | Callback receiving final result and the full trace. |
| void csilk_wf_serve_ui | ( | csilk_app_t * | app, |
| const char * | path | ||
| ) |
Register a default route to serve the workflow dashboard.
| app | Application handle. |
| path | URL path (e.g., "/admin/workflow"). |
| void csilk_wf_set_budget | ( | csilk_wf_t * | wf, |
| int | max_tokens | ||
| ) |
Set a maximum token budget for the workflow.
| wf | Workflow handle. |
| max_tokens | Maximum total tokens (prompt + completion) allowed. |
| void csilk_wf_set_persistence | ( | csilk_wf_t * | wf, |
| const char * | wal_dir | ||
| ) |
Enable WAL persistence for a workflow definition.
| wf | Workflow handle. |
| wal_dir | Directory to store execution logs. |
| void csilk_wf_set_ttl | ( | csilk_wf_t * | wf, |
| int | ttl_sec | ||
| ) |
Set a global TTL for the workflow execution.
| wf | Workflow handle. |
| ttl_sec | TTL in seconds (0 for no limit). |
| void csilk_wf_signal_continue | ( | csilk_wf_t * | wf, |
| const char * | exec_id, | ||
| csilk_data_t * | input, | ||
| void(*)(csilk_data_t *result) | callback | ||
| ) |
Signal a paused workflow to continue.
| wf | Workflow definition. |
| exec_id | Execution ID of the paused workflow. |
| input | Optional replacement input (e.g., human-edited prompt). |
| callback | Callback for when the resumed workflow finishes. |
| char * csilk_wf_strdup | ( | csilk_wf_ctx_t * | ctx, |
| const char * | s | ||
| ) |
Duplicate a string using the workflow arena.
| ctx | Execution context. |
| s | Source string. |
| char * csilk_wf_to_mermaid | ( | csilk_wf_t * | wf | ) |
Export the workflow graph as a Mermaid string.
| wf | Workflow handle. |
| void csilk_wf_trace_free | ( | csilk_wf_trace_t * | trace | ) |
Free a trace object.
| char * csilk_wf_trace_to_json | ( | const csilk_wf_trace_t * | trace | ) |
Convert a trace object to a JSON string.
|
static |
Internal: enqueue a workflow node for execution on the libuv thread pool.
Algorithm:
| ctx | Workflow execution context. |
| node | The node to execute. |
| input | Input data to pass to the node's handler. |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
libuv timer callback — marks a node as timed out. Sets the is_timed_out flag on the node_work_t, which causes after_worker_cb to treat the output as NULL even if the handler eventually completes.
|
static |
|
static |
libuv after-work callback — processes node completion on the main loop thread.
Algorithm (the central scheduler dispatch in the workflow engine):
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
libuv thread-pool work callback for tool execution. Looks up the tool by name in the workflow's tool registry and calls its function with the arguments from the AI tool call.
|
static |
|
static |
Internal: persist a workflow event to the Write-Ahead Log.
Packs node_id, data type, and data value into a flat payload buffer and delegates to _wf_wal_append(). The payload format is: [node_id\0][data_type\0][data_value\0] Fields are NUL-terminated strings for simple parsing during recovery.
| ctx | Workflow execution context (must have wal_path set). |
| type | Event type (WF_EV_START, WF_EV_NODE_START, etc.). |
| node_id | Originating node ID, or NULL for workflow-level events. |
| data | Associated data (may be NULL for simple events). |
|
static |
libuv thread-pool work callback — executes a workflow node's handler on a background thread.
Broadcasts a "node_start" event to monitors, then calls the node's handler function. The output is stored in the work request struct for retrieval by after_worker_cb on the main loop thread.
|
static |
|
static |