Hold Chat
The Hold Chat LOP acts as a conversation gatekeeper. It monitors an input conversation table and decides whether to pass it through or block it based on token count thresholds, message count thresholds, or a manual hold toggle. When no hold is active, the input conversation is copied to the output. When any hold condition is met, the output stops updating.
Overview
Section titled “Overview”Hold Chat evaluates three independent hold conditions on every cook:
- Token Hold — counts the total tokens across all messages using tiktoken and compares against a configurable threshold.
- Message Hold — counts the number of messages and compares against a configurable threshold.
- Manual Hold — a simple toggle for human-controlled pausing.
If any one of these conditions is active, the operator enters a held state and stops passing the conversation through. When all conditions clear, the conversation is released to the output. Each condition fires its own pair of callbacks (on/off), and the overall hold state fires the general onHold / onHoldEnd callbacks.
Requirements
Section titled “Requirements”- tiktoken — Python package used for token counting. Install via the ChatTD Python manager.
Input/Output
Section titled “Input/Output”Inputs
Section titled “Inputs”The operator reads from an internal input_table DAT with columns: role, message, id, timestamp.
Outputs
Section titled “Outputs”- conversation_dat — When no hold is active, the input table is copied here. Downstream operators can read this output to receive the released conversation.
Usage Examples
Section titled “Usage Examples”Token-Based Hold
Section titled “Token-Based Hold”- Wire a conversation table into the Hold Chat operator.
- On the Hold page, enable Enable Token Hold.
- Set Token Hold Threshold to your desired limit (e.g., 2048 tokens).
- As the conversation grows, the Token Total read-only parameter updates automatically.
- When the total token count exceeds the threshold, the hold activates and the output stops updating.
- Once the input conversation is trimmed below the threshold, the hold releases and the conversation passes through.
Message Count Hold
Section titled “Message Count Hold”- On the Hold page, enable Enable Message Hold.
- Set Message Hold Threshold to the maximum number of messages allowed.
- Message Total updates automatically as messages arrive.
- When the message count reaches the threshold, the hold activates.
Manual Moderation Hold
Section titled “Manual Moderation Hold”- On the Hold page, toggle Toggle Manual Hold to On.
- The Manual Hold read-only indicator turns on, confirming the hold is active.
- The output stops updating until you toggle Toggle Manual Hold back to Off.
Lock When Held
Section titled “Lock When Held”Enable Lock When Held & Unlock to prevent the operator from recalculating while held. This skips the token and message counting entirely during a hold, which can save processing when conversations are large. When the hold clears, normal evaluation resumes.
Callbacks
Section titled “Callbacks”Hold Chat fires granular callbacks for each hold type, letting you react to specific threshold crossings independently. The general onHold and onHoldEnd callbacks fire when the overall hold state changes (any hold activating or all holds clearing), while the type-specific callbacks (onTokenThreshold, onMessageThreshold, onManual and their End variants) fire when individual conditions change.
Enable or disable individual callbacks on the Callbacks page using the toggle next to each callback name.
Common Use Cases
Section titled “Common Use Cases”- Rate limiting — pause a conversation pipeline when token usage gets too high.
- Content moderation — manually hold conversations for review before they reach downstream agents.
- Budget protection — set token thresholds that align with API cost limits.
- Batch processing — accumulate messages until a count threshold is reached, then release them all at once.
Parameters
Section titled “Parameters”op('hold_chat').par.Holdactive Toggle - Default:
False
op('hold_chat').par.Manualhold Toggle - Default:
False
op('hold_chat').par.Userhold Toggle - Default:
False
op('hold_chat').par.Enabletokenhold Toggle - Default:
False
op('hold_chat').par.Tokenholdthreshold Int - Default:
2048- Range:
- 0 to 1
- Slider Range:
- 1 to 8192
op('hold_chat').par.Tokentotal Int - Default:
2048- Range:
- 0 to 1
- Slider Range:
- 1 to 8192
op('hold_chat').par.Tokenhold Toggle - Default:
False
op('hold_chat').par.Enablemessagehold Toggle - Default:
False
op('hold_chat').par.Messageholdthreshold Int - Default:
0- Range:
- 0 to 1
- Slider Range:
- 0 to 1
op('hold_chat').par.Messagetotal Int - Default:
0- Range:
- 0 to 1
- Slider Range:
- 0 to 1
op('hold_chat').par.Messagehold Toggle - Default:
False
op('hold_chat').par.Lockwhenheld Toggle - Default:
False
Callbacks
Section titled “Callbacks”op('hold_chat').par.Callbackdat DAT - Default:
ChatTD_callbacks
op('hold_chat').par.Editcallbacksscript Pulse - Default:
False
op('hold_chat').par.Createpulse Pulse - Default:
False
op('hold_chat').par.Onhold Toggle - Default:
False
op('hold_chat').par.Onholdend Toggle - Default:
False
op('hold_chat').par.Ontokenthreshold Toggle - Default:
False
op('hold_chat').par.Ontokenthresholdend Toggle - Default:
False
op('hold_chat').par.Onmessagethreshold Toggle - Default:
False
op('hold_chat').par.Onmessagethresholdend Toggle - Default:
False
op('hold_chat').par.Onmanual Toggle - Default:
False
op('hold_chat').par.Onmanualend Toggle - Default:
False
Callbacks
Section titled “Callbacks”onHoldonHoldEndonTokenThresholdonTokenThresholdEndonMessageThresholdonMessageThresholdEndonManualonManualEnd
def onHold(info):
# Called when any hold becomes active
# info: {'Hold': True}
pass
def onHoldEnd(info):
# Called when all holds become inactive
# info: {'Hold': False}
pass
def onTokenThreshold(info):
# Called when token count exceeds threshold
# info: {'Hold': True, 'Type': 'TokenThreshold'}
pass
def onTokenThresholdEnd(info):
# Called when token count drops below threshold
# info: {'Hold': False, 'Type': 'TokenThreshold'}
pass
def onMessageThreshold(info):
# Called when message count exceeds threshold
# info: {'Hold': True, 'Type': 'MessageThreshold'}
pass
def onMessageThresholdEnd(info):
# Called when message count drops below threshold
# info: {'Hold': False, 'Type': 'MessageThreshold'}
pass
def onManual(info):
# Called when manual hold is activated
# info: {'Hold': True, 'Type': 'ManualHold'}
pass
def onManualEnd(info):
# Called when manual hold is deactivated
# info: {'Hold': False, 'Type': 'ManualHold'}
pass Changelog
Section titled “Changelog”v1.0.02024-11-10
Initial release