feat: decision-log data layer for Decide mode (learning layer)
Storage + tools so Decide mode can learn instead of one-shot tie-breaking: log the call Brian makes, resolve it later with the outcome, recall similar past calls to ground new recommendations in his own track record. - memory: decisions table + Decision dataclass + log/resolve/get/list/recall_decisions (embedding over situation+choice; embed failure never blocks a log) - tools: log_decision / resolve_decision / recall_decisions handlers + specs - tests: 9 covering roundtrip, resolve, open-only filter, similarity rank, tool layer Data layer only — NOT wired into any mode's allow-list or the Decide card yet (the prompt/taste part is left for Brian; see docs/DECISION_LOG.md). No behavior changes until the tools are added to _DECIDE_TOOLS. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -81,6 +81,65 @@ def _thought_response(args: dict, ctx: dict) -> str:
|
||||
"next time I'm thinking.")
|
||||
|
||||
|
||||
def _log_decision(args: dict, ctx: dict) -> str:
|
||||
situation = (args.get("situation") or "").strip()
|
||||
choice = (args.get("choice") or "").strip()
|
||||
if not situation or not choice:
|
||||
return "Need both what was being decided and the call you landed on."
|
||||
conf = args.get("confidence")
|
||||
try:
|
||||
conf = int(conf) if conf is not None else None
|
||||
except (TypeError, ValueError):
|
||||
conf = None
|
||||
did = memory.log_decision(
|
||||
situation=situation, choice=choice,
|
||||
options=(args.get("options") or "").strip() or None,
|
||||
rationale=(args.get("rationale") or "").strip() or None,
|
||||
confidence=conf, tags=(args.get("tags") or "").strip() or None,
|
||||
)
|
||||
logbus.log("info", "decision logged (tool)", id=did)
|
||||
return (f"Logged decision #{did}. When you know how it played out, tell me and "
|
||||
"I'll close the loop on it.")
|
||||
|
||||
|
||||
def _resolve_decision(args: dict, ctx: dict) -> str:
|
||||
try:
|
||||
did = int(args.get("decision_id"))
|
||||
except (TypeError, ValueError):
|
||||
return "Which decision? I need its id (#number)."
|
||||
outcome = (args.get("outcome") or "").strip()
|
||||
if not outcome:
|
||||
return "Tell me how it turned out so I can record the outcome."
|
||||
rating = args.get("rating")
|
||||
try:
|
||||
rating = int(rating) if rating is not None else None
|
||||
except (TypeError, ValueError):
|
||||
rating = None
|
||||
if not memory.resolve_decision(did, outcome, rating):
|
||||
return f"(couldn't find decision #{did})"
|
||||
logbus.log("info", "decision resolved (tool)", id=did, rating=rating)
|
||||
return f"Closed the loop on decision #{did}. That goes into how I weigh the next one."
|
||||
|
||||
|
||||
def _recall_decisions(args: dict, ctx: dict) -> str:
|
||||
query = (args.get("query") or "").strip()
|
||||
if not query:
|
||||
return "Give me the gist of the call you're weighing and I'll pull similar past ones."
|
||||
hits = memory.recall_decisions(query, k=int(args.get("k") or 4))
|
||||
if not hits:
|
||||
return "No comparable past decisions on record yet."
|
||||
lines = []
|
||||
for d in hits:
|
||||
head = f"#{d.id} ({d.created_at[:10]}): {d.situation} → {d.choice}"
|
||||
if d.resolved:
|
||||
verdict = {1: "went well", 0: "mixed", -1: "went badly"}.get(d.outcome_rating, "resolved")
|
||||
head += f" — {verdict}: {d.outcome}"
|
||||
else:
|
||||
head += " — outcome still open"
|
||||
lines.append(head)
|
||||
return "\n".join(lines)
|
||||
|
||||
|
||||
# name -> {spec (OpenAI function tool), handler}
|
||||
TOOLS: dict[str, dict] = {
|
||||
"journal_write": {
|
||||
@@ -481,6 +540,34 @@ TOOLS.update({
|
||||
{"thread_id": {**_N, "description": "The thread id (#number) of the thought he reacted to."},
|
||||
"brian_said": {**_S, "description": "What Brian said / his take, in your words."}},
|
||||
["thread_id", "brian_said"])},
|
||||
"log_decision": {"handler": _log_decision, "spec": _f(
|
||||
"log_decision",
|
||||
"Record a real decision Brian lands on (especially in Decide mode) so it can "
|
||||
"inform future calls. Capture it once he's settled — what he was deciding, the "
|
||||
"call, and why. Outcome comes later via resolve_decision.",
|
||||
{"situation": {**_S, "description": "What was being decided, in Brian's terms."},
|
||||
"choice": {**_S, "description": "The call he landed on."},
|
||||
"options": {**_S, "description": "The alternatives weighed (optional, newline/free text)."},
|
||||
"rationale": {**_S, "description": "Why this call (optional)."},
|
||||
"confidence": {**_N, "description": "How sure he was, 1-5 (optional)."},
|
||||
"tags": {**_S, "description": "Domain, comma-separated: poker | life | build | ... (optional)."}},
|
||||
["situation", "choice"])},
|
||||
"resolve_decision": {"handler": _resolve_decision, "spec": _f(
|
||||
"resolve_decision",
|
||||
"Close the loop on a previously logged decision once Brian knows how it turned "
|
||||
"out. This is what makes the decision log learn — outcomes sharpen future calls.",
|
||||
{"decision_id": {**_N, "description": "The decision id (#number)."},
|
||||
"outcome": {**_S, "description": "What actually happened, in Brian's terms."},
|
||||
"rating": {**_N, "description": "How it went: 1 good / 0 mixed / -1 bad (optional)."}},
|
||||
["decision_id", "outcome"])},
|
||||
"recall_decisions": {"handler": _recall_decisions, "spec": _f(
|
||||
"recall_decisions",
|
||||
"Pull past decisions similar to one Brian's weighing now, with how they turned "
|
||||
"out — so you can ground a recommendation in his own track record rather than "
|
||||
"generic advice. Use it when he's deciding something with precedent.",
|
||||
{"query": {**_S, "description": "The gist of the current call / situation."},
|
||||
"k": {**_N, "description": "How many to pull (default 4)."}},
|
||||
["query"])},
|
||||
"start_session": {"handler": _start_session, "spec": _f(
|
||||
"start_session",
|
||||
"Begin a live poker session. Call when Brian sits down to play.",
|
||||
|
||||
Reference in New Issue
Block a user