From d18f2b51132a78e19b18fff5c745e6b193cd8033 Mon Sep 17 00:00:00 2001 From: leo Date: Thu, 11 Dec 2025 17:48:32 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BF=AE=E5=A4=8Ddeviceid=20to=20user?= =?UTF-8?q?=20id?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main/live-agent-api/api/v1/internal.py | 1 + main/live-agent-api/schemas/device.py | 1 + main/live-agent-api/services/device_service.py | 1 + main/xiaozhi-server/core/connection.py | 6 +++++- 4 files changed, 8 insertions(+), 1 deletion(-) diff --git a/main/live-agent-api/api/v1/internal.py b/main/live-agent-api/api/v1/internal.py index 5e7800eb0..f83ad43db 100644 --- a/main/live-agent-api/api/v1/internal.py +++ b/main/live-agent-api/api/v1/internal.py @@ -98,6 +98,7 @@ async def resolve_agent_by_wake( data=DeviceAgentResolveResponse( device_id=resolved.device_id, agent_id=resolved.agent_id, + owner_id=resolved.owner_id, # Device owner's user_id for memory storage is_default=resolved.is_default, match_type=resolved.match_type, agent_config=agent_cfg, diff --git a/main/live-agent-api/schemas/device.py b/main/live-agent-api/schemas/device.py index 631f8450c..d8f6d931e 100644 --- a/main/live-agent-api/schemas/device.py +++ b/main/live-agent-api/schemas/device.py @@ -65,6 +65,7 @@ class DeviceAgentResolveResponse(BaseModel): """Resolve agent for device by wake word or default""" device_id: str agent_id: str + owner_id: Optional[str] = None # Device owner's user_id for memory storage is_default: bool match_type: Literal["wake_word", "default"] agent_config: AgentConfigResponse diff --git a/main/live-agent-api/services/device_service.py b/main/live-agent-api/services/device_service.py index a2b66e764..36ed03ad5 100644 --- a/main/live-agent-api/services/device_service.py +++ b/main/live-agent-api/services/device_service.py @@ -267,6 +267,7 @@ class DeviceService: return DeviceAgentResolveResponse( device_id=device_id, agent_id=matched_agent.agent_id, + owner_id=device.owner_id, # Device owner's user_id for memory storage is_default=matched_binding.is_default, match_type=match_type, agent_config=agent_config, diff --git a/main/xiaozhi-server/core/connection.py b/main/xiaozhi-server/core/connection.py index a91bc355d..957537997 100644 --- a/main/xiaozhi-server/core/connection.py +++ b/main/xiaozhi-server/core/connection.py @@ -81,6 +81,7 @@ class ConnectionHandler: self.websocket = None self.headers = None self.device_id = None + self.owner_id = None # Device owner's user_id for memory storage self.client_ip = None self.prompt = None self.welcome_msg = None @@ -790,8 +791,10 @@ class ConnectionHandler: if self.memory is None: return """初始化记忆模块""" + # Use owner_id (real user_id) for memory storage, fallback to device_id if not available + memory_user_id = self.owner_id if self.owner_id else self.device_id self.memory.init_memory( - role_id=self.device_id, + role_id=memory_user_id, llm=self.llm, agent_id=self.agent_id, summary_memory=self.config.get("summaryMemory", None), @@ -966,6 +969,7 @@ class ConnectionHandler: self.need_bind = True return False self.agent_id = resolved.get("agent_id") + self.owner_id = resolved.get("owner_id") # Device owner's user_id private_config = resolved.get("agent_config") if private_config is None: