feat: split AI context into on-demand tools, route AI through AD4M - #196
Open
HexaField wants to merge 6 commits into
Open
feat: split AI context into on-demand tools, route AI through AD4M#196HexaField wants to merge 6 commits into
HexaField wants to merge 6 commits into
Conversation
✅ Deploy Preview for coasys-we ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Split the 297K monolithic schema context into a compact core prompt (~7K tokens) plus 8 on-demand context tools the model calls to load schema sections. Context tools resolve locally in the browser from a pre-compiled section map — zero latency, no round-trip. Build-time changes (ai-context): - assembleCoreContext(): rules + routing + entities + tokens + directory - assembleContextSections(): Record<string, string> per tool name - assembleContextToolDefs(): provider-neutral tool definitions - generate.ts writes coreContext.ts, contextSections.ts, contextToolDefs.ts - schemaContext.ts kept unchanged for IDE agents Runtime changes (app-shell): - aiInfra.ts: add Ollama ndjson streaming alongside Anthropic SSE - aiInfra.ts: sendPromptRequest() dispatches by protocol - aiInfra.ts: buildToolsForProvider() adapts tool defs per wire format - EditorStore: handle context tools alongside update_schema in the loop - EditorStore: provider auto-detection (Anthropic key -> anthropic, else ollama) - templateSurface.ts: classify aiProtocol + providerReady as WIRING Token cost: simple edits drop from 74K to ~7K cached tokens (−90%). Complex edits load only the sections they need. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ons, live Ollama 24 tests covering the AI infrastructure layer: Deterministic (mocked streams): - parseOllamaStream: text extraction, tool calls, split chunks, malformed JSON recovery, max_tokens mapping (7 tests) - parseAnthropicSSE: text extraction, tool_use blocks, [DONE] sentinel, non-data lines, malformed recovery (5 tests) - buildToolsForProvider: Anthropic vs Ollama wire format (3 tests) - formatExternalManifestForPrompt: properties + relations (3 tests) - loadContextSections: key names, content, coverage (3 tests) Live integration (localhost:11434, skip when unavailable): - Text streaming against real Ollama (1 test) - Context tool triggering — non-deterministic, graceful skip (1 test) - Full tool loop: prompt → tool call → resolve → response (1 test) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The CI 'generated files are committed' check regenerates context files and compares. Lint-staged was reformatting the generator output through prettier, causing a mismatch. Add coreContext.ts, contextSections.ts, contextToolDefs.ts, and context.json to .prettierignore alongside the existing schemaContext.ts entry. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replace direct Anthropic/Ollama dispatch with a single AD4M endpoint. WE sends all AI requests to the executor's OpenAI-compatible surface; the executor handles provider resolution (Anthropic, Ollama, OpenAI). - Remove AiProtocol, ProviderConfig, sendAnthropicRequest, sendOllamaRequest, parseAnthropicSSE, parseOllamaStream, buildToolsForProvider, toOllamaWireMessage - Add Ad4mConnection (baseUrl + token from SessionStore) - Add parseOpenAISSE for OpenAI delta-chunked SSE streaming - Add buildTools (OpenAI function-calling format only) - Add toOpenAIMessage to translate Anthropic content blocks - EditorStore gets connection from useSessionStore instead of hardcoded Ollama/Anthropic config - Tests rewritten: 7 parseOpenAISSE + 3 buildTools + 3 manifest + 3 context sections + 3 live AD4M integration = 19 tests, all pass Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Dev added options to DisplayField (PR #195). Regenerate the three context files whose stores reference now includes the field. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
HexaField
force-pushed
the
feat/ai-context-tools
branch
from
September 11, 2026 12:10
49d5705 to
0e30b50
Compare
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
Split the monolithic 297K-char AI context into a compact core prompt (~7K tokens) plus 8 on-demand context tools. Route all AI requests through AD4M's
/v1/chat/completionsendpoint instead of calling Anthropic or Ollama directly from the browser.Why
The monolithic context consumed ~75K tokens on every request, regardless of task complexity. Direct browser-to-provider dispatch duplicated transport logic and bypassed AD4M's model management. James's PR #996 adds native provider support (Anthropic, Ollama, OpenAI) to AD4M — WE should use that surface instead of maintaining its own provider implementations.
How
Context split — build-time assembly into three artifacts:
we_stores_referencewe_schema_operatorswe_component_registrywe_common_patternswe_design_propswe_plugin_registrieswe_store_patternswe_panelsAD4M routing — single transport path:
Removed:
sendAnthropicRequest,sendOllamaRequest,parseAnthropicSSE,parseOllamaStream,AiProtocol,ProviderConfig,buildToolsForProvider.Added:
Ad4mConnection,parseOpenAISSE,buildTools(OpenAI format only),toOpenAIMessage(Anthropic content-block → OpenAI translation).Tool resolution loop — unchanged, runs in EditorStore. Context tools resolve from the local section map with zero latency.
Builds directly on #996.
Tests: 19 pass — 7 parseOpenAISSE, 3 buildTools, 3 formatExternalManifestForPrompt, 3 loadContextSections, 3 live AD4M integration (skip when executor unavailable).