feat: directive recall + pre-tool-use hook#11
Open
felix-xtrace wants to merge 2 commits into
Open
Conversation
SDK surface for procedural-memory directive recall (the VecDB recall route):
- types: ActionContext, DirectiveDetails, DirectiveMemory, DirectiveListEnvelope,
RecallDirectivesParams — self-contained, no change to the core Memory union.
- memories.recallDirectives({ action | entities, task, mode }): typed sugar over
POST /v1/memories/search with include:[lesson,procedure]; defaults mode="retrieve"
(fast stage-1 lane). Client-side firing-rule guard throws if neither a non-empty
action nor entities is given (mirrors the server 422).
- renderDirectivesPrompt(): deterministic inject-ready markdown.
- ai-sdk: withDirectiveRecall(tools, opts) — a pre-tool-call hook that recalls the
directives for each tool's {name,args} before it runs and prepends them to the
result; directiveContextForToolCall() primitive. Fails soft.
7 tests; typecheck + full suite (53) + build green. Built on main (hand-written SDK);
re-port to the Stainless `next` line when that lands.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
examples/agent_loop_demo.ts runs the same task (make the judge model configurable in
scripts/memory_quality_sweep.py) through a Vercel AI SDK loop twice — plain tools vs
withDirectiveRecall. With recall, the captured lesson ("thread judge_model through the
scoring path instead of hardcoding JUDGE_MODEL") fires on read_file and the agent adopts the
team convention (judge_model); without it, the agent uses a generic `model` param. Reads all
creds from env (no hard-coded paths). Adds @ai-sdk/openai as a dev dependency for the example.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds the
@xtraceai/memorysurface for procedural-memory directive recall — the read side of the directive loop now live on the VecDB memory API. An agent can recall the situatedlesson/proceduredirectives keyed to what it's about to touch, and the AI SDK integration fires it automatically before each tool call.API
memories.recallDirectives({ action | entities, task, mode })— sugar overPOST /v1/memories/searchwithinclude:[lesson,procedure]. Defaultsmode:"retrieve"(the right lane for a per-tool-call hook). A client-side firing-rule guard throws if neither a non-emptyactionnorentitiesis given (mirrors the server's422— directives fire on symbols, not a query).renderDirectivesPrompt(directives)— deterministic inject-ready markdown (forretrieve, where the server doesn't pre-render).withDirectiveRecall(tools, opts)(ai-sdk) — wraps a tools object so each tool's{name, args}recalls its directives before it runs and prepends them to the result;directiveContextForToolCall()is the underlying primitive. Fails soft — a recall hiccup never breaks a tool; tools withoutexecutepass through.ActionContext,DirectiveDetails,DirectiveMemory,DirectiveListEnvelope,RecallDirectivesParams— self-contained, so the coreMemorydiscriminated union and its render path are untouched.Tests
7 new (
src/directives.test.ts): body shape +retrievedefault, the firing-rule guard (incl. fieldlessaction), explicit-entities +compose+task, render output, and the AI SDK wrapper (recall-before-exec + inject + pass-through + fail-soft).typecheck+ full suite (53) +buildall green.Note on the branch
Built on
main(the hand-written SDK) for the fast path. The repo has a Stainless-generatednext(v0.2.0) line in flight; when that lands, the directive types should flow from the OpenAPI spec (which the API already emits) and therecallDirectivessugar +ai-sdkhook re-port as hand layers on top.🤖 Generated with Claude Code