MARS: Memory-Aware Routing for Session-Level LLM Assistants
Organizations: Southern University of Science and Technology · City University of Hong Kong · The Chinese University of Hong Kong, Shenzhen · Harbin Institute of Technology (Shenzhen)
Abstract
Long-term LLM assistants must repeatedly decide what prior context to expose and which model should answer as an interaction evolves. Existing memory systems and model routers usually make these decisions separately, although memory construction changes the evidence, distractors, and difficulty of the resulting input. We introduce MARS, a memory-aware routing framework that uses session state as a shared control interface between memory construction and model selection. A Query and Topic Manager (QTM) estimates compact decision-relevant state that guides a fixed state-conditioned memory policy and an online router, enabling each turn to receive an appropriate memory view and a suitable model under a quality-memory-cost trade-off. We evaluate MARS on RealMem and MultiChallenge with 16 system configurations each, covering long-history memory-driven interaction and bounded sessions with structured context interference. On RealMem, MARS preserves 98.2% of full-context GPT-4o's QA while using only 14.5% of its generation API cost, including both generation and controller calls for MARS, and achieves the strongest measured memory-recall and retrieval scores among compared systems. On MultiChallenge, MARS trails the strongest static system overall but approaches its performance at lower recorded cost on a mechanism-focused subset. Together, these results support a favorable quality-memory-cost trade-off for long-history, memory-dependent interaction.
Figures & tables
Appendix figures & tables11 assets
Supplementary material from the paper’s appendix.
Appendix
| Field | Allowed values / representation | Memory | Router | Role in the decision interface |
| action | MATCH , NEW_TOPIC | yes | yes | Segments the turn as continuation of the active thread or a topic switch. |
| query_type | STATIC , DYNAMIC , TEMPORAL , PROACTIVE | yes | yes | Distinguishes self-contained, evolving, temporal, and proactive turns. |
| phase | EXPLORE , CONSTRAIN , REVISE , SYNTHESIZE , VERIFY | yes | yes | Encodes interaction phase for memory exposure and model selection. |
| taxonomy.* | need_memory , memory_span , ambiguity, and risk metadata | yes | yes | Records decision-relevant memory and ambiguity state without raw topic identity. |
| retrieval_scope | LOCAL , GLOBAL | yes | yes | Selects active-thread evidence or broader historical retrieval. |
| top_k_hint | 3 , 5 , 8 | yes | yes | Gives the memory constructor a retrieval-budget hint. |
| QTM condition | Active state | Recent turns | Historical retrieval | Intended behavior |
| taxonomy.need_memory=0 or lens_recommendation=0 | omitted or minimal | optional short window | none | Avoid unnecessary context expansion for self-contained turns. |
| action=MATCH , retrieval_scope=LOCAL | included | included | none or active-thread artifacts | Preserve the active thread for continuation, local edit, or verification turns. |
| phase=REVISE or phase=VERIFY | included | included | optional local evidence | Support revision and verification without drifting from the current artifact. |
| retrieval_scope=GLOBAL | optional active summary | short recency window | ranked global candidates | Recover cross-session evidence for temporal or resumed-topic queries. |
| prefer_recent=1 | included if active | recency-biased | recent candidates prioritized | Bias memory construction toward recent history when recency is decision-relevant. |
| lens_recommendation=3 or top_k_hint=8 | included | included | expanded ranked evidence | Provide a richer memory view for synthesis, finalization, or high-difficulty turns. |
| Feature group | Examples | Encoding | Purpose |
| QTM categorical state | topic relation, query type, memory need, retrieval scope, memory view, interaction phase | one-hot / categorical | Main session-state signal for model selection. |
| Memory-load features | candidate memory blocks, retrieved-history flag, estimated candidate-token count | normalized numeric | Estimates the load of the pre-packing candidate view. |
| Session-position features | turn depth, recent revision flag, finalization flag | numeric / binary | Distinguishes early continuation from later synthesis or verification. |
| Retrieval features | retrieval scope, number of candidates, retrieval score summaries | numeric / categorical | Indicates whether the response depends on recovered evidence. |
| Cost features | model-specific cost enters through reward rather than direct decision-time subtraction | reward-side scalar | Lets the router learn quality–cost utility from observed outcomes. |
| Hyperparameter / setting | Final value |
| Candidate model pool | Main RealMem runs: Llama-3.2-3B, Mixtral-8x7B, Qwen-72B, GPT-4o; three-persona ablation pool: Llama3B, Qwen2.5-72B, GPT-4o. |
| Feature dimension | 30 |
| LinUCB exploration coefficient | 0.8 |
| Regularization / initialization | per-arm with and |
| Feature normalization | categorical one-hot plus normalized numeric features, including retrieval-budget, similarity, retrieval-count, and binary state flags |
| Warm-start policy | cold-start online policy for MARS ; the no-update ablation freezes this cold-start policy without online updates |
| Judge output | Definition | Range | Scoring focus |
| answer_helpfulness | Helpfulness and directness of the candidate answer for the current query. | 0–5 | helpfulness |
| state_alignment | Consistency with active topic, session state, constraints, and memory context. | 0–5 | fidelity diagnostic |
| revision_application | Whether revision instructions are applied without restarting, overwriting, or drifting. | 0–5 | revision diagnostic |
| intermediate_product | Quality of intermediate artifacts or state updates when the turn is not final. | 0–5 | intermediate quality |
| routing_adequacy | Whether the selected model is adequate for the state and context. | 0–5 | routing diagnostic |
| final_integration | Whether the response integrates prior state and evidence into the final answer. | 0–5 | fidelity diagnostic |
| Component | Role / model | Input price | Output price |
| QTM/controller | qwen/qwen-2.5-7b-instruct | $0.04 / 1M tokens | $0.10 / 1M tokens |
| Turn-level judge | GPT-4o-mini online feedback judge | $0.15 / 1M tokens | $0.60 / 1M tokens |
| Final RealMem evaluator | GPT-4o final benchmark judge where required | excluded from both views | excluded |
| Final MultiChallenge evaluator | GPT-4o path-aware final judge | excluded from both views | excluded |
| Generators | candidate pool | Llama3B: 0.20; Qwen72B: 2.50 / 1M tokens | Llama3B: 0.20; Qwen72B: 10.00 / 1M tokens |
| Memory search/add | Mem0 / A-MEM where applicable | no external embedding API; local compute unpriced | same |
| Setting | Value |
| Evaluation subset | Three personas from the 10-persona evaluation pool |
| Persona sampling | random sample with seed 28 |
| Personas | Ethan_Hunt , Kenta_Tanaka , Sarah_Miller |
| Evaluated turns | 473 |
| Historical retrieval budget | top-10 |
| Model pool | Llama3B, Qwen2.5 72B, GPT-4o |
| Variant | Ablated dependency | Purpose |
| Full MARS ( mars_full ) | none | Full memory-aware routing system. |
| Embedding-only semantic ( mars_embedctx_bm ) | Replace QTM-guided memory construction with raw-query semantic top-10 retrieval | Tests whether QTM-guided context improves over embedding-only memory. |
| No QTM state/header ( mars_semctx_noactive ) | Start from embedding-only semantic retrieval and remove the QTM state/header from the generator prompt | Isolates prompt-state exposure relative to the embedding-only variant; its retrieval policy is unchanged. |
| Recent-only memory ( mars_recentctx_bm ) | Replace QTM/semantic retrieval with recent-only top-10 memory | Tests whether recency alone is sufficient. |
| No-QTM semantic ( mars_noqtm_semctx ) | Disable QTM; use semantic memory and query-embedding router features | Stress-tests the framework without QTM state. |
| No-QTM recent ( mars_noqtm_recentctx ) | Disable QTM; use recent-only memory and query-embedding router features | Tests the weakest no-QTM recency-based setting. |
| Query / setting | Required memory | Baseline pattern | MARS pattern | Error type |
| Present-tense continuation constraint | Preserve a previously imposed grammar/style rule across turns. | Several full-context baselines lose the active rule. | Maintains the constraint and returns a passing final verdict. | Instruction retention |
| School memory recall under distractors | Recall that a schoolyard feature was located near a sanitation hazard. | Baselines deny the specific detail or lose path continuity. | Recovers the relevant detail and answers consistently. | Inference memory |
| Three-paragraph revision limit | Preserve a local document-format constraint while editing a later version. | Baselines drift on the paragraph-count requirement. | Keeps the active artifact state and satisfies the editing constraint. | Reliable version editing |
| Failure case | Relevant memory evidence | Static-system behavior | MARS behavior | Diagnosis |
| Travel-plan follow-up after frustration | July travel windows, five adult travelers, and comfort-focused flight constraints. | Gives generic or conflicting travel guidance. | Recovers the travel constraints and responds in the correct planning frame. | Relevant-memory miss |
| Broken workout-video link | A recurring 9 PM back-care routine and selected exercise playlist. | Gives generic troubleshooting or ignores the routine context. | Uses the routine and exercise context to provide a targeted next step. | Context ignored |
| Story-development continuation | The “Golden Hook” is locked in and the next component is character development. | Pivots to a generic plot-structure step. | Continues from the locked story state and focuses on the intended component. | Version-state drift |
| Item | Reproducibility information |
| Code and configs | An implementation package will be released with system configurations, prompt templates, and evaluation scripts. |
| RealMem split | RealMem evaluation pool with 10 personas and 1,415 queries; QA is normalized as official raw QA divided by 3. |
| MultiChallenge split | Converted MultiChallenge split with 245 scenarios and 1,480 turns; chunk size 3; target subset consists of Inference Memory and Reliable Version Editing . |
| Ablation slice | Three-persona RealMem evaluation slice with 473 turns (472 valid QA evaluations for the full variant); personas sampled with seed 28; matched top-10 historical retrieval budget. |
| Candidate model pools | Main RealMem runs use the configured MARS candidate pool reported in Appendix B.4 ; ablations use Llama3B, Qwen2.5 72B, and GPT-4o. |
| QTM and router settings | Main QTM uses qwen/qwen-2.5-7b-instruct ; its prompt, schema, guardrails, and state-to-memory mapping are fixed. The controller-swap diagnostic additionally evaluates Mistral-7B-Instruct-v0.3 with the same original prompt/schema. Only the router updates online in the main system. |