Control Codes
Control Codes
Control codes are special patterns that LLMs can include in their responses to steer workflow execution. When a cognition node's LLM output contains a control code, the execution engine detects it and takes the specified action.
Control codes are database-driven — global codes apply to all graphs, and you can add custom codes per character.
How They Work
During a cognition node's execution, the LLM generates a response. The execution engine scans this response for control code patterns. If found, the code triggers a specific behavior:
LLM Response: "Based on my analysis, this should be approved. [CHOICE:approve]"
→ Engine detects [CHOICE:approve]
→ Routes content to the "approve" output path
The control code is stripped from the displayed output — the user sees clean text while the engine follows the instruction.
Available Control Codes
| Code | Purpose | Example |
|---|---|---|
[CHOICE:option] |
Select a specific path at a Choice node | [CHOICE:approve] |
[GOTO:label] |
Jump to a labeled node | [GOTO:retry] |
[SET:var=value] |
Set a workflow variable | [SET:count=5] |
[DONE] |
Terminate the workflow | [DONE] |
[PAUSE] |
Pause execution for human review | [PAUSE] |
[LOOP:continue] |
Continue to the next loop iteration | [LOOP:continue] |
[LOOP:break] or [BREAK] |
Exit the current loop | [BREAK] |
[WAIT:seconds] |
Pause for a specified duration | [WAIT:30] |
[ERROR:message] |
Force a failure with a message | [ERROR:Invalid input] |
[PASS] |
Explicit success signal | [PASS] |
[FAIL:reason] |
Explicit failure with reason | [FAIL:Criteria not met] |
[CALL:agent:message] |
Send a message to another agent (M2M) | [CALL:alice:Please review] |
[EMIT:event:data] |
Emit a custom event | [EMIT:alert:threshold exceeded] |
[THINK:strategy] |
Apply a thinking strategy | [THINK:deductive] |
Using Control Codes in Prompts
You don't need to teach the LLM about control codes manually. ThinkThing automatically injects control code documentation into the LLM's system prompt when the graph uses nodes that benefit from them.
For example, a Choice node's prompt includes: "When you've made your decision, include [CHOICE:option_name] in your response where option_name matches one of the available choices."
The LLM learns the syntax from the injected instructions and uses it naturally.
Variables
The [SET:var=value] code lets LLMs create and modify workflow variables. These variables can be referenced in subsequent node prompts using {{var_name}} syntax.
Example flow:
- Extract node finds a count:
[SET:total_items=42] - Next Prompt node uses: "Process the {{total_items}} items..."
- The prompt becomes: "Process the 42 items..."
Loop nodes automatically provide built-in variables: _loop_index (0-based), _loop_count, and _loop_item (for foreach loops).
Custom Control Codes
You can create custom control codes through the ThinkThing API or interface. Custom codes can:
- Define new patterns with custom behavior
- Override global codes for specific characters
- Add domain-specific workflow control language
Custom codes are stored in the database and loaded at execution time.
When Control Codes Fire
Control codes are processed at specific points:
- After LLM response — the engine scans the full response text
- Before output — codes are stripped from the text passed to the next node
- Per node — each cognition node's output is scanned independently
If a response contains multiple control codes, they are processed in order of appearance. Conflicting codes (e.g., [DONE] and [LOOP:continue]) follow first-match precedence.