Conceptual Overview¶
Table of Contents¶
Introduction¶
Skemata is a powerful, extensible workflow runner built to handle everything from simple automations to complex, stateful processes. It’s designed with flexibility at its core — so you can adapt it to your exact use case.
Core Entities¶
Org¶
An org is an identifier for other entities mainly. It's used to keep track of which entity belongs to whom.
Skemata-specific org settings live in org_skemata_config, which currently stores limits like max_running_edge_instances and rate-limit config.
Tool¶
Tools define how actions run and what they look like. They specify the following-
- The input structure that the action must receive. There can only be one input
- The outputs the action emits. There can be multiple of these.
- The type of implementation. This can be internal function calls or HTTP requests.
- The version. This is an integer.
- The input and output structures are specified using JSON schema draft 4
- The type. Broadly, there are actions that can trigger flows and ones that cannot. The ones that can trigger flows are called triggers. Below are the types of actions. We will explain each of them in later sections.
sync_actionsync_triggerasync_actionasync_triggertrigger_context
These are some basic tools
- The "Manual Trigger" just allows one to trigger a flow manually as opposed to based on some event and outputs the input it receives.
- The "Echo" action just outputs the input it receives. But it cannot trigger flows.
- Each can take any input as specified in their inputSchema.
- Note that output schemas is an array. But each only specifies one output schema that can also be any json object.
- The Manual Trigger also specifies default trigger options. These are used to limit how frequently a trigger can be triggered. In this case, it's 60 times in 1 minute.
- The input and output schemas are JSON schemas
[
{
"id": "tol_manual00000000000000",
"icon": "https://placehold.co/200",
"description": "Manual trigger node that can be used to trigger a flow",
"name": "Manual Trigger",
"version": 1,
"implementation": {
"type": "internal"
},
"inputSchema": {
"type": "object",
"properties": {
"input": {
"type": "object",
"default": "$.prev"
}
}
},
"outputSchemas": [
{
"schema": {
"type": "object",
"additionalProperties": true
},
"key": "default",
"label": "Default"
}
],
"type": "sync_trigger",
"defaultTriggerOpts": {
"triggerLimit": 60,
"triggerPeriodUnits": 1,
"triggerPeriod": "minute"
}
},
{
"id": "tol_echo0000000000000000",
"icon": "https://placehold.co/200",
"description": "Test node that returns the input as output",
"name": "Echo",
"implementation": {
"type": "internal"
},
"inputSchema": {
"type": "object",
"additionalProperties": true
},
"version": 1,
"outputSchemas": [
{
"schema": {
"type": "object",
"additionalProperties": true,
"default": "$.input"
},
"key": "default",
"label": "Default"
}
],
"type": "sync_action"
}
]
Action¶
- Actions are instances of Tools.
- They contain the actual input data that will be used for tools.
- If an action is a trigger, it will also have "triggerOptions" that are populated from the "defaultTriggerOptions" from the Tool. The "triggerOptions" also specify if the trigger is enabled or not.
- They are what actually constitute a flow
An action looks like
{
"id": "act_000000000",
"tool_id": "tol_manual000000",
"tool_version": 1,
"input": {
"input": "Hello world"
},
"triggerOptions": {
"triggerLimit": 60,
"triggerPeriodUnits": 1,
"triggerPeriod": "minute",
"enabled": true
}
}
Flow¶
- We collect actions and determine the order of their execution using flows.
- Flows are a graph of actions connected by edges.
- Flows are what actually "run" the actions.
- A flow can have multiple triggers.
Edge¶
- Edges are pointers between actions
- Edges specify a source action and a sink action.
- An action can have multiple incoming edges and multiple outgoing edges.
- Thus an edge must have a routing key so that we can identiy multiple outgoing/incoming edges. The (source_action_id, routing_key) must be unique.
- We use routing keys to determine which edge to traverse when we receive an output from a given action.
- Every action must always have at least one outgoing edge with the "default" routing key.
- Every trigger must always have exactly an incoming edge with the "default" routing key
This is what a basic flow looks like
{
"actions": [
{
"id": "actionId1",
"toolId": "tol_manual00000000000000",
"version": 1
},
{
"id": "actionId2",
"toolId": "tol_echo0000000000000000",
"version": 1
}
],
"edges": [
{
"id": "edgeId1",
"sinkActionId": "actionId1",
"sourceActionId": null,
"routingKey": "default"
},
{
"id": "edgeId2",
"sourceActionId": "actionId1",
"sinkActionId": "actionId2",
"routingKey": "default"
},
{
"id": "edgeId3",
"sourceActionId": "actionId2",
"sinkActionId": null,
"routingKey": "default"
}
]
}
Flow Instance¶
- A flow instance is an instance of a flow that is executing, i.e. when you "launch" a flow, a flow instance is created. It is what we use to keep track of different "executions" of a flows.
- A flow instance has the following states
- "running"
- "completed"
- "cancelled"
Edge Instance¶
- An edge instance is associated with an edge.
- An edge instance is the unit of execution for a flow instance. It is a log of the traversal of the flow graph and of the outputs of the actions that are executed.
- An edge instance has the following states
- "queued"
- "running"
- "awaiting-updates"
- "failed"
- "completed"
- "cancelled"
Execution Overview¶
flowchart LR
A["nul"] -->|"Edge A ('default')"| MT["Manual Trigger"]
MT -->|"Edge B ('default')"| E["Echo"]
E -->|"Edge C ('default')"| C["null"]
Let's take our example message flow from earlier to look at how a flow may be executed.
- Manual trigger is a trigger action. By default, based on it's tool, we construct an Action input
As you can see the value for this input is a jsonpath. We will use this to create our action implementation input dynamically.
- We can fire our startFlow endpoint and trigger it. At this point a flow instance is created with status "running"
- Our input looks something like this:
- EdgeInstance A is created with prev set to the above input. With status set to "queued".
- We then set the status of Edge Instance A to "running".
- Now, using the action input
we interpolate it to
and set EdgeInstance A "input" to the above value
- We then run the action implementation using the mapped "input". In this case, it returns
- We then fetch the next edge which is the outgoing edge for manual trigger--Edge B. We then insert Edge Instance B.
- We then set the "prev" of EdgeInstance B to
- We then set the status of Edge Instance A to completed
- Next, we repeat the above for Edge Instance B
- Finally, when it comes to Edge Instance C, there is no sink action and so we just set "input" for Edge Instance C to it's "prev" and set it to completed as well
Now since each edge instance is set to "completed", the flow instance is considered "completed" as well.
Routing Keys¶
Static Routing Keys¶
An action can have multiple outputs. This is useful in case different outputs need to be handled differently. For example, if we were to have an HTTP node, we could have two types of outputs--one where the request succeeds and one where it fails.
Let's say we have an tool like
{
"id": "tol_http0000000000",
"icon": "https://placehold.co/200",
"description": "HTTP Node",
"name": "HTTP Node",
"inputSchema": {
"type": "object",
"properties": {
"url": {
"type": "string"
}
}
},
"outputSchemas": [
{
"schema": {
"type": "object",
"additionalProperties": true
},
"key": "default",
"label": "Success"
},
{
"key": "failure",
"label": "Output type 2",
"schema": {
"type": "object",
"properties": {
"error": {
"type": "string"
}
},
"additionalProperties": false
}
}
],
"implementation": {
"type": "internal"
},
"type": "sync_trigger",
"defaultTriggerOpts": {
"triggerLimit": 60,
"triggerPeriodUnits": 1,
"triggerPeriod": "minute",
"enabled": true
},
"version": 1
}
In this case, if our implementation fails, we emit the output with the error which we can then use to maybe retry the error based on the status code, whereas, if it's a success, we can proceed with our flow.
flowchart LR
A["null"] -->|"Edge A ('default')"| HT["HTTP Trigger"]
HT -->|"Edge B ('default')"| E["Echo"]
HT -->|"Edge C ('failure')"| N["Notify User"]
E -->|"Edge D ('default')"| F["null"]
N -->|"Edge E ('default')"| G["null"]
Dynamic Routing Keys¶
The above example only has static routing keys, i.e. we know them before we receive the action input. But in many cases, it is useful to have routing keys that can be generated from the input where it would not be feasible to have static keys in those cases. This is especially useful when you have an array of inputs and you need to handle each output differently. But this could work in non array scenarios as well. For example, let's say we have a bulk HTTP Input trigger that lets us make many requests in parallel. We could potentially want to handle the response for each request seperately.
{
"id": "tol_http0000000000",
"icon": "https://placehold.co/200",
"description": "HTTP Bulk Node",
"name": "HTTP Node",
"inputSchema": {
"type": "object",
"properties": {
"urls": {
"type": "array",
"items": {
"type": "string"
}
}
}
},
"outputSchemas": [
{
"schema": {
"type": "object",
"additionalProperties": true
},
"key": "default",
"label": "Internal Error"
},
{
"key": "$.urls[*]",
"label": "On \"{{.}}\" response",
"schema": {
"type": "object",
"additionalProperties": true
}
}
],
"implementation": {
"type": "internal"
},
"type": "sync_trigger",
"defaultTriggerOpts": {
"triggerLimit": 60,
"triggerPeriodUnits": 1,
"triggerPeriod": "minute"
},
"version": 1
}
In the above trigger definition, we have an output schema with a "$.urls[*]" routing key. As you can see this is a wildcard jsonpath. This is how we define dynamic routing keys. So let's say our action input looks like
We can use our routing key path to query our input. We would get the following results
[
{
"path": "urls[0]",
"value": "https://www.google.com"
},
{
"path": "urls[1]",
"value": "https://example.com"
}
]
Thus, based on our input we can statically determine how many outputs there will be. We use this to then generate the edges for each of these potential outputs. So we would have a flow that looks like
flowchart LR
A["null"] -->|"Edge A ('default')"| HBT["HTTP Bulk Trigger"]
HBT -->|"Edge B ('default', 'Internal Error')"| FBT["File Bug Ticket"]
HBT -->|"Edge C ('urls[0]', 'On 'www#46;google#46;com response'')"| S["Scrape search result"]
HBT -->|"Edge D ('urls[1]', 'On 'www#46;example#46;com response'')"| EC["Echo"]
FBT -->|"Edge E ('default')"| H["null"]
S -->|"Edge F ('default')"| I["null"]
EC -->|"Edge G ('default')"| j["null"]
As you can see we use the canonical json path as the routing key. Thus, the bulk HTTP Node would output an output for each response like
{
"status": "completed",
"outputs": [
{
"res": "some google data",
"routingKey": "url[0]"
},
{
"res": "some example.com data",
"routingKey": "url[1]"
}
]
}
Asynchronous Actions¶
Till now, we have only discussed synchronous actions and triggers but as we saw earlier, there are asynchronous actions as well
- async_action
- async_trigger
Often when you execute an action, it may be a long running process or it may not be able to return the response immediately, in this case, it's useful to be able to wait for the action to finish and then execute the next step. Take this tool as an example
{
"id": "tol_longrunning0000",
"version": 1,
"name": "Long Running Job",
"description": "",
"inputSchema": {
"type": "object",
"additionalProperties": true
},
"type": "sync_trigger",
"defaultTriggerOpts": {
"triggerLimit": 60,
"triggerPeriodUnits": 1,
"triggerPeriod": "minute"
},
"outputSchemas": [
{
"key": "completed",
"label": "Long running process completed",
"schema": {
"type": "object",
"required": ["jobId", "response"],
"properties": {
"jobId": "string",
"response": {
"type": "object",
"additionalProperties": true
}
}
}
},
{
"key": "default",
"label": "Long running process started",
"schema": {
"type": "object",
"required": ["jobId"],
"properties": {
"jobId": "string"
}
}
}
]
}
Our flow would look like
flowchart LR
A["null"] -->|"Edge A ('default')"| LRJ["Long Running Job"]
LRJ -->|"Edge B ('default')"| E["Echo"]
LRJ -->|"Edge C ('completed')"| C["Echo"]
E -->|"Edge D ('default')"| F["Echo"]
C -->|"Edge E ('default')"| G["Echo"]
In this case, one the flow is triggered, it runs as usual but once the implementation is run, the action would return
{
"outputs": [
{
"routingKey": "default",
"data": {
"jobId": "xyz"
}
}
],
"status": "awaiting-updates"
}
The edge instance status is set to "awaiting-updates". The "default" edge is run. Then once the job completes, it fires a callback with status "completed". The edge instance is then set to completed and the "completed" edge gets run.
The callback payload would look like
"outputs": [{
"routingKey": "completed",
"data": {
"jobId": "xyz",
"data": {
// job data
}
}
}],
"status": "completed"
This would then cause the "completed" edge instance to run
Trigger Contexts¶
We also have an action type called "trigger_context". These actions are used to set context for a trigger so all actions (including) the trigger can make use of the particular context variables. Say we have an trigger context that sets a variable called "foo", all actions in that flow could then access it in their action input as $.foo. The implementation for these run each step of the flow. So you can always have fresh values if required or cache the value as needed.