36#ifndef CSILK_WORKFLOW_H
37#define CSILK_WORKFLOW_H
73typedef struct csilk_data_s {
78 void (*free_fn)(
void*);
211typedef char* (*csilk_wf_tool_fn)(
const char* args_json,
void*
user_data);
224 const char* description,
225 const char* parameters_json,
253void csilk_wf_bind(csilk_wf_node_t* from, csilk_wf_node_t* to);
261void csilk_wf_on(csilk_wf_node_t* from,
const char* condition, csilk_wf_node_t* to);
271void csilk_wf_on_loop(csilk_wf_node_t* from,
const char* condition, csilk_wf_node_t* to);
High-performance C web framework — main public API header.
Generic data container for passing messages between workflow nodes.
Definition workflow.h:73
void * value
Definition workflow.h:76
char * type
Definition workflow.h:74
void * meta
Definition workflow.h:81
Workflow execution context — per-run state tracking all node progress, scheduling,...
Definition workflow.c:110
A single node in a workflow DAG. Each node wraps a handler function with optional edges,...
Definition workflow.c:49
csilk_wf_handler_t handler
Definition workflow.c:52
int max_retries
Definition workflow.c:68
int retry_delay_ms
Definition workflow.c:69
int is_remote
Definition workflow.c:70
int is_interactive
Definition workflow.c:66
int is_entry
Definition workflow.c:60
void * user_data
Definition workflow.c:53
int timeout_ms
Definition workflow.c:65
Workflow definition: a DAG of processing nodes connected by conditional or unconditional edges....
Definition workflow.c:79
char * node_id
Definition workflow.h:87
const char * model
Definition workflow.h:118
void csilk_wf_set_ttl(csilk_wf_t *wf, int ttl_sec)
Set a global TTL for the workflow execution.
Definition workflow.c:466
double temperature
Definition workflow.h:121
char * model
Definition workflow.h:92
char *(* csilk_wf_tool_fn)(const char *args_json, void *user_data)
Function signature for a workflow tool.
Definition workflow.h:211
char * csilk_wf_strdup(csilk_wf_ctx_t *ctx, const char *s)
Duplicate a string using the workflow arena.
Definition workflow.c:626
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.
Definition workflow.c:1939
void csilk_wf_node_set_entry(csilk_wf_node_t *node, int is_entry)
Mark a node as an entry point for the workflow.
Definition workflow.c:317
void csilk_wf_node_set_join(csilk_wf_node_t *node, csilk_wf_join_policy_t policy)
Set the join policy for a node.
Definition workflow.c:380
void csilk_wf_node_set_timeout(csilk_wf_node_t *node, int timeout_ms)
Set a timeout for a specific node.
Definition workflow.c:458
void csilk_wf_node_set_interactive(csilk_wf_node_t *node, int is_interactive)
Mark a node as interactive (requires human signal to proceed).
Definition workflow.c:474
csilk_data_t *(* csilk_wf_handler_t)(csilk_wf_ctx_t *ctx, csilk_data_t *input, void *user_data)
Function signature for a workflow node handler.
Definition workflow.h:134
void csilk_wf_enable_distributed(csilk_wf_t *wf, csilk_mq_t *mq)
Enable distributed execution by bridging workflow with an MQ.
Definition workflow.c:600
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.
Definition workflow.c:640
csilk_wf_t * csilk_wf_new(const char *name)
Create a new AI workflow instance.
Definition workflow.c:216
const char * csilk_wf_run(csilk_wf_t *wf, csilk_data_t *input, void(*callback)(csilk_data_t *result))
Run the workflow asynchronously.
Definition workflow.c:1933
csilk_wf_t * csilk_wf_from_json(const char *json)
Create a workflow from a JSON string.
Definition workflow_loader.c:74
uint64_t start_time
Definition workflow.h:88
csilk_wf_node_t * csilk_wf_get_node(csilk_wf_t *wf, const char *id)
Get a node by ID.
Definition workflow.c:1257
int completion_tokens
Definition workflow.h:94
const char *(* csilk_wf_router_t)(csilk_data_t *input)
Dynamic router function signature.
Definition workflow.h:112
uint64_t start_time
Definition workflow.h:101
void csilk_wf_on(csilk_wf_node_t *from, const char *condition, csilk_wf_node_t *to)
Add a conditional route between nodes.
Definition workflow.c:356
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.
Definition workflow.c:492
char * error
Definition workflow.h:95
char * input_dump
Definition workflow.h:90
int prompt_tokens
Definition workflow.h:93
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.
Definition workflow.c:288
char * exec_id
Definition workflow.h:100
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.
Definition workflow.c:1220
void csilk_wf_serve_ui(csilk_app_t *app, const char *path)
Register a default route to serve the workflow dashboard.
Definition workflow.c:207
const char * prompt
Definition workflow.h:120
void csilk_wf_set_persistence(csilk_wf_t *wf, const char *wal_dir)
Enable WAL persistence for a workflow definition.
Definition workflow.c:390
csilk_wf_join_policy_t
Join policies for nodes with multiple incoming dependencies.
Definition workflow.h:58
@ CSILK_WF_JOIN_AND
Definition workflow.h:59
@ CSILK_WF_JOIN_OR
Definition workflow.h:60
char * csilk_wf_to_mermaid(csilk_wf_t *wf)
Export the workflow graph as a Mermaid string.
Definition workflow.c:1273
uint64_t end_time
Definition workflow.h:102
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.
Definition workflow.c:1205
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.
Definition workflow.c:361
void csilk_wf_on_error(csilk_wf_node_t *from, csilk_wf_node_t *target)
Add an error fallback route.
Definition workflow.c:366
int max_history_messages
Definition workflow.h:124
csilk_wf_trace_node_t ** nodes
Definition workflow.h:103
void csilk_wf_node_set_remote(csilk_wf_node_t *node, int is_remote)
Mark a node for remote execution via MQ.
Definition workflow.c:509
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.
Definition workflow.c:2039
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.
Definition workflow.c:2166
char * output_dump
Definition workflow.h:91
const char * system_msg
Definition workflow.h:119
size_t node_count
Definition workflow.h:104
void csilk_wf_free(csilk_wf_t *wf)
Deallocate a workflow and all its nodes.
Definition workflow.c:260
void csilk_wf_node_set_schema(csilk_wf_node_t *node, const char *schema)
Set an expected JSON Schema for a node's output.
Definition workflow.c:482
void csilk_wf_trace_free(csilk_wf_trace_t *trace)
Free a trace object.
Definition workflow.c:1366
int max_tokens
Definition workflow.h:122
void csilk_wf_set_budget(csilk_wf_t *wf, int max_tokens)
Set a maximum token budget for the workflow.
Definition workflow.c:450
csilk_wf_t * csilk_wf_load_yaml(const char *path)
Load a workflow definition from a YAML file.
Definition workflow_loader.c:373
int stream
Definition workflow.h:123
void * csilk_wf_alloc(csilk_wf_ctx_t *ctx, size_t size)
Allocate memory from the workflow arena.
Definition workflow.c:614
char * csilk_wf_trace_to_json(const csilk_wf_trace_t *trace)
Convert a trace object to a JSON string.
Definition workflow.c:1321
void csilk_wf_register_monitor(csilk_wf_t *wf, csilk_ctx_t *c)
Register a WebSocket connection to receive live workflow updates.
Definition workflow.c:402
void csilk_wf_route(csilk_wf_node_t *node, csilk_wf_router_t router)
Set a dynamic router for a node.
Definition workflow.c:373
void csilk_wf_register_handler(const char *name, csilk_wf_handler_t handler)
Register a global handler for use in declarative workflows.
Definition workflow_loader.c:25
void csilk_wf_bind(csilk_wf_node_t *from, csilk_wf_node_t *to)
Bind two nodes sequentially (default routing).
Definition workflow.c:351
uint64_t end_time
Definition workflow.h:89
Configuration for built-in AI nodes.
Definition workflow.h:117
Trace record for a single node execution.
Definition workflow.h:86
Complete execution trace of a workflow.
Definition workflow.h:99