feat(agent): support cost questions and thinking fallback

This commit is contained in:
2026-09-17 00:02:38 +02:00
parent d9c612e354
commit cfa2f37986
5 changed files with 200 additions and 35 deletions
+41
View File
@@ -53,6 +53,10 @@ def test_system_prompt_requires_contextual_decision_support():
assert "genau EINE gezielte" in SYSTEM_PROMPT
assert "Regelnummern niemals" in SYSTEM_PROMPT
assert "spekuliere nicht mit Trainingswissen" in SYSTEM_PROMPT
# Anwendung auf den konkreten Einzelfall (Kostenaufstellung)
assert "Arbeitgeberkosten Schritt für Schritt" in SYSTEM_PROMPT
assert "nenne diese Annahme explizit" in SYSTEM_PROMPT
assert "nicht zusätzlich, wenn die Rechnung" in SYSTEM_PROMPT
class TestDecisionSupportValidation:
@@ -244,6 +248,43 @@ def test_trim_results_drops_tail_under_budget():
assert trim_results(blocks, None) is blocks
def test_thinking_only_empty_content_retries_without_think(mini_index):
"""think=true: qwen3.8 lieferte fallweise leeren content (Antwort nur im
thinking-Feld). Ein OllamaError auf dem think-Zug -> einmaliger Retry ohne
thinking; die Anfrage scheitert nicht mehr mit 503."""
from agent.ollama_client import OllamaError
class ThinkingClient:
def __init__(self):
self.think_flags = []
def chat_full(self, model, messages, temperature=0.1, num_ctx=16384,
num_predict=1024, think=False):
self.think_flags.append(think)
if think:
raise OllamaError(
"empty response from qwen3.8:27b (keys: ['message'])"
)
return "Barauszahlung ist lohnsteuerpflichtig [lb-min-01].", "stop"
def chat(self, *a, **k):
raise AssertionError("chat() sollte via chat_full laufen")
def close(self):
pass
import dataclasses
cfg = dataclasses.replace(mini_index, think=True)
client = ThinkingClient()
result = answer_question(
"Was passiert bei einer Barauszahlung?", cfg, client=client
)
assert result["verified"] is True
assert result["citations"] == ["lb-min-01"]
assert client.think_flags == [True, False]
def test_length_retry_doubles_budget(mini_index):
"""done_reason='length' (abgeschnittene Antwort) -> ein technischer
Retry mit doppeltem num_predict; zaehlt nicht als Regel-Regenerierung."""