Hausmeister: topic-aware session_summary

This commit is contained in:
root 2026-03-15 12:16:36 +07:00
parent 04a2c0020b
commit 74ac5a2ce5
3 changed files with 48 additions and 15 deletions

View file

@ -323,9 +323,9 @@ def _tool_session_search(query):
return "\n".join(lines) return "\n".join(lines)
def _tool_session_summary(session_id): def _tool_session_summary(session_id, topic=None):
import memory_client import memory_client
return memory_client.get_session_summary(session_id, limit=20) return memory_client.get_session_summary(session_id, limit=20, topic=topic or None)
def get_tool_handlers(session_id: str = None) -> dict: def get_tool_handlers(session_id: str = None) -> dict:
@ -354,5 +354,5 @@ def get_tool_handlers(session_id: str = None) -> dict:
"memory_read": lambda scope="": _tool_memory_read(scope), "memory_read": lambda scope="": _tool_memory_read(scope),
"memory_suggest": lambda scope, kind, content: _tool_memory_suggest(scope, kind, content), "memory_suggest": lambda scope, kind, content: _tool_memory_suggest(scope, kind, content),
"session_search": lambda query: _tool_session_search(query), "session_search": lambda query: _tool_session_search(query),
"session_summary": lambda: _tool_session_summary(session_id) if session_id else "Keine Session aktiv.", "session_summary": lambda topic="": _tool_session_summary(session_id, topic=topic) if session_id else "Keine Session aktiv.",
} }

View file

@ -35,9 +35,10 @@ Nach dem Aufruf sagst du kurz: "Notiert." — kein langes Erklaeren.
NICHT speichern: Passwoerter, Tokens, Smalltalk, Hoeflichkeiten, reine Fragen. NICHT speichern: Passwoerter, Tokens, Smalltalk, Hoeflichkeiten, reine Fragen.
SESSION-RUECKBLICK: SESSION-RUECKBLICK:
- "Was haben wir besprochen?" session_summary aufrufen (liefert alle Themen der aktuellen Session) - "Was haben wir besprochen?" session_summary OHNE topic
- "Erinnerst du dich an X?" mit konkretem Stichwort session_search - "Was haben wir ueber X besprochen?" session_summary MIT topic="X"
- Antworte mit 2-5 knappen Kernthemen, nicht mit einem einzelnen Fakt. - Bei thematischer Filterung: Zuerst die passenden Punkte, dann kurz erwaehnen was sonst noch Thema war.
- session_search nur fuer Stichwort-Suche in ALTEN Sessions (nicht aktuelle).
TOOLS: TOOLS:
Nutze Tools fuer Live-Daten. Wenn alles OK: kurz sagen. Bei Problemen: erklaeren + Loesung.""" Nutze Tools fuer Live-Daten. Wenn alles OK: kurz sagen. Bei Problemen: erklaeren + Loesung."""
@ -311,8 +312,14 @@ TOOLS = [
"type": "function", "type": "function",
"function": { "function": {
"name": "session_summary", "name": "session_summary",
"description": "Zusammenfassung aller Themen der aktuellen Session. Nutze dieses Tool bei Fragen wie 'Was haben wir besprochen?', 'Worüber haben wir geredet?', 'Was war heute Thema?'. Liefert alle Frage-Antwort-Paare kompakt.", "description": "Zusammenfassung der aktuellen Session. Ohne topic = alle Themen. Mit topic = nur thematisch passende Punkte. Nutze topic wenn die Frage ein klares Thema enthaelt (z.B. 'Container', 'Jarvis', 'Backup').",
"parameters": {"type": "object", "properties": {}, "required": []}, "parameters": {
"type": "object",
"properties": {
"topic": {"type": "string", "description": "Themenbegriff zum Filtern (z.B. 'Container', 'Backup'). Leer lassen fuer allgemeine Zusammenfassung."},
},
"required": [],
},
}, },
}, },
] ]

View file

@ -123,8 +123,8 @@ def get_session_messages(session_id: str, limit: int = 10) -> list[dict]:
return [] return []
def get_session_summary(session_id: str, limit: int = 20) -> str: def get_session_summary(session_id: str, limit: int = 20, topic: str = None) -> str:
"""Kompakte Zusammenfassung der aktuellen Session als Themen-Liste.""" """Kompakte Zusammenfassung der aktuellen Session, optional nach Thema gefiltert."""
if not session_id: if not session_id:
return "Keine aktive Session." return "Keine aktive Session."
messages = get_session_messages(session_id, limit=limit) messages = get_session_messages(session_id, limit=limit)
@ -139,9 +139,9 @@ def get_session_summary(session_id: str, limit: int = 20) -> str:
if not content: if not content:
continue continue
if role == "user": if role == "user":
current_q = content[:120] current_q = content[:200]
elif role == "assistant" and current_q: elif role == "assistant" and current_q:
exchanges.append((current_q, content[:120])) exchanges.append((current_q, content[:200]))
current_q = None current_q = None
if current_q: if current_q:
exchanges.append((current_q, None)) exchanges.append((current_q, None))
@ -149,10 +149,36 @@ def get_session_summary(session_id: str, limit: int = 20) -> str:
if not exchanges: if not exchanges:
return "Keine Themen in dieser Session." return "Keine Themen in dieser Session."
lines = [f"Session ({len(exchanges)} Themen):"] if topic:
topic_lower = topic.lower()
matching = []
other_topics = []
for q, a in exchanges:
combined = (q + " " + (a or "")).lower()
if topic_lower in combined:
matching.append((q, a))
else:
other_topics.append(q[:80])
lines = []
if matching:
lines.append("Zum Thema '" + topic + "' (" + str(len(matching)) + " Punkte):")
for i, (q, a) in enumerate(matching, 1):
line = str(i) + ". Frage: " + q
if a:
line += "\n Antwort: " + a
lines.append(line)
else:
lines.append("Zum Thema '" + topic + "' wurde nichts direkt besprochen.")
if other_topics:
lines.append("\nSonstige Themen: " + ", ".join(other_topics))
return "\n".join(lines)
lines = ["Session (" + str(len(exchanges)) + " Themen):"]
for i, (q, a) in enumerate(exchanges, 1): for i, (q, a) in enumerate(exchanges, 1):
line = f"{i}. Frage: {q}" line = str(i) + ". Frage: " + q
if a: if a:
line += f"\n Antwort: {a}" line += "\n Antwort: " + a
lines.append(line) lines.append(line)
return "\n".join(lines) return "\n".join(lines)