fix(honcho): pass user_message as search_query in get_prefetch_context

The user_message parameter was accepted by get_prefetch_context but intentionally discarded, with the rationale that passing it would
expose conversation content in server access logs.

This rationale is inconsistent: Honcho already persists every message in full via saveMessages. The content is already in the database. A search query in an access log adds negligible additional exposure, and is moot for self-hosted Honcho deployments where the operator owns the logs.

Without search_query, Honcho returns the full peer representation -
all observations, deductive/inductive layers, and peer card - in
insertion order. When contextTokens is set, the most useful parts
(peer card, dialectic conclusions) are truncated because raw
observations fill the budget first.

Passing user_message as search_query enables Honcho's semantic
retrieval to return only conclusions relevant to the current session
topic, reducing injection noise and improving context quality on cold starts.

The _fetch_peer_context method already accepts and passes search_query to the Honcho API. This change simply connects the two.
This commit is contained in:
qxxaa
2026-04-28 14:41:11 +01:00
committed by Teknium
parent 046c293183
commit 0a7cc85eab

View File

@@ -626,14 +626,15 @@ class HonchoSessionManager:
Pre-fetch user and AI peer context from Honcho.
Fetches peer_representation and peer_card for both peers, plus the
session summary when available. search_query is intentionally omitted
— it would only affect additional excerpts that this code does not
consume, and passing the raw message exposes conversation content in
server access logs.
session summary when available. When user_message is provided, it is
passed as search_query to the peer context call so Honcho returns
conclusions relevant to the session topic rather than the full
observation dump.
Args:
session_key: The session key to get context for.
user_message: Unused; kept for call-site compatibility.
user_message: Optional first user message used as search_query for
topic-relevant context retrieval.
Returns:
Dictionary with 'representation', 'card', 'ai_representation',
@@ -659,7 +660,7 @@ class HonchoSessionManager:
logger.debug("Failed to fetch session summary from Honcho: %s", e)
try:
user_ctx = self._fetch_peer_context(session.user_peer_id, target=session.user_peer_id)
user_ctx = self._fetch_peer_context(session.user_peer_id, search_query=user_message or None, target=session.user_peer_id)
result["representation"] = user_ctx["representation"]
result["card"] = "\n".join(user_ctx["card"])
except Exception as e: