Kontext-Anatomie

Intermediate

Aufschlüsselung der Struktur von Kontextfenstern und wie Agenten Informationen verwalten.

Zuletzt aktualisiert: 24. Jan. 2026

Agentenkontext verstehen

Der Agentenkontext umfasst den System-Prompt, die Gesprächshistorie, Tool-Definitionen und abgerufene Informationen. Eine effiziente Verwaltung dieses Kontexts ist entscheidend für die Agentenleistung.

Think of context as the agent's working memory—everything it needs to understand the task and respond appropriately.

📊

Explore Context Layers

Click each layer to see example content

Context Window

7,750 / 8,192 tokens

850
1200
2500
3200
You are Claude, an AI assistant made by Anthropic.
You have access to tools for file operations.
Always be helpful, harmless, and honest.
Never execute dangerous commands.

Priority Order

When context exceeds the window limit, content is typically trimmed from the middle or oldest history first. System prompts and tool definitions have highest priority and are rarely truncated. Recent conversation turns are preserved to maintain coherence.

What Actually Gets Sent to the Model

messages = [
  // 1. System prompt (highest priority)
  { "role": "system", "content": "You are a helpful coding assistant..." },

  // 2. Conversation history
  { "role": "user", "content": "Help me fix this bug" },
  { "role": "assistant", "content": "I'll read the file first" },

  // 3. Tool calls and results
  { "role": "assistant", "tool_calls": [{"name": "read_file"}] },
  { "role": "tool", "content": "def buggy_function():..." },

  // 4. Latest user message
  { "role": "user", "content": "Thanks, what was the issue?" },
]

tools = [
  { "name": "read_file", "description": "Read file contents", ... },
  { "name": "write_file", "description": "Write to a file", ... },
]

Kontext-Komponenten

📋

System-Prompt

Definiert die Rolle, Fähigkeiten und Verhaltensrichtlinien des Agenten.

🔧

Tool-Definitionen

Beschreibungen der verfügbaren Tools und ihrer Verwendung.

💬

Gesprächshistorie

Vorherige Nachrichten, Tool-Aufrufe und deren Ergebnisse.

📚

Abgerufene Informationen

Externes Wissen, das während des Gesprächs abgerufen wurde.

Context Management Strategies

Sliding Window

Keep the most recent N messages. Simple but may lose important early context.

messages = messages[-MAX_MESSAGES:]

Summarization

Periodically compress older messages into summaries. Preserves key information while reducing tokens.

summary = llm("Summarize this conversation: " + old_messages)
context = [system, summary] + recent_messages

Priority-based Truncation

Assign priority scores to messages. System prompts and recent turns get highest priority.

priority: system > tools > recent_user > recent_assistant > old_history

Common Pitfalls

Context Overflow

Exceeding the context window causes truncation. The model loses access to earlier information, potentially forgetting instructions or important context.

Tool Definition Bloat

Too many tools or overly verbose descriptions eat into context space. Keep tool definitions concise and only include tools relevant to the task.

Lost in the Middle

Models pay less attention to information in the middle of long contexts. Place critical information at the start or end.

Stale Retrieved Data

RAG results from earlier in conversation may become outdated as discussion evolves. Refresh retrieved data when the topic shifts.

Wichtige Erkenntnisse

  • 1Kontextmanagement ist der Schlüssel zur Agenten-Zuverlässigkeit
  • 2Priorisiere aktülle und relevante Informationen
  • 3Tool-Definitionen sollten klar und eindeutig sein
  • 4Zusammenfassung hilft, Kontext über lange Sitzungen zu erhalten