feat: improve AI chat - system prompt, tool output, context window display (#17769)

⚠️ **AI-generated PR — not ready for review** ⚠️

cc @FelixMalfait

---

## Changes

### System prompt improvements
- Explicit skill-before-tools workflow to prevent the model from calling
tools without loading the matching skill first
- Data efficiency guidance (default small limits, use filters)
- Pluralized `load_skill` → `load_skills` for consistency with
`load_tools`

### Token usage reduction
- Output serialization layer: strips null/undefined/empty values from
tool results
- Lowered default `find_*` limit from 100 → 10, max from 1000 → 100

### System object tool generation
- System objects (calendar events, messages, etc.) now generate AI tools
- Only workflow-related and favorite-related objects are excluded

### Context window display fix
- **Bug**: UI compared cumulative tokens (sum of all turns) against
single-request context window → showed 100% after a few turns
- **Fix**: Track `conversationSize` (last step's `inputTokens`) which
represents the actual conversation history size sent to the model
- New `conversationSize` column on thread entity with migration

### Workspace AI instructions
- Support for custom workspace-level AI instructions

---------

Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com>
This commit is contained in:
Félix Malfait
2026-02-09 14:26:02 +01:00
committed by GitHub
co-authored by claude[bot] <41898282+claude[bot]@users.noreply.github.com>
parent 6c7c389785
commit 3216b634a3
105 changed files with 3245 additions and 1714 deletions
+13
View File
@@ -48,6 +48,18 @@ __metadata:
languageName: node
linkType: hard
"@ai-sdk/groq@npm:^2.0.34":
version: 2.0.34
resolution: "@ai-sdk/groq@npm:2.0.34"
dependencies:
"@ai-sdk/provider": "npm:2.0.1"
"@ai-sdk/provider-utils": "npm:3.0.20"
peerDependencies:
zod: ^3.25.76 || ^4.1.8
checksum: 10c0/1e1ad69db49e1b06f18f2e7181f8a094afc275bb9cd96edc614303ff0a86945ba0c25adcf3d2ccbf398eb275d9348fc6224ba8af60009a9a9e23bb25dc718a5f
languageName: node
linkType: hard
"@ai-sdk/openai-compatible@npm:1.0.30":
version: 1.0.30
resolution: "@ai-sdk/openai-compatible@npm:1.0.30"
@@ -56985,6 +56997,7 @@ __metadata:
resolution: "twenty-server@workspace:packages/twenty-server"
dependencies:
"@ai-sdk/anthropic": "npm:^2.0.17"
"@ai-sdk/groq": "npm:^2.0.34"
"@ai-sdk/openai": "npm:^2.0.30"
"@ai-sdk/provider-utils": "npm:^3.0.9"
"@ai-sdk/xai": "npm:^2.0.19"