New Tool Radar

AI Agents & Automation

How to Limit the Context Window of a Jan Agent So Long Chats Do Not Overflow

Set a context window limit on a Jan agent so a long chat is trimmed instead of failing when the window fills.

Schematic diagram with three steps: Open the agent settings, Set the window limit, then Test a long chat.

A Jan agent keeps the conversation in the model context window, and a long chat eventually fills it. A context window limit decides how much history the agent keeps: past the limit, the oldest messages are dropped or summarised instead of the run failing.

Before you start

You need Jan running with an agent or assistant that holds long chats. Note the model context size first, because the limit must fit inside it with room left for the reply.

Set the limit in the agent settings

Open the Jan agent settings and set the context window limit to a value below the model maximum, leaving room for the reply. Save the settings and start a fresh chat so the new limit applies from the first message.

Test with a chat longer than the limit

Hold a chat that passes the limit, for example twelve turns on a limit of ten messages, and check the agent still answers the latest question. Then ask about the first turn: the agent should say it no longer has that detail, which confirms the trim happened instead of a failure.

Worked example: A long chat with a fictional bookshop agent

Maple Books is a fictional bookshop. Its Jan agent has a context window limit of 10 messages. The table shows the trim.

Turn User message Kept in context?
1 I want a book about bicycle repair. No, dropped after turn 10
9 What is the price? Yes
10 Is it in stock? Yes
11 Who wrote it? Yes

Expected result (UNTESTED): turns 9 to 11 are answered from context, and turn 1 is no longer remembered after the trim. We checked the Jan agent documentation summary, which describes agent tasks and model settings, but we did not set the limit on a live Jan instance.

Limits

A trimmed context loses early details, so a limit is a trade-off, not a fix: a chat that needs the first turn after twenty turns needs a summary step, not a bigger window. Keep the limit well below the model maximum so the reply always has room.

Sources

See all