Commit 62f69c7d authored by Kantz's avatar Kantz
Browse files

kleine anpassung am Toollogger

parent b903391a
......@@ -31,7 +31,7 @@ def needs_more_context(history: str, context_sheet: str) -> dict:
payload = json.loads(content)
return {
"needs_more_context": bool(payload.get("needs_more_context")),
"reason": payload.get("reason", ""),
"reason": content,
}
except json.JSONDecodeError:
return {"needs_more_context": True, "reason": "classifier_parse_error"}
return {"needs_more_context": True, "reason": content}
......@@ -51,6 +51,7 @@ def run_chat(messages: list[dict], draft: str | None = None) -> dict:
history_text = context_store.format_history(messages)
sheet_text = context_store.format_sheet(sheet)
decision = decision_LLM.needs_more_context(history_text, sheet_text)
_append_tool_log(tool_log, "decision", sheet_text, decision)
context_store.add_decision(sheet, decision)
if decision.get("needs_more_context"):
......
......@@ -29,8 +29,17 @@ def write_tool_log(entries: list[dict], created_at: str | None = None, chat_id:
path = os.path.join("logs", f"tool_calls_{suffix}_{filename_ts}.json")
payload = {
"timestamp": timestamp,
"entries": entries,
"entries": list(entries),
}
if os.path.exists(path):
try:
with open(path, "r", encoding="utf-8") as f:
existing = json.load(f)
if isinstance(existing, dict) and isinstance(existing.get("entries"), list):
payload["entries"] = existing["entries"] + payload["entries"]
payload["timestamp"] = existing.get("timestamp", payload["timestamp"])
except (OSError, json.JSONDecodeError):
pass
with open(path, "w", encoding="utf-8") as f:
json.dump(payload, f, ensure_ascii=True, indent=2)
return path
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment