# 各模型的上下文窗口

Canonical URL: https://developers.iagenify.com/zh/sdk/agent/context/window/
Language: zh

引擎从目录中读取真实窗口, 并且绝不允许您要求更多。 默认值为20万, 不论模式允许什么 。

Status: read from the catalogue · cached 10 minutes · context_too_large

## 如何决定限额 {#resolution}

- 模型窗口从 [(目录)](/zh/sdk/ref/iagenify/catalogue) 开始跑步 保持十分钟
- 无 `contextTokens`,限制是 **小** 和那扇窗户
- 与 `contextTokens`这就是极限——除非它大于被拒的窗口。

```javascript
// Default on a model with a 1 048 576-token window → limit 200 000
api.agents.create({ runtime: "local", machine: pc, model: "gemini-3.5-flash" });

// Asking for more than the model has
api.agents.create({ runtime: "local", machine: pc, model, contextTokens: 2_000_000 });
// IaGenifyError context_too_large: contextTokens (2,000,000) is larger than
// the context window of … (1,048,576 tokens).
```

## 接受接受的 {#validation}

| Name | Type | Requirement | Description |
| --- | --- | --- | --- |
| `contextTokens` | integer | 200 000 | 几件全记号 **至少 10 000 个以上**。其他任何拒绝的 `invalid_context` 创建时。 |

目录是在运行时阅读的, 不是创建时, 所以 `context_too_large` 第一个 `run()` 而不是当天体被建造时。

## 为什么默认值低于窗口 {#why-default}

> **窗口是适合的,不是明智的**
>
> 运送80万个物证的转弯速度缓慢,费用昂贵,因为整个历史每次重现。 200 000是一个工作上限,可以快速地前进;提高这个上限是您为具体工作所做的决定,而不是您继承的违约。

## 读回读回 {#reading}

```javascript
agent.context;
// { tokens: 31_204, limit: 200_000, window: 1_048_576, cachedTokens: 22_400,
//   cleared: 3, parts: { system: 2_100, tools: 3_900, memory: 180, messages: 25_024 } }
```

| 字段 | 是 |
| --- | --- |
| `tokens` | 由提供者测量的最后一个转弯的大小 。 |
| `limit` | 有效限度——你的 `contextTokens`,或违约。 |
| `window` | 模型的窗口是自己的,或者 `null` 如果目录无法读取 。 |
| `cachedTokens` | 供应商上次从缓存中 提供多少服务 |
| `cleared` | 迄今为止,已清空了多少工具结果。 |
| `parts` | 解析:系统、工具、内存、信息。 |

## 如果目录无法读取 {#unreachable}

运行以您要求的上限或默认值继续 。 `window` 居留 `null` 也没有任何人因为太大而被拒绝,

## 当您调出后退模式时要注意 {#fallback}

限制从主模式中解析。 小窗口的回退可以拒绝一个被接受的主要历史, 从而选择大小相当的回退, 或者保留 `contextTokens` 以他们所持的价位计。

- [清除工具结果](/zh/sdk/agent/context/clearing): 最先让位的东西
- [回退与重试](/zh/sdk/agent/fallback-and-retry): 为什么后退的窗口很重要

```python
from iagenify import IaGenifyError

# Default on a model with a 1 048 576-token window → limit 200 000
api.agents.create(runtime="local", machine=pc, model="gemini-3.5-flash")

# Asking for more than the model has: refused on the first run, once the window is read
agent = api.agents.create(runtime="local", machine=pc, model=model, context_tokens=2_000_000)
try:
    agent.run(message="…")
except IaGenifyError as error:
    print(error.code)   # "context_too_large"
```

```python
agent.context
# {"tokens": 31_204, "limit": 200_000, "window": 1_048_576, "cachedTokens": 0,
#  "cleared": 3, "parts": {"system": 2_100, "tools": 3_900, "memory": 0, "messages": 25_204}}
```
