agent-claw: automated task changes
This commit is contained in:
30
agentclaw/app/agent_claw_main/tools/messaging.py
Normal file
30
agentclaw/app/agent_claw_main/tools/messaging.py
Normal file
@@ -0,0 +1,30 @@
|
||||
"""Messaging tool — channel-adapter-backed send_message for the agent."""
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from channels.adapter import ChannelAdapter
|
||||
|
||||
# Injected by main.py before each invocation
|
||||
_adapter: 'ChannelAdapter | None' = None
|
||||
_message_sent: bool = False
|
||||
|
||||
|
||||
def set_adapter(adapter: 'ChannelAdapter') -> None:
|
||||
global _adapter, _message_sent
|
||||
_adapter = adapter
|
||||
_message_sent = False # reset on each new invocation
|
||||
|
||||
|
||||
def was_sent() -> bool:
|
||||
"""Returns True if send() was called during this invocation."""
|
||||
return _message_sent
|
||||
|
||||
|
||||
def send(text: str) -> str:
|
||||
"""Send a message to the user via the active channel adapter."""
|
||||
global _message_sent
|
||||
if _adapter is None:
|
||||
return 'No channel adapter configured.'
|
||||
msg_id = _adapter.send(text)
|
||||
_message_sent = True
|
||||
return f"Sent (id={msg_id})" if msg_id else 'Sent'
|
||||
Reference in New Issue
Block a user