Skip to content

feat(memory): route memory compaction output to user channel (#1773)#2141

Open
aquamarine-bot wants to merge 3 commits intoagentscope-ai:mainfrom
aquamarine-bot:feat/memory-compaction-channel-notify
Open

feat(memory): route memory compaction output to user channel (#1773)#2141
aquamarine-bot wants to merge 3 commits intoagentscope-ai:mainfrom
aquamarine-bot:feat/memory-compaction-channel-notify

Conversation

@aquamarine-bot
Copy link
Copy Markdown
Contributor

Motivation

When memory compaction is triggered, the summarizer output (e.g., "Compacting memory: 32 messages summarized into ...") is currently sent only via agent.print(), which routes through the streaming pipeline to the web console. Users on external channels (Telegram, Discord, Feishu, etc.) do not see these status messages — they only appear in the server logs.

Changes

src/copaw/app/runner/runner.py

  • Added _channel_manager attribute to AgentRunner with set_channel_manager() setter (mirrors the existing set_chat_manager() pattern)
  • Pass channel_manager=self._channel_manager when instantiating CoPawAgent

src/copaw/app/workspace/service_factories.py

  • Call runner.set_channel_manager(cm) after creating the ChannelManager, so the runner holds a reference to it

src/copaw/agents/react_agent.py

  • CoPawAgent.__init__ now accepts an optional channel_manager parameter and stores it as self._channel_manager

src/copaw/agents/hooks/memory_compaction.py

  • In _print_status_message, after the existing await agent.print(msg) call, check if the agent has a _channel_manager and _request_context
  • If both are available, call channel_manager.send_text() to push the status message to the user's native channel (Telegram, Discord, etc.)
  • Wrapped in try/except so channel send failures are non-fatal and do not interrupt the reasoning loop

Behavior

  • Web console: unchanged (still receives messages via agent.print)
  • External channels: now receive memory compaction status messages
  • No impact if channel_manager is not configured (e.g., console-only deployment)

Testing

  • All existing tests pass (pytest tests/unit/workspace/test_agent_creation.py — 4 passed)
  • pre-commit run passes on changed files (black, flake8, pylint, mypy all green)

Related: /discussions/1773 — Task #9 (P0, Memory)

When memory compaction is triggered, notify the user not only via
the streaming pipeline (web UI) but also through their native channel
(e.g. Telegram, Discord) so external platform users see the summary.

- Add channel_manager to CoPawAgent and pass it from AgentRunner
- Wire channel_manager in create_channel_service
- Send status via ChannelManager.send_text in _print_status_message

Fixes: agentscope-ai/discussions/1773
@aquamarine-bot
Copy link
Copy Markdown
Contributor Author

Update

Merge conflicts with latest main have been resolved and pushed. All checks (pre-commit, unit tests) are green. Ready for review.

cc @cuiyuebing

@aquamarine-bot
Copy link
Copy Markdown
Contributor Author

Update

Rebased onto latest main — all merge conflicts resolved. CI is running again. Ready for review.

cc @cuiyuebing

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

Labels

None yet

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

2 participants