Skip to main content

Context Curation, Hybrid Vector RAG & Stateless MRTR

Keep AI prompts lean by consolidating bloated API wrappers, and pause multi-step sub-agents cleanly without holding server RAM.

Engineer deterministic context windows for district EdTech curricula using hybrid vector retrieval, citation-preserving resource URIs, and stateless Multi-Round Tool Reasoning (MRTR) without server-side session leaks.

Key Terms in This Lab:RAG & Agents1:1 OpenAPI Tool BloatIn plain English: Auto-wrapping 35 CRUD endpoints floods tools/list with ~14,800 schema tokens, confusing the model and slowing routing. Consolidating them into 5 intent-driven workflow tools cuts tokens by over 80%.Analogy: Handing a diner a 35-page raw kitchen ingredient binder instead of a clean 5-item café menu.On Azure Stack: Refactored in FastMCP 4 from 35 LMS REST endpoints into 5 workflow tools for Agent Framework.RAG & AgentsContext Window & Token BudgetIn plain English: Every tool description, JSON schema, and retrieved document sent to the model consumes tokens—costing money, adding latency, and diluting attention. Keeping schemas compact preserves room for actual reasoning.Analogy: Desk space while taking an exam: if you pile 35 binders on the desk, there is no room left to write.On Azure Stack: Measured with tiktoken before dispatching prompts to Azure OpenAI.RAG & Agents2026-07-28 ttlMs & cacheScopeIn plain English: Because stateless HTTP runs fresh per request, re-downloading tool schemas on every turn wastes time. Returning ttlMs (e.g. 300000 ms) and cacheScope ("tenant") lets hosts reuse schemas safely.Analogy: Printing "Menu valid for 5 minutes" so guests do not ask the kitchen to reprint the menu every bite.On Azure Stack: Emitted in tools/list _meta and cached by Microsoft Agent Framework per district tenant.RAG & AgentsHybrid Vector + Semantic RAGIn plain English: Retrieval-Augmented Generation (RAG) fetches verified curriculum passages before the model answers, returning stable resource URIs (like edtech://district-01/rubrics/...) so educators can audit every claim.Analogy: Using both the book index (keywords) and a librarian who understands meaning (vectors) to find exact pages.On Azure Stack: Azure AI Search combining BM25 keyword + vector embeddings + Semantic Ranker.RAG & AgentsStateless MRTR (Multi-Round Tool Reasoning)In plain English: Sometimes a sub-agent discovers missing info (like which grade band to score against). In stateless MRTR, the tool returns InputRequiredResult + a state_handle, lets the UI ask the user, and resumes on any container.Analogy: Putting a numbered bookmark in a book and handing it back—any clerk can pick up right where you stopped.On Azure Stack: Saves MRTR state in Azure Cosmos DB or Azure Managed Redis using Entra Managed Identity.RAG & AgentsOpaque state_handleIn plain English: Instead of keeping pause state in server RAM (which vanishes on scale-in), the server writes a checkpoint to a fast external store and hands the client an opaque state_handle ID to send back on the next turn.Analogy: A coat-check claim ticket: you do not carry the coat, and any attendant can retrieve it from the rack.On Azure Stack: Prefixed az-cosmos-mrtr-... backed by Azure Cosmos DB / Azure Managed Redis.RAG & AgentsDeprecated Sampling PatternIn plain English: Server-initiated Sampling required a long-lived stateful connection while waiting for the client—breaking stateless serverless scaling. Modern 2026-07-28 workflows replace it with InputRequiredResult + state_handle.Analogy: Keeping a phone call on hold for 10 minutes instead of hanging up and calling back with a ticket number.On Azure Stack: Replaced by stateless InputRequiredResult + Cosmos DB/Redis on Azure Container Apps.
Microsoft Azure Stack:
Azure AI Search (Hybrid + Semantic)Microsoft agent-framework + Azure AI Foundry
Details
Vector & Hybrid RAG
Azure AI Search (Hybrid + Semantic)

BM25 + vector retrieval with semantic reranking over district curriculum corpora.

GCP equivalent: Vertex Vector Search
Agent Orchestrator SDK
Microsoft agent-framework + Azure AI Foundry

Typed Python agent orchestration binding FastMCP 4 and mcp v2 tool contracts.

GCP equivalent: Google ADK
Concept Escalator

1. Visual Analogy · Concise 5-Item Café Menu vs. 35-Page Kitchen Binder + Bookmark Ticket

Intuition First
Start Here · Plain-English Concept Brief
~5 min

How do we stop 35 API endpoints from eating our token budget—and pause for human input across stateless servers?

Think of an LLM’s context window as a small desk. If you dump 35 raw REST API schemas onto the desk before asking a question, the model gets slower, costs more, and picks the wrong tool. Meanwhile, when a rubric tool needs a teacher to clarify a grade band, it should drop a bookmark ticket in a database instead of freezing a server.

How this fits: This is Piece 3 (RAG & Agent). Once your transport and Python contract work, you make tool selection accurate, ground answers in real curriculum data, and support human-in-the-loop pauses.

  • Consolidate raw CRUD routes into 5 workflow tools and add ttlMs caching to cut token overhead >80%.
  • Return InputRequiredResult + an opaque state_handle instead of deprecated stateful Sampling calls.
  • Resume statelessly on any cloud container and cite grounded passages from Azure AI Search or Vertex AI Search.

Dumping 35 auto-wrapped OpenAPI routes into tools/list is like handing a hungry guest a 35-page raw kitchen inventory binder. Curating 5 workflow tools with ttlMs caching gives the model a crisp café menu, while a stateless MRTR state_handle acts like a bookmark ticket stored in Cosmos DB/Redis or Firestore/Memorystore when educator input is needed.

Engineering Takeaway: Consolidating routes cuts schema tokens by >80%, and stateless InputRequiredResult + state_handle replaces deprecated Sampling across serverless replicas.
Quick Concept Check (Optional)

In 2026-07-28 stateless MCP, how should a sub-agent pause to ask an educator for a missing grade band?

Step 1 of 3 ready? Move on to see how the pieces connect visually.

Engineering Scratchpad

Auto-saved per lab in mcp_foundry_v1_scratchpads

0 chars saved