feat(agent): log answer comments

This commit is contained in:
2026-09-17 00:02:31 +02:00
parent b42c326d7f
commit af8bfcaa6a
10 changed files with 241 additions and 55 deletions
+20
View File
@@ -40,6 +40,15 @@ def test_audit_persists_interaction_and_rating(tmp_path):
try:
store.record_interaction(interaction_payload())
store.record_rating("test-request-1", "down", "Quelle war nicht passend")
first_comment_id = store.record_comment(
"test-request-1", "Bitte mit einer anderen Quelle prüfen."
)
second_comment_id = store.record_comment(
"test-request-1", "Der Stand ist für mich besonders wichtig."
)
# Retry mit derselben Request-ID aktualisiert die Interaktion, ohne ihre
# bereits gespeicherten Bewertungen oder Kommentare zu löschen.
store.record_interaction(interaction_payload())
rows = store.recent()
finally:
store.close()
@@ -50,6 +59,11 @@ def test_audit_persists_interaction_and_rating(tmp_path):
assert rows[0]["citations"] == ["lb-min-01"]
assert rows[0]["rating"] == "down"
assert rows[0]["feedback"] == "Quelle war nicht passend"
assert [item["comment_id"] for item in rows[0]["comments"]] == [
first_comment_id,
second_comment_id,
]
assert rows[0]["comments"][0]["comment"].startswith("Bitte mit")
def test_audit_can_omit_free_text_and_still_log_metadata(tmp_path, capsys):
@@ -63,6 +77,7 @@ def test_audit_can_omit_free_text_and_still_log_metadata(tmp_path, capsys):
try:
store.record_interaction(interaction_payload())
store.record_rating("test-request-1", "up", "soll nicht gespeichert werden")
store.record_comment("test-request-1", "auch dieser Kommentar ist privat")
row = store.recent()[0]
finally:
store.close()
@@ -71,10 +86,13 @@ def test_audit_can_omit_free_text_and_still_log_metadata(tmp_path, capsys):
assert row["question"] is None
assert row["answer"] is None
assert row["feedback"] is None
assert row["comments"][0]["comment"] is None
assert "Was gilt?" not in output
assert "soll nicht gespeichert werden" not in output
assert "auch dieser Kommentar ist privat" not in output
assert '"event": "agent_interaction"' in output
assert '"event": "agent_rating"' in output
assert '"event": "agent_comment"' in output
def test_rating_requires_existing_interaction(tmp_path):
@@ -82,6 +100,8 @@ def test_rating_requires_existing_interaction(tmp_path):
try:
with pytest.raises(KeyError):
store.record_rating("missing", "up", None)
with pytest.raises(KeyError):
store.record_comment("missing", "Kommentar")
finally:
store.close()