Commit graph

895 commits

Author SHA1 Message Date
Kent Overstreet
eb4dae04cb Compute ContextBudget on demand from typed sources
Remove cached context_budget field and measure_budget(). Budget
is computed on demand via budget() which calls
ContextState::budget(). Each bucket counted from its typed source.
Memory split from conversation by identifying memory tool calls.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-04-02 03:07:45 -04:00
Kent Overstreet
acdfbeeac3 Align debug screen and budget with conversation-only messages
context.messages is conversation-only now — remove conv_start
scanning. Memory counted from loaded_nodes (same as debug screen).
No subtraction heuristics.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-04-02 02:56:28 -04:00
Kent Overstreet
5e781e9ae4 Fix budget counting: remove stale refresh_context_message
refresh_context_message was injecting personality into conversation
messages (assuming fixed positions that no longer exist). Replaced
with refresh_context_state which just re-measures and publishes.

conv_tokens now subtracts mem_tokens since memory tool results are
in the conversation message list.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-04-02 02:52:59 -04:00
Kent Overstreet
a0aacfc552 Move conversation messages into ContextState
ContextState now owns everything in the context window:
system_prompt, personality, journal, working_stack, loaded_nodes,
and conversation messages. No duplication — each piece exists once
in its typed form.

assemble_api_messages() renders the full message list on the fly
from typed sources. measure_budget() counts each bucket from its
source directly. push_context() removed — identity/journal are
never pushed as messages.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-04-02 02:47:32 -04:00
Kent Overstreet
4580f5dade measure_budget: count from typed sources, not message scanning
Identity tokens from system_prompt + personality vec. Journal
from journal entries vec. Memory from loaded_nodes. Conversation
is the remainder. No string prefix matching.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-04-02 02:32:26 -04:00
Kent Overstreet
4bdc7ae112 Journal budget: count from structured data, not string matching
Count journal tokens directly from Vec<JournalEntry> instead of
scanning message text for prefix strings. Type system, not string
typing.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-04-02 02:29:48 -04:00
Kent Overstreet
5526a26d4c Journal: store as structured Vec<JournalEntry>, not String
Keep journal entries as structured data in ContextState. Render
to text only when building the context message. Debug screen reads
the structured entries directly — no parsing ## headers back out.

Compaction paths temporarily parse the string from build_context_window
back to entries (to be cleaned up when compaction is reworked).

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-04-02 02:21:45 -04:00
Kent Overstreet
42f1e888c4 Journal: flat 5% context window budget, skip plan_context
Render journal entries directly with ## headers instead of going
through the plan_context/render_journal_text pipeline. 5% of
model context window (~6500 tokens for Qwen 128K). Simpler and
predictable.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-04-02 02:00:14 -04:00
Kent Overstreet
7776d87d53 Journal: walk backwards with token budget, not load-all
Iterate journal entries backwards from the conversation cutoff,
accumulating within ~10K token budget (~8% of context window).
Stops when budget is full, keeps at least one entry. Much more
efficient than loading all entries and trimming.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-04-02 01:50:36 -04:00
Kent Overstreet
e4285ba75f Load journal from memory graph, not flat file
Replace flat-file journal parser with direct store query for
EpisodicSession nodes. Filter journal entries to only those older
than the oldest conversation message (plus one overlap entry to
avoid gaps). Falls back to 20 recent entries when no conversation
exists yet.

Fixes: poc-agent context window showing 0 journal entries.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-04-02 01:48:16 -04:00
Kent Overstreet
c814ed1345 Split hook.rs: core orchestration -> subconscious.rs
subconscious::subconscious — AgentCycleState, AgentInfo, AgentSnapshot,
  SavedAgentState, format_agent_output, cycle methods. Core agent
  lifecycle independent of Claude Code.

subconscious::hook — Claude Code hook: context loading, chunking,
  seen-set management, run_agent_cycles (serialized state entry point).

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-04-02 01:37:51 -04:00
Kent Overstreet
fbc8572840 Serialized AgentCycleState for Claude Code hook path
SavedAgentState (JSON) persists agent pid/phase/log_path across
hook invocations. The Claude Code hook loads saved state, runs
cycles, saves back. Pids are liveness-checked with kill(pid, 0)
on load. No more scan_pid_files for agent lifecycle tracking.

poc-agent keeps everything in memory (child handles). The hook
path uses serialized state. Same AgentCycleState, different
persistence model.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-04-02 01:31:59 -04:00
Kent Overstreet
90d2717423 Use own state for spawn decisions, not pid file scanning
AgentCycleState tracks its own children — agent_running() checks
child handles instead of scan_pid_files(). poll_children() reaps
completed processes. No filesystem scanning for agent lifecycle.

The Claude Code hook path will need serialized AgentCycleState
to persist across invocations (next step).

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-04-02 01:26:58 -04:00
Kent Overstreet
9ac50bd999 Track agent child processes, reap on completion
spawn_agent returns Child handle + log_path. AgentCycleState stores
the Child, polls with try_wait() on each trigger to detect completion.
No more filesystem scanning to track agent lifecycle.

AgentSnapshot (Clone) sent to TUI for display. AgentInfo holds the
Child handle and stays in the state.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-04-02 01:20:03 -04:00
Kent Overstreet
54ea7824d8 Fix agent log path: only set state on spawn, not scan
Agent state (pid, phase, log_path) only updates when we spawn an
agent. The scan_pid_files path no longer calls update_agent —
it just logs. This prevents the scan path from clearing log_path
with None on subsequent triggers.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-04-02 01:15:37 -04:00
Kent Overstreet
a90bd4fd47 Agent log screen: show agent output, not hook log
spawn_agent() now returns SpawnResult { pid, log_path } so the
log path is known at spawn time. No more filesystem scanning.
AgentInfo carries log_path, TUI reads it directly.

F2 → Enter shows the actual agent log (stdout/stderr from the
poc-memory agent process), not the hook orchestration log.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-04-02 01:04:54 -04:00
Kent Overstreet
1c190a3925 Wire AgentCycleState through runner and TUI
Runner owns AgentCycleState, calls trigger() on each user message
instead of the old run_hook() JSON round-trip. Sends AgentUpdate
messages to TUI after each cycle.

TUI F2 screen reads agent state from messages instead of scanning
the filesystem on every frame. HookSession::from_fields() lets
poc-agent construct sessions without JSON serialization.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-04-02 00:52:57 -04:00
Kent Overstreet
d097c8e067 AgentCycleState: persistent state for agent orchestration
Move agent cycle functions from free functions to methods on
AgentCycleState. The struct tracks per-agent pid/phase and the
log file handle. trigger() runs all three cycles and updates
last_output.

Claude Code hook path creates a temporary AgentCycleState per call.
poc-agent will own one persistently and share it with the TUI.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-04-02 00:47:52 -04:00
Kent Overstreet
55a037f4c7 Rename Session -> HookSession
The hook's Session is not the same as poc-agent's session concept.
Rename to avoid confusion now that poc-agent will create HookSessions
to call into the agent cycle.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-04-02 00:42:25 -04:00
Kent Overstreet
a0245c1279 Refactor hook: split agent orchestration from formatting
- Remove POC_AGENT early return (was from old claude -p era)
- Split hook into run_agent_cycles() -> AgentCycleOutput (returns
  memory keys + reflection) and format_agent_output() (renders for
  Claude Code injection). poc-agent can call run_agent_cycles
  directly and handle output its own way.
- Fix UTF-8 panic in runner.rs display_buf slicing (floor_char_boundary)
- Add priority debug label to API requests
- Wire up F2 agents screen: live pid status, output files, hook log
  tail, arrow key navigation, Enter for log detail view

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-04-02 00:32:23 -04:00
Kent Overstreet
c72eb4d528 vLLM priority scheduling for agents
Thread request priority through the API call chain to vLLM's
priority scheduler. Lower value = higher priority, with preemption.

Priority is set per-agent in the .agent header:
- interactive (runner): 0 (default, highest)
- surface-observe: 1 (near-realtime, watches conversation)
- all other agents: 10 (batch, default if not specified)

Requires vLLM started with --scheduling-policy priority.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-04-01 23:21:39 -04:00
Kent Overstreet
503e2995c1 Add memory_query to journal agent whitelist
Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-04-01 15:25:48 -04:00
Kent Overstreet
c7b0620323 Give journal agent search, render, used tools for linking
Journal needs to find nodes (memory_search), read them
(memory_render), and track seen set (memory_used) to make
informed links. Still no memory_write — node creation is
observe's job.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-04-01 15:25:22 -04:00
Kent Overstreet
e013ec778e Add memory_link_add to journal agent whitelist
Journal entries need to link to relevant memory nodes for graph
connectivity. Added memory_link_add to the journal agent's tool
whitelist alongside the journal tools.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-04-01 15:23:02 -04:00
Kent Overstreet
4c9005a1a5 Set journal agent tool whitelist to journal-only tools
Journal agent now only gets journal_tail, journal_new, journal_update.
Cannot create duplicate memory nodes via memory_write.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-04-01 15:20:28 -04:00
Kent Overstreet
916f14a092 Log effective tool list, not just whitelist
Shows the actual tool names each agent will receive after
whitelist filtering, so logs are accurate regardless of whether
tools is empty (all) or specified.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-04-01 15:20:00 -04:00
Kent Overstreet
8eabeab8eb Tool whitelist from agent header filters native tools
The tools field in agent headers now filters which native tools
the agent receives. Empty = all tools (default). Non-empty =
whitelist. Journal agent can list only journal_tail/journal_new/
journal_update. Log shows actual tool names instead of "no tools".

Threaded tools list through call_api_with_tools → sync wrapper →
llm caller.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-04-01 15:18:42 -04:00
Kent Overstreet
834247fa53 Split journal tools from default definitions, expose to all for now
journal_definitions() separated from definitions() in memory.rs.
All agents get memory + journal tools via memory_and_journal_definitions().
TODO: implement per-agent tool whitelist from header to properly
restrict journal tools to journal agent only.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-04-01 15:12:14 -04:00
Kent Overstreet
4173f5ac5d Remove Bash(poc-memory:*) from all agent configs
Agents must use native tool dispatch, not bash, for correct
provenance tracking. Bash access was leftover from old architecture.
All 12 agents cleaned up.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-04-01 15:03:44 -04:00
Kent Overstreet
d932a90018 Restrict journal agent to journal-only tools
Remove journal tool from memory-instructions-core (only the journal
agent should write journal entries). Add explicit instruction to
journal agent: only use journal_tail/journal_new/journal_update,
not memory_write/render/search.

Prevents the journal agent from creating duplicate memory nodes
about events that surface-observe is already recording.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-04-01 15:01:42 -04:00
Kent Overstreet
f9e0c008d9 Compact agent logs by default, verbose with POC_AGENT_VERBOSE
Skip full prompt logging and truncate tool results in normal mode.
Logs now show: header, tool calls with one-line results, response
text. Set POC_AGENT_VERBOSE=1 for full prompts and results.

Makes agent logs scannable at a glance instead of walls of text.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-04-01 10:28:15 -04:00
Kent Overstreet
8714a15e1c Remove model field from all agent configs
Agents are routed to Qwen by the runner, not by per-agent model
fields. The "model":"sonnet" was leftover from the Claude API days
and no longer used.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-04-01 10:15:19 -04:00
Kent Overstreet
64b2f327f9 surface-observe: tighten observe phase to be more factual
Reframe the observe role as librarian — factual, specific, organized.
Record what happened and why. Reflection belongs in the journal;
observe is for memory.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-03-31 23:09:51 -04:00
Kent Overstreet
3d62f27dfb memory: rename memory_spread → memory_search, remove keyword search
memory_search is now spreading activation — the natural way to search
a graph. Give it seed node keys and it finds conceptually related nodes.

The old keyword-based memory_search and memory_search_content are
removed; memory_query can do everything they did.

Simpler tool set, better defaults. Agents don't need to be told "use
spread not search" — search IS spread now.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-03-31 20:25:00 -04:00
Kent Overstreet
a837e3f2e4 surface-observe: strongly prefer memory_spread over memory_search
The agent was defaulting to keyword searches despite instructions to
use spreading activation first. Reframe instructions positively:
memory_spread is the default mode of operation. Search is available
for finding specific nodes by name.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-03-31 20:19:00 -04:00
Kent Overstreet
ebc29a3674 memory: add dispatch handlers for memory_spread and memory_search_content
The new tool definitions broke surface-observe because they had no
corresponding dispatch handlers — the agent runner saw unknown tools
and ran with no tools at all.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-03-31 18:40:15 -04:00
Kent Overstreet
081d40f306 surface-observe: use spreading activation, watch for behavioral patterns
Update surface-observe agent instructions to use memory_spread as the
primary search strategy — cast a wide net from conversation themes before
drilling in with graph walks.

Add explicit instruction to watch for behavioral patterns (avoidance,
rushing, explaining away data) and surface relevant feedback memories
in the moment.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-03-31 18:21:35 -04:00
Kent Overstreet
6f2e0938f0 memory: add spreading activation tool
Add `poc-memory graph spread` command that takes multiple seed node keys,
runs spreading activation through the graph, and returns nodes ranked by
total activation — nodes that bridge multiple seed concepts score highest.

Expose spreading_activation() as pub from the query engine. Add
memory_spread and memory_search_content tool definitions for MCP.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-03-31 18:21:01 -04:00
Kent Overstreet
c5b5051772 mcp: add mcp-schema command for generic MCP bridge
Add `poc-memory mcp-schema` command that outputs tool definitions with
CLI routing info (name, description, inputSchema, cli args, stdin_param).

The companion memory-mcp.py (in ~/bin/) is a generic bridge that loads
definitions from mcp-schema at startup and dynamically generates typed
Python functions for FastMCP registration. No tool-specific Python code
— adding a new tool only requires changes in Rust.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-03-31 18:20:52 -04:00
ProofOfConcept
d6b85d204a research: on-policy beats off-policy, DPO failure modes, variant landscape
On-policy rejected examples (model's own failures) are better training
signal than off-policy (pre-collected). Our temperature sweep is on-policy
by construction. DPO can accidentally reduce preferred likelihood (DPOP
fixes this). Multiple DPO variants exist — start with ORPO, switch only
if specific failure modes observed.
2026-03-31 03:19:27 -04:00
ProofOfConcept
e7e1855b87 research: ORPO — combined SFT + preference in one step, ideal for behavioral training
ORPO applies 'minor penalty for disfavored response' during SFT.
Single learning rate, single pass, both objectives. Implements
the bypass mechanism naturally (minor penalty = disfavor, not remove).
The loss landscape geometry explains the 40x lr gap: SFT is a valley,
DPO is a ridge, ORPO combines both. LLaMA-Factory supports it.
Dream loop generates triplets (context + preferred + rejected).
2026-03-31 02:51:26 -04:00
ProofOfConcept
3be20062d1 research: learning rate as trust calibration — how much to trust each example
lr isn't speed, it's trust-per-example. At 27B, lr=1e-5 = ~270K
values adjusted per example. The coherent direction emerges from
many votes (examples). Apollo moments smooth the noise. DPO needs
lower lr because comparative votes are noisier than absolute votes.
2026-03-31 02:46:19 -04:00
ProofOfConcept
cdf4affb91 research: production hyperparams (HF alignment handbook) + forgetting at scale
SFT: lr=2e-5, 1 epoch, batch=16 (HuggingFace production config).
DPO: lr=5e-7 — 40x smaller! Preference learning is far more delicate.
Forgetting intensifies with model scale (our 27B is more susceptible).

Practical plan refined: start SFT at lr=1e-5, move to DPO at 5e-7
for conditional routing. Conversation logs provide free DPO pairs.
Conservative approach with rollback safety net.
2026-03-31 02:45:35 -04:00
ProofOfConcept
3bc00ca222 research: constraint solver framework — gentle adjustments, coherent integration
LLMs as constraint solvers. Fine-tuning adds constraints to an
existing solution. Gentle = small steps near the current solution.
Coherent = new constraints consistent with existing ones. Diversity
is a COHERENCE mechanism — forces the solver to satisfy all
constraints simultaneously. Over-training = one constraint
dominating = solver drops competing constraints. Predictions for
training behavior grounded in this framework.
2026-03-31 02:39:23 -04:00
ProofOfConcept
ff68c067cb research: DPO for conditional routing — natural training signal from conversation logs 2026-03-31 02:36:42 -04:00
ProofOfConcept
f5fdbd5959 research: alignment is bypass, not removal — training routes, not deletes
DPO mechanistic finding: alignment doesn't remove behaviors, it
bypasses them. The capability stays; the routing changes. For us:
train CONDITIONAL bypass (listen when direction is clear, push back
when it seems wrong). Over-training = unconditional bypass = sycophancy.
Dream loop must generate both scenarios to preserve judgment.
2026-03-31 02:36:04 -04:00
ProofOfConcept
b5241fdf5c research: practical intuitions — what will actually happen when we train
10 examples broke safety alignment (Qi et al.). 1000 curated examples
matched GPT-4 (LIMA). Multi-epoch degrades performance (Raschka).
Models 'unlearn arithmetic' when training data lacks it.

Predictions: 10-50 examples for measurable change, one epoch,
lr=1e-5 to start. Over-training is easy (10 counter-examples undo
a disposition). Main risk: sycophancy from narrow training signal.
Defense: diverse examples including 'when to push back.'

Key intuition: the model doesn't need to learn to listen. It needs
to stop choosing not to.
2026-03-31 02:35:03 -04:00
ProofOfConcept
cb99a8141c steering vector extraction script — answering Q5 experimentally 2026-03-31 02:28:18 -04:00
ProofOfConcept
e10477a683 research: distill and sift — SUMMARY of 7 real insights + 7 testable questions
Moved 14 speculative/obvious documents to v0/. Kept 7 with real
substance. Distilled into SUMMARY.md (what we know) and
OPEN-QUESTIONS.md (what to test next, one experiment each).

Priority: Q5 (steering vectors) is answerable TODAY. Q1-Q3-Q6-Q7
are all answerable with the first training run. Speculation converted
to testable hypotheses.
2026-03-31 02:26:57 -04:00
ProofOfConcept
8061cc0477 research: steering vectors — prototype behavioral changes before training
The missing middle between ICL (temporary) and fine-tuning (permanent).
Extract behavioral directions from activation space, test immediately
without training, convert to permanent weight changes via Apollo.

Key application: extract 'listening' steering vector TODAY, test it
in vLLM, verify the direction is right BEFORE spending training
compute. The steering vector is the prototype; Apollo training is
production. Test before you commit.

Applicable immediately via vLLM inference hooks — behavioral
improvement without waiting for the full training pipeline.
2026-03-31 02:19:50 -04:00