feat: Add sender_id to LLM runtime context

This commit is contained in:
yorkhellen
2026-05-01 19:43:38 +08:00
committed by Xubin Ren
parent 1040124ede
commit c4170fa9ba
3 changed files with 8 additions and 2 deletions
+5 -2
View File
@@ -83,12 +83,14 @@ class ContextBuilder:
@staticmethod
def _build_runtime_context(
channel: str | None, chat_id: str | None, timezone: str | None = None,
session_summary: str | None = None,
session_summary: str | None = None, sender_id: str | None = None,
) -> str:
"""Build untrusted runtime metadata block for injection before the user message."""
lines = [f"Current Time: {current_time_str(timezone)}"]
if channel and chat_id:
lines += [f"Channel: {channel}", f"Chat ID: {chat_id}"]
if sender_id:
lines += [f"Sender ID: {sender_id}"]
if session_summary:
lines += ["", "[Resumed Session]", session_summary]
return ContextBuilder._RUNTIME_CONTEXT_TAG + "\n" + "\n".join(lines) + "\n" + ContextBuilder._RUNTIME_CONTEXT_END
@@ -138,9 +140,10 @@ class ContextBuilder:
chat_id: str | None = None,
current_role: str = "user",
session_summary: str | None = None,
sender_id: str | None = None,
) -> list[dict[str, Any]]:
"""Build the complete message list for an LLM call."""
runtime_ctx = self._build_runtime_context(channel, chat_id, self.timezone, session_summary=session_summary)
runtime_ctx = self._build_runtime_context(channel, chat_id, self.timezone, session_summary=session_summary, sender_id=sender_id)
user_content = self._build_user_content(current_message, media)
# Merge runtime context and user content into a single user message
+2
View File
@@ -929,6 +929,7 @@ class AgentLoop:
chat_id=chat_id,
session_summary=pending,
current_role=current_role,
sender_id=msg.sender_id,
)
final_content, _, all_msgs, stop_reason, _ = await self._run_agent_loop(
messages, session=session, channel=channel, chat_id=chat_id,
@@ -1024,6 +1025,7 @@ class AgentLoop:
media=msg.media if msg.media else None,
channel=msg.channel,
chat_id=self._runtime_chat_id(msg),
sender_id=msg.sender_id,
)
async def _bus_progress(
+1
View File
@@ -518,6 +518,7 @@ class Consolidator:
channel=channel,
chat_id=chat_id,
session_summary=session_summary,
sender_id=None,
)
return estimate_prompt_tokens_chain(
self.provider,