KB-currency refresh (medium priority, 2026-06-19) via /architect:kb-update. 74 medium-prioritets filer re-verifisert mot Microsoft Learn (MCP) — delegert til 15 parallelle Opus-subagenter (3 bølger) gruppert etter delt kilde, med disjunkte fil-sett. Verifisert i hovedkontekst (scope-sjekk + diff-review av de faktatunge gruppene + tester). Hovedendringer (faktuelle korreksjoner + currency): - Azure AI Search semantic ranker: TILGJENGELIG PÅ ALLE TIERS (også Free/Basic m/ gratis månedlig kvote) — gammel KB sa feilaktig "kun S1+". Korrigert i tier-tabell, anti-patterns og beslutningstabell (azure-ai-search-setup). - APIM score-threshold = DISTANSE (lavere = strengere): tuning-tabellen i rag-caching-optimization hadde retningen baklengs — invertert til korrekt. - Agentic retrieval GA/preview-nyanse presisert (hovedkontekst-korreksjon mot agentic-retrieval-how-to-migrate): GA via REST 2026-04-01 returnerer EKSTRAKTIV grounding (references + activity), IKKE syntetiserte svar. Answer synthesis, ikke-minimal reasoning effort (LLM query planning) og multi-turn messages forblir preview (2026-05-01-preview). Subagent hadde overforenklet til "hele kjernepipelinen GA"; rettet i agentic-rag-patterns + citation-tracking. - Copilot Studio modell-tabeller (platforms/copilot-studio): fjernet Claude Opus 4.5 + GPT-5.2 (borte fra kilde), lagt til Claude Sonnet 4.6/Opus 4.6 (GA), Opus 4.7 + Mistral Medium 3.5 (experimental); GPT-5 Reasoning/Auto = preview; A2A GA (apr 2026). - Computer Use (CUA): Copilot Studio GA 2026-05-07; 4 modeller m/ tier/status (OpenAI CUA + Sonnet 4.5 GA, Sonnet 4.6 + Opus 4.6 experimental); 5 credits/ steg standard, 15 premium; US-only region-krav FJERNET i GA-dok; Cloud PC pool + Hosted browser + bring-your-own-machine. - Azure AI Search REST API-versjoner bumpet: 2025-09-01 -> 2026-04-01 (stabil), 2025-11-01-preview -> 2026-05-01-preview (hybrid-search, rag-security-rbac, chunking). - Power Automate-integrasjon: trigger "Run a flow from Copilot" -> "When an agent calls the flow"; App Service innebygd MCP (preview) lagt til. - M365 Copilot-manifest v1.26 -> v1.28 (GA, mai) / v1.29 dokumentert (juni); "Tenant graph grounding" -> "Work IQ". - Speech fast transcription 2t/300MB -> 5t/500MB; multilingual 14 -> 15 locales (+ pt-BR). Content Understanding reasoning preview -> GA (v1.0, 2025-11-01). - Security Copilot E5 -> E5+E7. Død Databricks-URL ci-cd/best-practices -> ci-cd/flows. Prompt Flow retirement (2027-04-20 -> MAF) notert der den presenteres som go-forward. Gateway-topologi-tabell-feil rettet. - Alle 74 Last updated -> 2026-06-19. Discovery ikke kjørt (historisk kun Databricks-støy) -> 389-telling uendret, ingen resync. validate 239 PASS, kb-integrity 115/115 (262 orphan-warnings uendret), gitleaks clean. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01REiKFhP4w6xGXXqWKpPCJJ
573 lines
22 KiB
Markdown
573 lines
22 KiB
Markdown
# Context Window Optimization for Copilot
|
||
|
||
**Last updated:** 2026-06-19
|
||
**Status:** GA
|
||
**Category:** Copilot Extensibility & Integration
|
||
|
||
---
|
||
|
||
## Introduksjon
|
||
|
||
Context window optimization er kritisk for å maksimere kvalitet, ytelse og kostnadseffektivitet i Copilot-løsninger. Kontekstvinduet definerer hvor mye informasjon (målt i tokens) en språkmodell kan prosessere i én forespørsel — både input (prompt, grounding data, samtalehistorikk) og output (generert respons).
|
||
|
||
Dårlig context window management fører til:
|
||
- **Trunkert kontekst** — viktig informasjon kuttes ut
|
||
- **Kostnadssprekk** — unødvendig høyt tokenforbruk
|
||
- **Degradert kvalitet** — modellen får ikke nok kontekst til å svare presist
|
||
- **Gateway timeouts** — langvarige oppgaver overskrider tidsgrenser
|
||
|
||
Microsoft tilbyr ulike mekanismer for context window management på tvers av Azure OpenAI, Copilot Studio, Microsoft 365 Copilot og Microsoft Fabric.
|
||
|
||
**Verified** (MCP: microsoft-learn, 2026-02)
|
||
|
||
---
|
||
|
||
## Kjernekomponenter / Nøkkelegenskaper
|
||
|
||
### Token-anatomi
|
||
|
||
Tokens er ikke ord, men subword-enheter. Eksempel (Azure OpenAI tokenization):
|
||
- `"report"` = 1 token
|
||
- `"."` = 1 token
|
||
- `"optimization"` = 2-3 tokens (modellavhengig)
|
||
|
||
**Input tokens** består av:
|
||
1. **User prompt** — brukerens spørsmål/instruksjon
|
||
2. **Grounding data** — RAG-dokumenter, schema, metadata
|
||
3. **System message / role information** — persona og instruksjoner
|
||
4. **Conversation history** — tidligere meldinger i tråden
|
||
|
||
**Output tokens** = generert respons fra LLM.
|
||
|
||
**Totalt kontekstvindu** = `max_prompt_tokens + max_completion_tokens`
|
||
|
||
### Automatisk trunkeringsstrategi (Azure OpenAI Assistants API)
|
||
|
||
Assistants API håndterer automatisk trunkering når kontekstvinduet overskrides:
|
||
|
||
| Strategi | Beskrivelse | Bruksområde |
|
||
|----------|-------------|-------------|
|
||
| `auto` | OpenAI's default — intelligently truncates based on relevance | Generell bruk |
|
||
| `last_messages` | Inkluderer N siste meldinger, kutter eldre | Chat-assistenter med lang historikk |
|
||
|
||
**Kodeeksempel (Python):**
|
||
```python
|
||
# Assistants API — Run creation med token limits
|
||
run = client.beta.threads.runs.create(
|
||
thread_id="thread_abc123",
|
||
assistant_id="asst_abc123",
|
||
max_prompt_tokens=500,
|
||
max_completion_tokens=1000,
|
||
truncation_strategy={"type": "last_messages", "last_messages": 10}
|
||
)
|
||
```
|
||
|
||
**Beste praksis:**
|
||
- For File Search: `max_prompt_tokens >= 20 000` (anbefalt 50 000+)
|
||
- For lange samtaler: Fjern `max_prompt_tokens`-limit helt
|
||
- Hvis Run når `max_completion_tokens`: Status = `incomplete`, sjekk `incomplete_details`
|
||
|
||
**Verified** (MCP: Azure OpenAI Assistants API documentation)
|
||
|
||
### Copilot Studio: Samtale-tokens og limieter
|
||
|
||
**Conversation context limits:**
|
||
- **ACS channel (Omnichannel):** Maks 28 KB total melding (inkl. variabler)
|
||
- **Transcript limit:** 512 tegn per bot-respons i nedlastede transkripsjonar
|
||
- **Inaktivitet:** Samtale lagres etter 30 min inaktivitet, ny tråd ved gjenopptaking
|
||
- **Telefoni:** 3 min timeout etter "End Conversation"-event
|
||
|
||
**Vanlig feil:** Variable passing ved handoff til Dynamics 365 Customer Service feiler med `MessageSizeExceeded` hvis totale variablestørrelse > 28 KB. **Løsning:** Clear unødvendige variabler før transfer.
|
||
|
||
**Verified** (MCP: Copilot Studio quotas documentation)
|
||
|
||
### Microsoft 365 Copilot Chat API: Context control
|
||
|
||
**Known limitations:**
|
||
- Ingen støtte for action/content generation (filopprettelse, e-post, møtebooking)
|
||
- Kun tekstrespons
|
||
- Ingen code interpreter / graphic art tools
|
||
- **Long-running tasks prone to gateway timeouts** — ingen context window persistence for langvarige operasjoner
|
||
- Web search grounding må toggles av per melding (single-turn action)
|
||
|
||
**Context window management:**
|
||
- Bruker både enterprise search grounding og web search grounding by default
|
||
- Ingen eksplisitt `max_tokens`-kontroll eksponert i Chat API
|
||
- Context begrenset av [Semantic Index for Copilot limitations](https://learn.microsoft.com/microsoftsearch/semantic-index-for-copilot)
|
||
|
||
**Verified** (MCP: Microsoft 365 Copilot Chat API documentation)
|
||
|
||
### Azure OpenAI On Your Data: Runtime parameters
|
||
|
||
For RAG-scenarios med Azure OpenAI On Your Data (Azure AI Search-integrasjon):
|
||
|
||
| Parameter | Type | Standardverdi | Funksjon |
|
||
|-----------|------|---------------|----------|
|
||
| `topNDocuments` | int | 5 | Antall dokumentchunks sendt til LLM (3, 5, 10, 20) |
|
||
| `chunk_size` | int | 1024 | Chunk-størrelse ved indeksering (tokens) |
|
||
| `strictness` | int | 3 | Filtrerer irrelevante chunks (1-5) |
|
||
| `inScope` | bool | true | Begrens svar til kun data (ikke modellens egen kunnskap) |
|
||
| `temperature` | float | 0.7 | Randomness (anbefalt 0 for konsistens) |
|
||
|
||
**Token flow ved RAG:**
|
||
1. **Intent generation** — genererer search intents fra spørsmål + history
|
||
2. **Retrieval** — henter relevante chunks
|
||
3. **Filtration** — `strictness` kutter irrelevante chunks
|
||
4. **Reranking** — sorterer beste chunks på tvers av intents
|
||
5. **Parameter inclusion** — `topNDocuments` chunks inkluderes i prompt
|
||
6. **Response generation** — LLM genererer svar + citations
|
||
|
||
**Optimalisering:**
|
||
- Øk `topNDocuments` hvis svar mangler viktig kontekst (men ikke for høyt — kan distrahere modellen)
|
||
- Reduser `strictness` hvis korrekte chunks filtreres ut
|
||
- Bruk `chunk_size=1536` for dokumenter med store tabeller/detaljerte seksjoner
|
||
- Sett `temperature=0` for konsistente svar
|
||
|
||
**Verified** (MCP: Azure OpenAI On Your Data best practices documentation)
|
||
|
||
---
|
||
|
||
## Arkitekturmønstre
|
||
|
||
### 1. Adaptive Token Budgeting (Assistants API)
|
||
|
||
**Pattern:** Dynamisk allokering av token-budsjett basert på Run-livssyklus.
|
||
|
||
```python
|
||
from openai import OpenAI
|
||
from azure.identity import DefaultAzureCredential, get_bearer_token_provider
|
||
|
||
token_provider = get_bearer_token_provider(
|
||
DefaultAzureCredential(),
|
||
"https://cognitiveservices.azure.com/.default"
|
||
)
|
||
|
||
client = OpenAI(
|
||
base_url="https://YOUR-RESOURCE.openai.azure.com/openai/v1/",
|
||
api_key=token_provider
|
||
)
|
||
|
||
# First completion: conservative budget
|
||
run = client.beta.threads.runs.create(
|
||
thread_id=thread_id,
|
||
assistant_id=assistant_id,
|
||
max_prompt_tokens=500,
|
||
max_completion_tokens=1000
|
||
)
|
||
|
||
# Monitor remaining budget
|
||
status = client.beta.threads.runs.retrieve(thread_id=thread_id, run_id=run.id)
|
||
if status.status == "incomplete":
|
||
# Increase budget for retry
|
||
retry_run = client.beta.threads.runs.create(
|
||
thread_id=thread_id,
|
||
assistant_id=assistant_id,
|
||
max_prompt_tokens=1000, # doubled
|
||
max_completion_tokens=2000
|
||
)
|
||
```
|
||
|
||
**Når bruke:**
|
||
- Multi-turn samtaler hvor første svar ofte er tilstrekkelig, men noen cases krever mer dybde
|
||
- File Search-scenarios med varierende dokumentkompleksitet
|
||
- Cost-sensitive deployments
|
||
|
||
### 2. Conversation Pruning (Copilot Studio / Chat Completions)
|
||
|
||
**Pattern:** Eksplisitt kutt av eldre samtalehistorikk før kontekstvinduet fylles.
|
||
|
||
```typescript
|
||
// Pseudo-code for Copilot Studio variable management
|
||
function pruneConversationContext(variables: Record<string, any>): Record<string, any> {
|
||
const MAX_CONTEXT_SIZE_KB = 24; // Buffer under 28 KB ACS limit
|
||
|
||
let currentSize = JSON.stringify(variables).length / 1024;
|
||
|
||
if (currentSize > MAX_CONTEXT_SIZE_KB) {
|
||
// Strategy 1: Remove oldest messages
|
||
delete variables.history_message_1;
|
||
delete variables.history_message_2;
|
||
|
||
// Strategy 2: Summarize old context
|
||
variables.conversation_summary = summarizeHistory(variables);
|
||
|
||
// Strategy 3: Clear non-essential variables
|
||
Object.keys(variables).forEach(key => {
|
||
if (key.startsWith("temp_") || key.startsWith("debug_")) {
|
||
delete variables[key];
|
||
}
|
||
});
|
||
}
|
||
|
||
return variables;
|
||
}
|
||
```
|
||
|
||
**Når bruke:**
|
||
- Handoff til Dynamics 365 Customer Service (ACS channel limit)
|
||
- Lange customer service-samtaler
|
||
- Voice-based copilots (timeout-sensitiv)
|
||
|
||
### 3. Schema Reduction for Grounding Data (Fabric Copilot)
|
||
|
||
**Pattern:** Reduser grounding data (semantic model schema, lakehouse metadata) ved hjelp av embeddings.
|
||
|
||
Fabric Copilot bruker automatisk:
|
||
- **Embedding-basert kolonneutvelgelse** — sender ikke hele schema, kun relevante kolonner
|
||
- **Prompt augmentation** — omskriver prompt for spesifisitet
|
||
- **Hidden fields/private tables** — ekskluder fra Copilot-kontekst
|
||
|
||
**Manuell optimalisering:**
|
||
1. **Hide irrelevante felt** i semantic model (Power BI)
|
||
2. **Mark tables as private** hvis de ikke skal være tilgjengelige
|
||
3. **Hide report pages/visuals** bak bookmarks
|
||
|
||
**Token impact:**
|
||
- Full schema: 5 000–15 000 tokens (avhengig av modellstørrelse)
|
||
- Reduced schema: 500–2 000 tokens
|
||
- **Savings: 70-90% reduction i grounding data tokens**
|
||
|
||
**Verified** (MCP: Fabric Copilot consumption documentation)
|
||
|
||
### 4. Predicted Outputs for Known Context (Azure OpenAI)
|
||
|
||
**Pattern:** Send kjent tekst (f.eks. eksisterende kode) som `prediction` for å akselerere respons.
|
||
|
||
```python
|
||
code = """
|
||
for number in range(1, 101):
|
||
if number % 3 == 0 and number % 5 == 0:
|
||
print("FizzBuzz")
|
||
elif number % 3 == 0:
|
||
print("Fizz")
|
||
elif number % 5 == 0:
|
||
print("Buzz")
|
||
else:
|
||
print(number)
|
||
"""
|
||
|
||
completion = client.chat.completions.create(
|
||
model="gpt-4o-mini",
|
||
messages=[
|
||
{"role": "user", "content": "Replace 'FizzBuzz' with 'MSFTBuzz'"},
|
||
{"role": "user", "content": code}
|
||
],
|
||
prediction={
|
||
"type": "content",
|
||
"content": code # Known text for latency optimization
|
||
}
|
||
)
|
||
```
|
||
|
||
**Når bruke:**
|
||
- Code refactoring (modellen ser mye av eksisterende kode)
|
||
- Document editing (kjent baseline-tekst)
|
||
- Iterative improvements
|
||
|
||
**Verified** (MCP: Azure OpenAI predicted outputs documentation)
|
||
|
||
---
|
||
|
||
## Beslutningsveiledning
|
||
|
||
### Når velge hvilken optimaliserings-strategi?
|
||
|
||
| Scenario | Anbefalt tilnærming | Verktøy |
|
||
|----------|---------------------|---------|
|
||
| **Multi-turn chat med lang historikk** | Truncation strategy (`last_messages`) | Assistants API |
|
||
| **RAG med variable dokumentmengder** | Dynamisk `topNDocuments` + strictness tuning | Azure OpenAI On Your Data |
|
||
| **Copilot Studio handoff** | Conversation pruning før transfer | Custom Logic (Power Automate) |
|
||
| **Fabric Copilot (Power BI)** | Schema reduction (hide fields/tables) | Semantic model config |
|
||
| **Cost-sensitive produksjon** | `max_prompt_tokens` + `max_completion_tokens` limits | Assistants API / Chat Completions |
|
||
| **Langvarige analyser** | Unngå Chat API, bruk Assistants/Responses API | Azure OpenAI Assistants |
|
||
| **Copilot handoff med context** | Continuation tokens (maks 28 KB) | M365 Copilot + Teams Bot Framework |
|
||
|
||
### Debugging context window-problemer
|
||
|
||
**Symptom: "Information not present in retrieved documents" (men du vet det finnes)**
|
||
|
||
1. **Sjekk retrieval** — er riktige chunks i citations? (REST API: `tool` message)
|
||
2. **Sjekk filtration** — reduser `strictness` (Azure OpenAI On Your Data)
|
||
3. **Sjekk reranking** — øk `topNDocuments`
|
||
4. **Sjekk intent generation** — inspiser `intents` field (REST API)
|
||
5. **Sjekk chunk size** — øk til 1536 for tabeller/semistrukturert data
|
||
|
||
**Symptom: Incomplete responses / gateway timeout**
|
||
|
||
1. **Sjekk token limits** — fjern `max_prompt_tokens` for File Search
|
||
2. **Sjekk Run status** — `incomplete_details` field
|
||
3. **Sjekk conversation size** — prune historikk (Copilot Studio < 28 KB)
|
||
4. **Unngå long-running tasks** i Chat API — bruk Assistants API
|
||
|
||
**Symptom: Inconsistent responses**
|
||
|
||
1. **Sett `temperature=0`** for determinisme
|
||
2. **Sjekk conversation history** — samme spørsmål, forskjellig history = forskjellig respons
|
||
3. **Oppgrader modell** — GPT-4 > GPT-3.5 for intent generation
|
||
|
||
---
|
||
|
||
## Integrasjon med Microsoft-stakken
|
||
|
||
### Azure AI Foundry + Assistants API
|
||
|
||
**Token management:**
|
||
- Bruk `max_prompt_tokens` og `max_completion_tokens` for budsjett-kontroll
|
||
- File Search anbefaler **minimum 20 000 prompt tokens** (ideelt 50 000+)
|
||
- Truncation strategy: `auto` (default) eller `last_messages` (eksplisitt)
|
||
|
||
**Monitoring:**
|
||
- Enable **Diagnostic Settings** for long-term token usage tracking
|
||
- Log `incomplete_details` når Runs feiler
|
||
- Track token usage per Run (input + output tokens i response)
|
||
|
||
### Copilot Studio + Dynamics 365 Omnichannel
|
||
|
||
**Variable size management:**
|
||
- **Pre-transfer pruning** — clear unødvendige variabler før handoff
|
||
- **Monitor ACS channel limit** — 28 KB max (inkl. serialiserte variabler)
|
||
- **Avoid authentication variables in voice** — ikke støttet ved voice handoff
|
||
|
||
**Best practice:**
|
||
```javascript
|
||
// Pre-handoff cleanup logic
|
||
const essentialVariables = {
|
||
customerName: context.customerName,
|
||
caseId: context.caseId,
|
||
priority: context.priority
|
||
// Only keep what Dynamics 365 agent needs
|
||
};
|
||
|
||
// Transfer with minimal context
|
||
transferToAgent(essentialVariables);
|
||
```
|
||
|
||
### Microsoft 365 Copilot Extensibility
|
||
|
||
**Message Extension Agents:**
|
||
- **Copilot handoff** — bruk continuation tokens (maks 28 KB context)
|
||
- **Deep link format:** `https://teams.microsoft.com/l/chat/.../continuation=<token>`
|
||
- **Token lifecycle management** — sett expiry, håndter replay-scenario
|
||
|
||
**Custom Engine Agents:**
|
||
- **No long-running task support** i Chat API
|
||
- **Context maintenance:** kun under aktiv sesjon (cleared ved app close)
|
||
- **Token limits:** Underlagt Semantic Index for Copilot limitations
|
||
|
||
### Power BI + Fabric Copilot
|
||
|
||
**Grounding data optimization:**
|
||
- **Schema reduction:** Hide/private fields ekskluderes automatisk
|
||
- **Report metadata:** Hide pages/visuals bak bookmarks
|
||
- **Token cost:** Report creation = høy consumption (verbose output + schema)
|
||
|
||
**Consumption rate:**
|
||
- Basert på input + output tokens
|
||
- **Smoothing:** Background operations fordelt over 24 timer
|
||
- **No direct token control** — optimalisering via item-konfigurasjon
|
||
|
||
---
|
||
|
||
## Offentlig sektor (Norge)
|
||
|
||
### GDPR og token logging
|
||
|
||
**Problemstilling:** Tokens kan inneholde personopplysninger — hvordan logger uten å bryte personvern?
|
||
|
||
**Løsning:**
|
||
1. **Aggregate metrics only** — logg total token count, ikke token content
|
||
2. **Pseudonymization** — hash user IDs før logging
|
||
3. **Retention policies** — automatisk sletting etter 90 dager (Datatilsynets anbefaling)
|
||
4. **Diagnostic Settings (Azure)** — enable for compliance, men konfigurer data residency (Norway East/West)
|
||
|
||
### Kostnadsfordeling i statlige virksomheter
|
||
|
||
**Utfordring:** Hvordan allokere token-kostnader til riktig kode/prosjekt?
|
||
|
||
**Løsning:**
|
||
1. **Tagging strategy** — `costCenter`, `projectId` i Azure Resource tags
|
||
2. **Per-assistant tracking** — separat Assistants API-instans per team/prosjekt
|
||
3. **Monthly token budgets** — `max_prompt_tokens` for cost control
|
||
4. **Chargeback model** — FinOps-dashboards (Azure Cost Management + Power BI)
|
||
|
||
### Språklige hensyn (norsk/samisk)
|
||
|
||
**Token efficiency:**
|
||
- **Norsk bokmål/nynorsk:** ~1.3x flere tokens enn engelsk (subword tokenization)
|
||
- **Samisk:** ~1.5-2x flere tokens (mindre representert i training data)
|
||
- **Implikasjon:** Context window fylles raskere — vurder større modeller (GPT-4 32K/128K)
|
||
|
||
**Anbefaling:**
|
||
- For norskspråklige chat-assistenter: Assistants API med `truncation_strategy="last_messages"` + norsk prompt engineering
|
||
- For samiskspråklige: Vurder prompt compression techniques (summarization av eldre meldinger)
|
||
|
||
---
|
||
|
||
## Kostnad og lisensiering
|
||
|
||
### Azure OpenAI — Token pricing (NOK, eks. mva.)
|
||
|
||
**Assistants API:**
|
||
- **No additional cost** for Assistants API itself
|
||
- **Code Interpreter:** Charged per session
|
||
- **File Search:** Charged per GB indexed + per query
|
||
|
||
**Chat Completions (GPT-4o, Norway East region, estimert 2026):**
|
||
- Input tokens: ~0.035 NOK / 1K tokens
|
||
- Output tokens: ~0.11 NOK / 1K tokens
|
||
- **Cached input tokens:** ~0.0035 NOK / 1K tokens (10x discount for repeated context)
|
||
|
||
**Eksempel — RAG-scenario (10 000 spørsmål/måned):**
|
||
- Avg. input: 2000 tokens (prompt + 5 chunks @ 300 tokens each)
|
||
- Avg. output: 500 tokens
|
||
- **Monthly cost:** (10K × 2K × 0.035 / 1K) + (10K × 0.5K × 0.11 / 1K) = **1 250 NOK**
|
||
|
||
**Optimalisering:**
|
||
- **Bruk caching** for repeterende grounding data (10x reduksjon)
|
||
- **Reduce topNDocuments** fra 10 til 5 (50% input token saving)
|
||
- **Prompt compression** — fjern verbose system messages
|
||
|
||
### Copilot Studio — Capacity Units (CU)
|
||
|
||
**Token → CU konvertering:**
|
||
- **Smoothing:** Background operations (Copilot in Fabric) fordelt over 24 timer
|
||
- **No direct visibility** på tokenization — minimal bruker-kontroll
|
||
- **Optimization:** Begrens knowledge sources, bruk hidden fields
|
||
|
||
**Licensing:**
|
||
- Copilot Studio: Inkludert i Power Apps/Power Automate Premium
|
||
- **Per-user licensing** — ikke direkte token-basert billing
|
||
|
||
### Microsoft 365 Copilot
|
||
|
||
**Token cost:**
|
||
- **No extra cost** for Chat API med M365 Copilot-lisens
|
||
- **Lisens-krav:** Microsoft 365 Copilot add-on (per bruker)
|
||
- **Ingen token quotas** eksponert til brukere
|
||
|
||
**Ikke støttet uten lisens** (per 2026-02).
|
||
|
||
---
|
||
|
||
## For arkitekten (Cosmo)
|
||
|
||
### Når foreslå context window optimization?
|
||
|
||
**Trigger scenarios:**
|
||
1. **Kunde rapporterer "missing information" i svar** → RAG retrieval/filtration issue
|
||
2. **Intermitterende gateway timeouts** → long-running tasks i Chat API
|
||
3. **Kostnad eksploderer** → ingen token budgets satt
|
||
4. **Copilot Studio handoff feiler** → > 28 KB variable size
|
||
5. **Inconsistent svar** → conversation history ikke pruned, high temperature
|
||
|
||
### Diagnostikk-sjekkliste
|
||
|
||
**For Azure OpenAI On Your Data:**
|
||
- [ ] Sjekk `topNDocuments` (default 5 — øk til 10 hvis info mangler)
|
||
- [ ] Sjekk `strictness` (default 3 — reduser til 2 hvis for aggressiv)
|
||
- [ ] Sjekk `chunk_size` (default 1024 — øk til 1536 for tabeller)
|
||
- [ ] Inspiser `intents` i API response (feil modell hvis tomme?)
|
||
- [ ] Sjekk `temperature` (sett til 0 for konsistens)
|
||
|
||
**For Assistants API:**
|
||
- [ ] Sjekk `max_prompt_tokens` (fjern limit for File Search)
|
||
- [ ] Sjekk Run status (`incomplete` → øk token budget)
|
||
- [ ] Sjekk `truncation_strategy` (bruk `last_messages` for lange chats)
|
||
|
||
**For Copilot Studio:**
|
||
- [ ] Sjekk variable size før handoff (< 24 KB buffer)
|
||
- [ ] Sjekk conversation timeout (30 min inaktivitet → ny tråd)
|
||
- [ ] Sjekk voice handoff region (US/CA/EU/UK/Asia/Australia kun)
|
||
|
||
### Arkitektur-tradeoffs
|
||
|
||
| Tilnærming | Fordel | Ulempe | Anbefalt for |
|
||
|------------|--------|--------|--------------|
|
||
| **Aggressive truncation** | Lav cost, rask respons | Kan kutte viktig kontekst | Cost-sensitive, short-form chat |
|
||
| **No token limits** | Maksimal kvalitet | Høy cost, potensielt treg | Enterprise RAG, komplekse analyser |
|
||
| **Conversation pruning** | Balansert cost/kvalitet | Krever custom logic | Multi-turn customer service |
|
||
| **Schema reduction** | Lav grounding token cost | Kan ekskludere relevante felt | Power BI Copilot, Fabric |
|
||
|
||
### Anbefalinger for norsk offentlig sektor
|
||
|
||
**Standardoppsett for statlige virksomheter:**
|
||
1. **Assistants API med token budgets** — transparens for kostnadsfordeling
|
||
2. **Diagnostic Settings enabled** — compliance logging (Norway East data residency)
|
||
3. **Temperature=0** — konsistens viktigere enn kreativitet for forvaltning
|
||
4. **Truncation strategy: last_messages (10-20)** — balanse mellom kontekst og cost
|
||
5. **Chunk size: 1536** — norske dokumenter ofte tabellrike (rundskriv, forskrifter)
|
||
|
||
**Unngå:**
|
||
- Chat API for long-running tasks (bruk Assistants API)
|
||
- Voice handoff utenfor støttede regioner (kun US/CA/EU/UK/Asia/AU)
|
||
- Hardkodede token limits uten monitoring (Runs feiler uten synlig feilmelding)
|
||
|
||
### Referansearkitektur: RAG med context optimization
|
||
|
||
```
|
||
User Query
|
||
↓
|
||
[Intent Generation] ← GPT-4 (ikke GPT-3.5-turbo-1106)
|
||
↓
|
||
[Azure AI Search] ← query_type="vectorSemanticHybrid"
|
||
↓
|
||
[Filtration] ← strictness=2 (lavere enn default for recall)
|
||
↓
|
||
[Reranking] ← Combine intents, top relevance
|
||
↓
|
||
[Parameter Inclusion] ← topNDocuments=10, chunk_size=1536
|
||
↓
|
||
[LLM Generation] ← GPT-4o, temperature=0, max_tokens=1500
|
||
↓
|
||
Response + Citations
|
||
```
|
||
|
||
**Token breakdown (typisk):**
|
||
- Intent generation: 200 tokens
|
||
- Grounding data (10 chunks @ 400 tokens): 4000 tokens
|
||
- System message: 300 tokens
|
||
- Conversation history (5 turns): 1000 tokens
|
||
- **Total input:** ~5500 tokens
|
||
- **Output:** 500-1500 tokens
|
||
- **Total per query:** ~7000 tokens (~0.30 NOK ved GPT-4o Norway East pricing)
|
||
|
||
---
|
||
|
||
## Kilder og verifisering
|
||
|
||
**MCP-verified sources (microsoft-learn):**
|
||
|
||
1. **Azure OpenAI Assistants API — Context Window Management**
|
||
- https://learn.microsoft.com/en-us/azure/foundry-classic/openai/concepts/assistants#context-window-management
|
||
- Verified: max_prompt_tokens, max_completion_tokens, truncation_strategy
|
||
|
||
2. **Troubleshooting and best practices for Azure OpenAI On Your Data**
|
||
- https://learn.microsoft.com/en-us/azure/foundry-classic/openai/how-to/on-your-data-best-practices
|
||
- Verified: topNDocuments, strictness, chunk_size, workflow funnel
|
||
|
||
3. **Quotas and limits for Copilot Studio**
|
||
- https://learn.microsoft.com/en-us/microsoft-copilot-studio/requirements-quotas
|
||
- Verified: 28 KB ACS channel limit, conversation timeout behavior
|
||
|
||
4. **How Copilot in Microsoft Fabric works**
|
||
- https://learn.microsoft.com/en-us/fabric/fundamentals/how-copilot-works
|
||
- Verified: Schema reduction, token smoothing, grounding data optimization
|
||
|
||
5. **Overview of the Microsoft 365 Copilot Chat API (preview)**
|
||
- https://learn.microsoft.com/en-us/microsoft-365-copilot/extensibility/api/ai-services/chat/overview
|
||
- Verified: Known limitations, no long-running task support, context limits
|
||
|
||
6. **Azure OpenAI Predicted Outputs**
|
||
- https://learn.microsoft.com/en-us/azure/foundry/openai/how-to/predicted-outputs
|
||
- Verified: Prediction parameter for latency optimization
|
||
|
||
7. **Copilot handoff (Teams Bot Framework)**
|
||
- https://learn.microsoft.com/en-us/microsoftteams/platform/bots/how-to/conversations/bot-copilot-handoff
|
||
- Verified: Continuation tokens, context handoff mechanism
|
||
|
||
**Confidence level:**
|
||
- **Core mechanisms:** Verified (MCP-basert research, januar 2026)
|
||
- **Pricing estimates:** Baseline (modellantagelser basert på Azure pricing calculator, NOK exchange rate)
|
||
- **Offentlig sektor-anbefalinger:** Baseline (basert på generelle GDPR/Datatilsynet-prinsipper, ikke produkt-spesifikk dokumentasjon)
|
||
|
||
**Sist oppdatert:** 2026-06-19 (Session-basert research via microsoft-learn MCP)
|