HKUDS/nanobot · error · TypeError
context_window_tokens must be an integer
Error message
context_window_tokens must be an integer
What it means
Type guard in LLMRuntimeManager.select_context_window: the caller passed a context_window_tokens argument that is not an int (bool is explicitly rejected too, since bool subclasses int). The value must be a real integer token count before the runtime's default context limit is replaced, because downstream admission logic does arithmetic on it.
Solutions
- Coerce the value with int() before calling select_context_window
- Fix the config source so the context window is stored as an integer
- Reject non-integer input at the API/config boundary with a 4xx error
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at nanobot/agent/model_runtime.py:159 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of HKUDS/nanobot@42f37dc4c0 (2026-08-26).
Data as JSON: /api/errors/ab030f051d28d75b.
Report an issue: GitHub.
Appendix: source
Thrown at nanobot/agent/model_runtime.py:159
def select_model(self, model: str) -> LLMRuntime:
"""Change the default model without reconstructing downstream consumers."""
if not isinstance(cast(object, model), str) or not model.strip():
raise ValueError("model must be a non-empty string")
self._runtime = replace(
self._runtime,
model=model.strip(),
model_preset=None,
)
return self._runtime
def select_context_window(self, context_window_tokens: int) -> LLMRuntime:
"""Change the default context limit for future admissions."""
raw_context_window = cast(object, context_window_tokens)
if not isinstance(raw_context_window, int) or isinstance(
raw_context_window,
bool,
):
raise TypeError("context_window_tokens must be an integer")
self._runtime = replace(
self._runtime,
context_window_tokens=context_window_tokens,
)
return self._runtime
def _refresh_provider_generation(self) -> LLMRuntime | None:
"""Adopt direct provider-default changes only for provider-backed defaults."""
if not self._tracks_provider_generation:
return None
runtime = self._runtime
captured = LLMRuntime.capture(
runtime.provider,
runtime.model,
context_window_tokens=runtime.context_window_tokens,
model_preset=runtime.model_preset,
snapshot_signature=runtime.snapshot_signature,
)View on GitHub (pinned to 42f37dc4c0)