# Adaptive Context Planner

> **Upcoming in 1.0 (preview). These pages describe the main branch of LLMSlim Core, which becomes the 0.13 release candidate and then 1.0. `pip install llmslim` installs 0.12.0 today, which doesn't have everything described here.** Docs for what pip installs: https://www.llmslim.app/docs.md

> Fit heterogeneous context into a real model budget without weakening hard constraints.

Build deterministic, explainable context plans across instructions, chat, retrieval, memory, and tool contracts.

Category: Core Concepts · Version: 1.0 · Updated: November 2026 · 6 min read

## Create a plan

Choose a model profile, policy, and output-token reserve. The planner generates safe representation candidates, allocates them deterministically, validates the result, and explains every decision. An infeasible plan says why in plan.warnings; pass raise_on_infeasible=True to get a ContextPlanningError instead.

planner.py:

```python
from llmslim import plan_context

plan = plan_context(
    messages=[
        {"role": "system", "content": "Answer only from supplied evidence."},
        *messages,
    ],
    documents=documents,
    tools=tools,
    model="sarvam-105b",
    policy="balanced",
    reserve_output_tokens=1024,
)

if not plan.feasible:
    raise RuntimeError("; ".join(plan.warnings))
print(plan.final_context)
```

## Policies and validation

Balanced, quality-first, cost-first, and latency-first policies change the utility tradeoff, not the trust boundary. Post-plan validation can conservatively fall back to safer candidates.

> **Planning is not authorization:** Tool schema selection never grants permission to call a tool. Preserve authorization, argument validation, and execution in the host.

## FAQ

### Can the planner drop trusted instructions?

No. Required trusted items are hard constraints. If they cannot fit, the plan is explicitly infeasible.

### Does planning call an LLM or execute tools?

No. Offline planning is local and deterministic. The separate hosted Sarvam mode calls a model only after server-side quota and spend checks; tool execution remains the host's responsibility.

### Is the hosted Sarvam key sent to the browser?

No. The key is read only by the server function and is never included in client configuration, responses, telemetry, or browser storage.

## Related

- [Provenance and ContextRole](https://www.llmslim.app/docs/1.0/context-role.md)
- [MCP catalogs and agent hosts](https://www.llmslim.app/docs/1.0/mcp-catalogs.md)

Canonical page: https://www.llmslim.app/docs/1.0/adaptive-context-planner
