Adaptive Context Planner
Fit heterogeneous context into a real model budget without weakening hard constraints.
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.
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.
Questions
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.