Skip to content

feat: add hook after dream completion with customizable script#3118

Open
JiajunBernoulli wants to merge 3 commits into
HKUDS:nightlyfrom
JiajunBernoulli:feat/hook-after-dream
Open

feat: add hook after dream completion with customizable script#3118
JiajunBernoulli wants to merge 3 commits into
HKUDS:nightlyfrom
JiajunBernoulli:feat/hook-after-dream

Conversation

@JiajunBernoulli
Copy link
Copy Markdown
Contributor

@JiajunBernoulli JiajunBernoulli commented Apr 14, 2026

Summary

  • Add after_hook_script config option to DreamConfig for custom post-dream processing
  • Invoke user-defined hook script after Dream completion (async, non-blocking)
  • Initialize default hook template in workspace/hooks/hook_after_dreaming.py
  • Hook receives context with changelog, cursor, batch, and result
  • Template includes three customizable functions: _validate_result, _notify_user, _save_to_external

Changes

  • nanobot/config/schema.py: Add after_hook_script: str | None to DreamConfig
  • nanobot/agent/loop.py: Pass dream config (including after_hook_script) to Dream
  • nanobot/agent/memory.py:
    • Add _invoke_hook_async method for async hook execution in thread pool
    • Only invoke hook when after_hook_script is configured
    • Safe cursor access with .get()
  • nanobot/utils/helpers.py: Initialize default hook template on workspace setup

Tests

Added comprehensive test suite in tests/agent/test_dream.py::TestDreamHook:

  • Hook not invoked when not configured
  • Hook invoked when configured and script exists
  • Missing script handled gracefully (debug log)
  • Missing run function handled gracefully
  • Hook exceptions don't crash Dream
  • Context contains expected keys
  • Batch cursor handled safely

Part1 in #3103

chengyongru and others added 3 commits April 14, 2026 00:37
- Add hook_script config option to DreamConfig
- Invoke user-defined hook script after Dream processing
- Initialize default hook template in workspace/hooks/
- Hook receives context with changelog, cursor, batch, and result
- Template includes three customizable functions:
  - _validate_result: validate memory keywords
  - _notify_user: send notifications
  - _save_to_external: save to external storage (Feishu, Tencent Docs, etc.)

Closes HKUDS#3103
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants