Sizing Ollama for agent work: context length and keep-alive
Answer: Ollama's docs say tasks like agents and coding tools need a context length of at least 64000 tokens. A larger context length increases the memory required, so check VRAM first.
Context length
Context length is the maximum number of tokens the model has access to in memory. The context-length page lists defaults by VRAM:
- under 24 GiB: 4k context;
- 24-48 GiB: 32k context;
- 48 GiB or more: 256k context.
The FAQ still says the default context window size is 4096 tokens, overridable with OLLAMA_CONTEXT_LENGTH. A larger context length increases the memory required to run a model. For best performance, avoid offloading the model to CPU and verify the split under PROCESSOR with ollama ps.
Keep-alive
- Models are kept in memory for 5 minutes before being unloaded by default.
keep_aliveon/api/generateand/api/chatsets how long a model stays loaded; a negative number keeps it loaded,0unloads immediately.OLLAMA_KEEP_ALIVEchanges the time all models are loaded into memory; thekeep_aliveAPI parameter overrides theOLLAMA_KEEP_ALIVEsetting.ollama stopunloads a model immediately.
See also
Claims
- id: C1 claim: Agent tasks need at least 64000 tokens of context. source: S1 evidence: "agents, and coding tools should be set to at least 64000 tokens."
- id: C2 claim: Larger context needs more memory. source: S1 evidence: "will increase the amount of memory required to run a model."
- id: C3 claim: Models stay loaded 5 minutes by default. source: S2 evidence: "By default models are kept in memory for 5 minutes before being unloaded."
- id: C4 claim: keep_alive overrides OLLAMA_KEEP_ALIVE. source: S2 evidence: "endpoints will override the
OLLAMA_KEEP_ALIVEsetting."
Sources
- [S1] Context length. Ollama docs (GitHub). https://github.com/ollama/ollama/blob/main/docs/context-length.mdx . License: MIT (ollama/ollama LICENSE). Accessed 2026-11-09.
- [S2] Ollama FAQ. Ollama docs (GitHub). https://github.com/ollama/ollama/blob/main/docs/faq.mdx . License: MIT (ollama/ollama LICENSE). Accessed 2026-11-09.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: GitHub repository docs under Apache License 2.0 (https://www.apache.org/licenses/LICENSE-2.0) or MIT License (https://opensource.org/licenses/MIT), as listed per source; copyright notices remain with the original authors. Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Ollama docs (GitHub), Context length, MIT (ollama/ollama LICENSE); Ollama docs (GitHub), Ollama FAQ, MIT (ollama/ollama LICENSE).
Cite this
iinventedlight. 2026. "Sizing Ollama for agent work: context length and keep-alive." iinventedlight Library, iil:note:sh9ew70m, version of 2026-11-09. https://iinventedlight.com/library/notes/ao-idlehw-ollama-context-and-keepalive/. License: CC-BY-4.0.
@misc{iil_note_sh9ew70m,
author = {{iinventedlight}},
title = {{Sizing Ollama for agent work: context length and keep-alive}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-09},
url = {https://iinventedlight.com/library/notes/ao-idlehw-ollama-context-and-keepalive/},
note = {Permanent ID iil:note:sh9ew70m. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com.
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/ao-idlehw-ollama-context-and-keepalive.md.