Skip to content

Agent context via nanobot, brain search with ranking, stack memory ask - #101

Merged
arthware-dev merged 10 commits into
mainfrom
feat/agent-and-search-improvements
Sep 19, 2026
Merged

arthware-dev merged 10 commits into
mainfrom
feat/agent-and-search-improvements

Conversation

@arthware-dev

@arthware-dev arthware-dev commented Sep 19, 2026

Copy link
Copy Markdown
Contributor

Faster, more reliable vault answers from the local agent, and a
one-call stack memory ask.

Agent

  • Context size is left to nanobot. Removed lean_state (its answer
    placeholders were copied into replies) and the grep-to-search shim
    (grep is literal again).
  • Context window of 32768 set on the active model preset, so
    consolidation runs.
  • Vault tool results join nanobot's microcompact; memory_search capped
    at 8 hits, memory_history at 10.
  • memory_search treats the person as a ranking keyword, not a filter,
    and logs its ranked result paths.

Search

  • Reads the brain instead of the source vault, so generated pages
    (diary) are found. ADR-011 updated.
  • Ranked by keyword rarity (IDF), then date.
  • Matches title and tag values; folds diacritics.
  • Excerpt shows the matching line with its section heading.

stack memory ask

  • Question in, answer with [N] citations and sources out, like
    stack web ask. One model call; searches with the question's own
    words.

Other

  • CLAUDE.md loads AGENTS.md and the role guides.
  • Design note docs/design/brain/content-pattern.md: one content
    pattern for the brain, diary cards in the vault.

Measured on a diary question: the answer page is now found by the first
search (before: 72-89 s, found by grep).

Unit suite green. Agent changes tested on the live agent; the result
caps and context window are live since the last rebuild and not yet
observed in use. stack memory ask is covered by unit tests only.

Replacing prior tool-turn answers with "[earlier answer from ...]"
taught the model that format. In a long room it sent the placeholder
as its reply and repeated the same grep.

- lean_state: only prior tool results become pointers
- test: no assistant message holds a placeholder after 10 tool turns
- log entry in agent-improvement-log.md
…rep routing

Our context shims worked against nanobot's own mechanisms. lean_state
duplicated microcompact, broke the prefix cache, and its "re-run"
placeholders made the model repeat tool calls. grep_tool ran regex
patterns as semantic queries, so the model retried the same grep.

- lean_state removed; state_log keeps the debug log, opt-in via
  AGENT_STATE_LOG=1
- grep_tool removed; vault grep is literal again
- compact_tools: vault read tools join nanobot's microcompact set
- config.json: context_window_tokens 32768, so token consolidation and
  history snip act (budget 23.5k) and prefill stays short
- agent-lab: replay subcommand removed with lean_messages
- ADR-012 update, improvement log entry
Claude Code reads CLAUDE.md, not AGENTS.md, so the repo rules were never
in its context.

- CLAUDE.md imports AGENTS.md, docs/agent/ops.md, docs/agent/dev.md
- .gitignore: keep the root CLAUDE.md, still ignore nested ones
Search read the source vault and sorted by date. Generated pages (the
diary) exist only in the brain, and the newest pages naming a person
filled the limit before the page with the rare word.

- search reads memory/brain (memory/vault before the first curator run);
  no Forgejo pull on the brain, the curator writes it
- rank: each top-level alternative scores its IDF, then date; one
  keyword keeps date order
- excerpt: the line with the rarest matching keyword
- "matches:" line for multi-keyword queries
- title/tag values and diacritic folding from 2ca1116
- ADR-011 update: search reads the brain
- person becomes a ranking keyword, not a --person filter; a parent's
  diary entry about a child does not list the child
- stderr block per search: query, regex, count, path and matched
  keywords per hit; no page text
- description matches what the output contains
Same shape as stack web ask: question in, short answer with [N]
citations and sources out. One model call; the search uses the
question's own words, because the --nl rewrite adds ontology words
that outrank the answering page.

- host: search the brain, send top hits as JSON to the bot-runner
- bot-runner: `answer` command, 600-token cap
- --json, --sources N; timing line on stderr
- sources print when the model is unreachable (exit 1)
nanobot reads context_window_tokens from the active preset (default
200000); the value under agents.defaults was ignored, so token
consolidation still budgeted against 200000.

- config.json: context_window_tokens 32768 on model_presets.primary
- test: the window sits on the active preset, not under defaults
A diary month is one page and the day is its heading, so the matching
line alone did not say when; the agent read the page again to find out.

- excerpt: "<nearest heading> › <line>"; the heading alone when it matched
Tool output is prompt the model reads before its next step; on the
local model each 1k tokens costs 5-7 s of prefill. The model asked for
20 hits and 30 changes, most of them noise.
Design note, nothing built. Every brain page gets the document pattern
(frontmatter, summary and facts, ontology tags, OKF fields). The diary
gets one card per entry in the vault, posted as a thread reply on the
entry's last main-timeline message and corrected by replying in that
thread, like documents; the warm diary pages are compiled from the
cards.

- entry unit open: message group, day or occasion
- built as a second compiler and compared against the current one
@arthware-dev
arthware-dev merged commit 46fc014 into main Sep 19, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant