Using Process States
Every step in a process has access to a shared execution context called state and secretState . This allows steps to communicate and share data during the process execution.
State Management Commands
In Unmeshed, for any steps you can add data with the following keywords to perform state operations:
Keyword | Description |
---|---|
__statePut | Add values to the context state |
__secretStatePut | Add values to the context secret state. Secrets are treated differently from regular state and is not made visible in plain text |
__statePutRemove | Remove the list of keys from the state |
__secretStateRemove | Remove the list of keys from the secret state |
What does __statePut
do?
When present in a step's output, the __statePut
field must contain a map of key-value pairs. These pairs will be *
merged* into the shared state context. After merging, the __statePut
field is removed from the step's output and
only its effects remain in the process state.
Example
{
"__statePut": {
"test": "value",
"testNumber": 100,
"object": {
"objKey1": "testValue"
},
"array": [
"test",
"test1"
]
},
"__stateRemove": [
"anOlderKey"
],
"regularOutput": {
"abc": 1234
}
}
After this step executes:
- The process context
state
becomes:
{
"test": "value",
"testNumber": 100,
"object": {
"objKey1": "testValue"
},
"array": [
"test",
"test1"
]
}
anOlderKey
if present would have been removed based on __stateRemove
instruction
- The step's own output becomes:
{
"regularOutput": {
"abc": 1234
}
}
How can you use this?
This can be leveraged by setting as output of any steps such as
Or any steps
Use the keywords for state management as needed from your worker outputs to directly update the process state.
How can you refer to a previously saved state?
Refer to this section: Passing Context Between Steps Using State
How does this work in code?
Behind the scenes, this functionality works similarly to the following Java code:
For __statePut
:
context.state.putAll(statePut);
All entries from the __statePut
map is merged into the shared process state. Any existing keys in the state will be overwritten by values from __statePut
.
For __stateRemove
:
context.state.removeAll(specifiedKeys);
All keys from the __stateRemove
list is removed from the process state.
The __statePut
and other keyword keys are removed from the output after the corresponding operations to avoid duplication and confusion.
When to Use __statePut
and __stateRemove
- You want a step to share calculated data with future steps.
- You want to dynamically update variables as context state during the flow.
- You want to avoid complex nesting of output references and simplify process context access.
__secretStatePut
and __secretStateRemove
: Secure State Values
Similar to __statePut
, Unmeshed also supports a secure variant called __secretStatePut
. This field allows you to
store sensitive values in the process state without persisting the actual values in the execution history.
This is useful for:
- Passwords
- Tokens
- API keys
- Any confidential information you want to share between steps without exposing it in logs or history
How does __secretStatePut
work?
{
"__secretStatePut": {
"accessToken": "abcd1234xyz",
"privateData": {
"secretField": "hidden"
}
},
"regularOutput": {
"result": true
}
}
- These values will be available in the shared state just like regular variables.
- Internally, the system hashes and stores a reference to the secret value.
- These secrets are not recorded in history and will not be visible to users viewing execution logs.
- Downstream steps can still access them as needed using state reference syntax.
Code Analogy
In Java-like behavior:
context.secretState.putAll(secretStatePut);
Secrets are separated from regular state and handled securely in the backend.
Use __secretStatePut
for any value that should not be logged or visible post-execution. This ensures compliance and
security for sensitive flows.