You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Replace the OpenClaw-based AI backend with the Claude Agent SDK (@anthropic-ai/claude-agent-sdk), adding intelligent message triage and dynamic model selection. This eliminates the dependency on a local proxy, gives cost control via per-query budget limits, and enables model-appropriate responses — cheap Haiku for simple conversation, Sonnet for substantive questions, Opus for complex tasks. The triage layer also offloads anti-abuse detection to more capable models when escalating, and subsumes the chime-in system into a single unified evaluation loop.
Triage System
The triage layer is the core new component. It accumulates messages per channel and periodically evaluates them using a Haiku-model SDK query to classify into one of:
Classification
Model
Reasoning Tokens
Description
ignore
—
—
No response needed
respond-haiku
Haiku
0 (simple)
Simple conversation, greetings
respond-sonnet
Sonnet
1024 (medium)
Questions, substantive discussion
respond-opus
Opus
4096 (complex)
Complex tasks, nuanced questions (rare)
chime-in
Triage decides
Varies
Organic conversation participation — triage picks the model per chime-in (replaces chimeIn module)
moderate
—
—
Flags for moderation review (logging only for now)
Dynamic interval (aggressive threshold-based): Triage frequency scales with message queue size:
Queue Size
Interval
0–1 messages
10s
2–4 messages
5s
5+ messages
2s
Trigger words: Bot name, @mention, configurable keywords, and moderation keywords bypass the timer for immediate evaluation. Moderation keywords combine existing spam.js patterns with a new triage.moderationKeywords[] config list.
@mentions: Always result in a response (ignore is not possible). Triage still picks the model and evaluates instantly.
Triage context: Triage evaluations see only the accumulated recent message buffer (cheap, fast Haiku calls). When a message is classified for a response, the responding model pulls the full DB-backed conversation history to generate its reply.
Triage verification: When triage escalates to Sonnet or Opus, the selected model first verifies the classification before generating a full response. This catches misclassification and prompt injection that Haiku might miss. If verification downgrades the model (e.g., Opus determines Sonnet is sufficient), the downgraded model is used instead.
Buffer lifecycle: Buffer clears after a response is sent. On ignore or moderate classification, counter resets but buffer is preserved for context continuity.
Requirements
Use @anthropic-ai/claude-agent-sdkquery() for all AI responses, replacing OpenClaw fetch() calls
Dynamic triage interval based on message queue size (aggressive thresholds: 0–1 msgs → 10s, 2–4 → 5s, 5+ → 2s)
Replace the OpenClaw-based AI backend with the Claude Agent SDK (
@anthropic-ai/claude-agent-sdk), adding intelligent message triage and dynamic model selection. This eliminates the dependency on a local proxy, gives cost control via per-query budget limits, and enables model-appropriate responses — cheap Haiku for simple conversation, Sonnet for substantive questions, Opus for complex tasks. The triage layer also offloads anti-abuse detection to more capable models when escalating, and subsumes the chime-in system into a single unified evaluation loop.Triage System
The triage layer is the core new component. It accumulates messages per channel and periodically evaluates them using a Haiku-model SDK query to classify into one of:
ignorerespond-haikurespond-sonnetrespond-opuschime-inmoderateDynamic interval (aggressive threshold-based): Triage frequency scales with message queue size:
Trigger words: Bot name, @mention, configurable keywords, and moderation keywords bypass the timer for immediate evaluation. Moderation keywords combine existing
spam.jspatterns with a newtriage.moderationKeywords[]config list.@mentions: Always result in a response (ignore is not possible). Triage still picks the model and evaluates instantly.
Triage context: Triage evaluations see only the accumulated recent message buffer (cheap, fast Haiku calls). When a message is classified for a response, the responding model pulls the full DB-backed conversation history to generate its reply.
Triage verification: When triage escalates to Sonnet or Opus, the selected model first verifies the classification before generating a full response. This catches misclassification and prompt injection that Haiku might miss. If verification downgrades the model (e.g., Opus determines Sonnet is sufficient), the downgraded model is used instead.
Buffer lifecycle: Buffer clears after a response is sent. On
ignoreormoderateclassification, counter resets but buffer is preserved for context continuity.Requirements
@anthropic-ai/claude-agent-sdkquery()for all AI responses, replacing OpenClawfetch()callsignore,respond-haiku,respond-sonnet,respond-opus,chime-in, ormoderatespam.jspatterns with newtriage.moderationKeywords[]config — bypass triage timerchimeIn.jsdeletedmoderateclassification logs structured warning via Winston (no automated action — deferred to AI Auto-Moderation — intelligent automated moderation powered by Claude SDK #56)allowedTools: ['WebSearch']total_cost_usdfrom SDK results)ANTHROPIC_API_KEYreplacesOPENCLAW_URL/OPENCLAW_TOKENshouldUseThread()/getOrCreateThread()logicNew Config Schema
{ "triage": { "enabled": true, "defaultInterval": 10000, "maxBufferSize": 30, "triggerWords": [], "moderationKeywords": [], "models": { "triage": "claude-haiku-4-5", "default": "claude-sonnet-4-20250514" }, "budget": { "triage": 0.05, "response": 0.50 }, "timeouts": { "triage": 10000, "response": 30000 }, "channels": [], "excludeChannels": [] } }Out of Scope
moderateclassification (separate issue — AI Auto-Moderation — intelligent automated moderation powered by Claude SDK #56)Files Affected
src/modules/ai.jssrc/modules/chimeIn.jssrc/modules/events.jssrc/modules/config.jsconfig.jsontriagesection, removechimeInsectionsrc/index.js.env.examplepackage.json@anthropic-ai/claude-agent-sdktests/modules/ai.test.jstests/modules/chimeIn.test.jstests/modules/events.test.jssrc/modules/triage.jstests/modules/triage.test.jsFiles Preserved Unchanged
src/modules/memory.js— mem0 deferredsrc/modules/moderation.js— no changes neededsrc/modules/threading.js— preserved as-issrc/modules/spam.js— patterns reused by triage, module unchangedDependencies
@anthropic-ai/claude-agent-sdknpm packageANTHROPIC_API_KEYenvironment variable