Skip to content

Context and model loop

This chapter follows a model turn from input collection to provider request and response handling. It covers what becomes model-visible context, how the request is shaped for a provider, how token pressure is managed, and how failures, retries, quota, and usage are surfaced.

Read this chapter when the question is: what did the model see, why did it see that, and how did the runtime handle the model call?

Source-anchor policy

This page is a chapter guide. Linked implementation pages carry concrete app.js anchors.

Semantic aliasMinified anchorScope
Context/model loop chapterN/A — navigation pageGroups prompt/context assembly, attachments, memory, compaction, provider routing, retries, quota, and usage.
Context/model implementation pagesSee linked source-anchor tablesConcrete bundle anchors live in the destination pages.

Model-turn map

flowchart TD
Input[User input / files / IDE / config] --> Prompt[Prompt and instruction sources]
Prompt --> Attachments[Attachments and file ingestion]
Prompt --> Memory[Memory and context board]
Attachments --> Request[Provider request]
Memory --> Request
Request --> Compaction[Truncation / compaction / checkpoints]
Compaction --> Provider[Provider adapter]
Provider --> Stream[Streaming response]
Provider --> Retry[Retry / rate-limit / fallback]
Stream --> Events[Session events and usage]
Retry --> Request
click Prompt "./prompt-sources/" "Open prompt sources"
click Attachments "./attachments-and-file-ingestion/" "Open attachments"
click Memory "./memory-and-context-board/" "Open memory and context board"
click Compaction "./conversation-compaction/" "Open conversation compaction"
click Provider "./model-api-routing/" "Open model API routing"
click Retry "./resilience-rate-limits-concurrency/" "Open resilience and retries"

Primary reading order

OrderPageContext/model question answered
1Prompt sources in Copilot CLIWhich static/runtime prompts, custom instructions, hooks, MCP prompts, and provider mappings feed the request?
2Prompt catalogWhat prompt families and templates are embedded in the bundle?
3Attachment and file-ingestion pipelineHow are images, documents, tagged files, MIME metadata, and size limits mapped into request payloads?
4Memory and dynamic context boardHow do agentic memory, local memory, context board, rem-agent, sidekicks, and consolidation affect context?
5Conversation compaction and memory compressionHow do /compact, automatic compaction, request trimming, summaries, and checkpoints manage context pressure?
6Model API routing and provider wire formatsHow are requests routed to Chat Completions, Responses, WebSocket Responses, or Anthropic Messages APIs?
7Rate limits, concurrency, retries, and error recoveryHow do retry policy, queue pauses, fallback, cancellation, rate-limit recovery, and request-size handling work?

Supporting topics

TopicPageWhy it matters
Provider identity and authModels, providers, and authentication workflowsExplains GitHub auth, BYOK/custom providers, model catalog access, and offline/custom paths.
Usage accountingUsage, quota, and billing metricsTracks /usage, assistant.usage, quota snapshots, premium metrics, and token details.
Rewind boundariesCheckpoints, undo, rewind, and forkShows how context history can be truncated, replayed, forked, or restored.
Agent-specific promptsCustom agents and skills packagingExplains AGENTS.md, SKILL.md, custom-agent prompts, allowed-tools, and skill invocation.

Handoffs

Created and maintained by Yingting Huang.