Personal AI, On Personal Devices
Python
feat: wire ChannelBridge to route messages to DeepResearchAgent
Jon Saad-Falconf75bd469ccee
diff --git a/src/openjarvis/server/channel_bridge.py b/src/openjarvis/server/channel_bridge.pyindex 735018db..c09f0e56 100644--- a/src/openjarvis/server/channel_bridge.py+++ b/src/openjarvis/server/channel_bridge.py@@ -51,12 +51,14 @@ class ChannelBridge:bus: EventBus,system: Any = None,agent_manager: Any = None,+ deep_research_agent: Any = None,) -> None:self._channels = channelsself._session_store = session_storeself._bus = busself._system = systemself._agent_manager = agent_manager+ self._deep_research_agent = deep_research_agentself._notification_timestamps: Dict[str, float] = {}self._subscribe_notifications()@@ -278,11 +280,29 @@ class ChannelBridge:f"Current message: {content}")- try:- result = self._system.ask(query)- response_text = result.get("content", str(result))- except Exception:- logger.exception("Error in JarvisSystem.ask()")+ # Try DeepResearchAgent first+ if self._deep_research_agent is not None:+ try:+ result = self._deep_research_agent.run(content)+ response_text = result.content or "No results found."+ except Exception as exc:+ logger.error("DeepResearch agent failed: %s", exc)+ response_text = f"Research error: {exc}"+ elif self._system is not None:+ try:+ result = self._system.ask(query)+ response_text = result.get("content", str(result))+ except Exception:+ logger.exception("Error in JarvisSystem.ask()")+ error_msg = (+ "Sorry, I couldn't process that right now. "+ "Try again in a moment."+ )+ self._session_store.append_message(+ sender_id, channel_type, "assistant", error_msg+ )+ return error_msg+ else:error_msg = ("Sorry, I couldn't process that right now. ""Try again in a moment."diff --git a/tests/server/test_channel_bridge_deep_research.py b/tests/server/test_channel_bridge_deep_research.pynew file mode 100644index 00000000..97360472--- /dev/null+++ b/tests/server/test_channel_bridge_deep_research.py@@ -0,0 +1,57 @@+"""Test ChannelBridge routes to DeepResearchAgent."""++from __future__ import annotations++from unittest.mock import MagicMock++import pytest+++def test_handle_chat_uses_deep_research_agent() -> None:+ """When a DeepResearch agent is configured, route through it."""+ from openjarvis.server.channel_bridge import ChannelBridge+ from openjarvis.server.session_store import SessionStore++ mock_agent = MagicMock()+ mock_agent.run.return_value = MagicMock(content="Found 3 results about Spain.")++ bridge = ChannelBridge(+ channels={},+ session_store=SessionStore(db_path=":memory:"),+ bus=MagicMock(),+ deep_research_agent=mock_agent,+ )++ result = bridge.handle_incoming(+ sender_id="+15551234567",+ content="When was my last trip to Spain?",+ channel_type="twilio",+ )++ assert "Spain" in result+ mock_agent.run.assert_called_once()+++def test_handle_chat_falls_back_to_system() -> None:+ """When no DeepResearch agent, fall back to system.ask()."""+ from openjarvis.server.channel_bridge import ChannelBridge+ from openjarvis.server.session_store import SessionStore++ mock_system = MagicMock()+ mock_system.ask.return_value = {"content": "Generic response"}++ bridge = ChannelBridge(+ channels={},+ session_store=SessionStore(db_path=":memory:"),+ bus=MagicMock(),+ system=mock_system,+ )++ result = bridge.handle_incoming(+ sender_id="+15551234567",+ content="Hello",+ channel_type="twilio",+ )++ assert result == "Generic response"+ mock_system.ask.assert_called_once()