message lifecycle events: received → preprocessed → sent #14539
Replies: 9 comments 1 reply
-
|
already in use, system-wide, not only for openclaw case |
Beta Was this translation helpful? Give feedback.
-
|
I'm slow - others make what I think of. We need it, go main |
Beta Was this translation helpful? Give feedback.
-
|
Super important update! Used successfully by our community, praised by every participant. |
Beta Was this translation helpful? Give feedback.
-
|
Great write-up @matskevich. The three-event lifecycle is the right design — we're building Engram (agent memory) on OpenClaw and the I'm going to add Happy to have you co-author or review. Let's consolidate and get this across the line. |
Beta Was this translation helpful? Give feedback.
-
|
Very much needed, hope this gets into the main soon! |
Beta Was this translation helpful? Give feedback.
-
|
great patch,the original memory is B/S love it! |
Beta Was this translation helpful? Give feedback.
-
|
Added |
Beta Was this translation helpful? Give feedback.
-
security layer: what message hooks enable (production report)we've been running message hooks as security infrastructure for 10+ days. sharing what works and what's missing. what works today (received + sent)outbound DLP (data loss prevention)
why this matters: your agent reads inbound audit trail
what preprocessed unlocks for security
with preprocessed:
real example from production: user sends voice message containing credentials. the gap: observation vs preventioncurrent hooks are fire-and-forget — they see events but can't block them. the hook runs, but message processing continues regardless. for a real security gateway, you need hooks that can return a decision: this would enable:
we'd be happy to prototype this. the pattern already exists in openclaw for other fixes we found running hooks in production1. groupId missing from MessageSentContext when bot replies in a group, 2. error isolation if a hook throws, it shouldn't crash message delivery. we wrap all triggers in try/catch — hook errors are logged but don't break the bot. this should be the default behavior upstream. both are small PRs we can submit once the base hooks land. running all of this in production with 2 bots, 4 groups, 700+ events. zero crashes from the hook system. message hooks aren't just a memory feature — they're the foundation for security, compliance, and automation. |
Beta Was this translation helpful? Give feedback.
-
|
follow-up: opened a separate proposal for PreReceive / PreSend hooks — message-level blocking and redaction. → #17234 current message hooks (received/preprocessed/sent) are fire-and-forget: great for logging, memory, analytics. but for security you need prevention, not just detection. pre-hooks would close that gap — same pattern as existing the two proposals are complementary:
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
your agent forgets everything. here's the fix.
every time openclaw compacts context, your agent loses conversations. it can't search old messages. it can't remember what you discussed last week. you can't build memory, analytics, or automations on top — because there's no event stream to build on.
message hooks change this. three events —
received,preprocessed,sent— turn openclaw from a stateless chatbot into infrastructure you can build real systems on.what becomes possible
1. your agent never forgets again
every message → append-only log → survives compaction forever. semantic search over your entire history. "what did we discuss about X last month?" — answered in seconds, not hallucinated.
2. auto-digest & people memory
nightly skill reads the raw log → writes daily summaries, extracts facts about people, links conversations to goals.
"met petya, he launched a startup"→ auto-updatespeople/petya.md. your agent builds a knowledge graph while you sleep.3. voice messages become searchable text
message:preprocessedfires after transcription. voice notes that were<media:audio>black boxes become full-text searchable transcripts. same for photos → descriptions, links → summaries.4. security: catch leaked secrets
message:senthook scans every outgoing message for API keys, tokens, credentials (regex + entropy detection). your agent reads.envfiles — this catches what prompt rules miss.5. multi-bot collaboration
two bots in the same group can't see each other's messages (telegram limitation). hooks forward events to a shared hub → bots coordinate in real-time. we run this in production with 2 bots across 4 groups.
6. conversation analytics
when are you most active? what topics dominate? sentiment over time? received/sent ratio? all derived from the raw event stream, zero additional instrumentation.
7. trigger anything from any message
any skill can subscribe to
message:receivedand fire automations: notifications, auto-responses, webhook triggers, content routing. no more polling, no more prompt-based workarounds.none of this is possible today. openclaw has no message event system. hooks exist for commands and sessions, but messages — the core of what an AI assistant does — are invisible to the extension system.
the proposal
three lifecycle events, fired automatically:
why three events, not two?
PR #6797 gives us
received+sent. butreceivedfires before media processing:<media:audio>(no transcript)<media:image>(no description)any hook that needs actual content (search, moderation, routing) gets useless tags instead of text.
preprocessedfills this gap — fires after transcription/description, before the agent sees it.preprocessed context
production data
we've been running all three events in a fork for 7+ days:
real example — voice message lifecycle:
received: body =<media:audio>(useless for search/logging)preprocessed: transcript = full text via groq/whisper + provider metadata (searchable)sent: bot's reply (correlates with input)implementation
~40 lines across 2 files. no new dependencies. no breaking changes:
src/hooks/message-hooks.ts— new type + trigger functionsrc/auto-reply/reply/get-reply.ts— one call after media processingfollows the exact pattern of existing
triggerMessageReceived/triggerMessageSent.related
message:received+message:sent(pending review, 10+ days)both PRs have been waiting 10+ days with no maintainer review. the community clearly wants this. happy to submit a clean PR combining all improvements, or help review either existing PR.
running this in production daily. if you want message hooks now, backport patch is available. but mainline support would benefit everyone.
Beta Was this translation helpful? Give feedback.
All reactions