feat: inject today's date into system prompt and add extended thinking support

Fixes age validation errors caused by the LLM not knowing the current date.

Changes:
- prompts.py: inject date.today() at the top of both system prompts so the
  LLM can accurately calculate a child's age from their date of birth
- llm.py: add optional thinking_budget parameter to complete(); when set,
  passes thinking={"type": "enabled", "budget_tokens": N} to litellm and
  raises max_tokens to thinking_budget + 4096 (Anthropic models only)
- config.py: add thinking_budget field, read from THINKING_BUDGET env var
- .env.example: document the THINKING_BUDGET option
- core.py: pass thinking_budget through to llm.complete()
- main.py: pass thinking_budget when constructing EmailAgent
- chat_app.py: switch from stream_complete to asyncio.to_thread(complete)
  so extended thinking works and so only the reply field is shown to
  the parent (not the raw JSON wrapper)

To enable extended thinking set THINKING_BUDGET=8000 in .env.

https://claude.ai/code/session_01SUWzMzFvSfWiHXA2p6rPg9
This commit is contained in:
Claude
2026-02-22 19:57:32 +00:00
parent 13cb35111d
commit 1bd11e6acd
7 changed files with 76 additions and 16 deletions
+4 -2
View File
@@ -31,8 +31,10 @@ class EmailAgent:
kb: KnowledgeBase,
store: ConversationStore,
notifier: AdminNotifier,
thinking_budget: int | None = None,
) -> None:
self._model = model
self._thinking_budget = thinking_budget
self._kb = kb
self._store = store
self._notifier = notifier
@@ -98,7 +100,7 @@ class EmailAgent:
system = build_system_prompt(self._kb, state)
try:
content = llm.complete(self._model, system, state.messages)
content = llm.complete(self._model, system, state.messages, self._thinking_budget)
parsed = self._parse_llm_response(content)
except Exception:
logger.exception("LLM call failed for %s", state.conversation_id)
@@ -140,7 +142,7 @@ class EmailAgent:
system = build_system_prompt(self._kb, state)
try:
content = llm.complete(self._model, system, state.messages)
content = llm.complete(self._model, system, state.messages, self._thinking_budget)
parsed = self._parse_llm_response(content)
except Exception:
logger.exception("LLM call failed (post-completion) for %s", state.conversation_id)