Skip tool guidance, custom prompt, and Agent Skills for tool-incapable models
effectiveSystemPrompt now gates tool-usage guidelines, the user's custom system prompt, and active Agent Skills behind whether the selected model actually supports tools (ModelInfo.capabilities.tools). All three assume tool/file/web access and can easily blow past small context windows. Confirmed live against Apple Intelligence: the default system prompt dropped from 16,377 to ~250 tokens (well under the 4K on-device limit), fully resolving the context-exceeded error from the initial Phase 1 rollout. Verified end-to-end with a real successful generation in the app after the fix. Also: .gitignore now excludes *.profraw (stray code-coverage artifact picked up while testing). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -31,6 +31,9 @@ DerivedData/
|
|||||||
*.dSYM.zip
|
*.dSYM.zip
|
||||||
*.dSYM
|
*.dSYM
|
||||||
|
|
||||||
|
## Code coverage
|
||||||
|
*.profraw
|
||||||
|
|
||||||
## Playgrounds
|
## Playgrounds
|
||||||
timeline.xctimeline
|
timeline.xctimeline
|
||||||
playground.xcworkspace
|
playground.xcworkspace
|
||||||
|
|||||||
@@ -151,8 +151,14 @@ Don't narrate future actions ("Let me...") - just use the tools.
|
|||||||
|
|
||||||
/// Builds the complete system prompt by combining default + conditional sections + custom
|
/// Builds the complete system prompt by combining default + conditional sections + custom
|
||||||
private var effectiveSystemPrompt: String {
|
private var effectiveSystemPrompt: String {
|
||||||
|
// Tool guidance, the user's custom prompt, and Agent Skills all generally assume tool
|
||||||
|
// access and can easily blow past small context windows (e.g. Apple's on-device 4K
|
||||||
|
// limit) — skip all three for tool-incapable models.
|
||||||
|
let modelSupportsTools = selectedModel?.capabilities.tools ?? true
|
||||||
|
|
||||||
// Check if user wants to replace the default prompt entirely (BYOP mode)
|
// Check if user wants to replace the default prompt entirely (BYOP mode)
|
||||||
if settings.customPromptMode == .replace,
|
if modelSupportsTools,
|
||||||
|
settings.customPromptMode == .replace,
|
||||||
let customPrompt = settings.systemPrompt,
|
let customPrompt = settings.systemPrompt,
|
||||||
!customPrompt.isEmpty {
|
!customPrompt.isEmpty {
|
||||||
// BYOP: Use ONLY the custom prompt
|
// BYOP: Use ONLY the custom prompt
|
||||||
@@ -170,18 +176,20 @@ Don't narrate future actions ("Let me...") - just use the tools.
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add tool-specific guidelines if MCP is enabled (tools are available)
|
// Add tool-specific guidelines if MCP is enabled (tools are available)
|
||||||
if mcpEnabled {
|
if mcpEnabled && modelSupportsTools {
|
||||||
prompt += toolUsageGuidelines
|
prompt += toolUsageGuidelines
|
||||||
}
|
}
|
||||||
|
|
||||||
// Append custom prompt if in append mode and custom prompt exists
|
// Append custom prompt if in append mode and custom prompt exists
|
||||||
if settings.customPromptMode == .append,
|
if modelSupportsTools,
|
||||||
|
settings.customPromptMode == .append,
|
||||||
let customPrompt = settings.systemPrompt,
|
let customPrompt = settings.systemPrompt,
|
||||||
!customPrompt.isEmpty {
|
!customPrompt.isEmpty {
|
||||||
prompt += "\n\n---\n\nAdditional Instructions:\n" + customPrompt
|
prompt += "\n\n---\n\nAdditional Instructions:\n" + customPrompt
|
||||||
}
|
}
|
||||||
|
|
||||||
// Append active agent skills (SKILL.md-style behavioral instructions)
|
// Append active agent skills (SKILL.md-style behavioral instructions)
|
||||||
|
if modelSupportsTools {
|
||||||
let activeSkills = settings.agentSkills.filter { $0.isActive }
|
let activeSkills = settings.agentSkills.filter { $0.isActive }
|
||||||
if !activeSkills.isEmpty {
|
if !activeSkills.isEmpty {
|
||||||
prompt += "\n\n---\n\n## Installed Skills\n\nThe following skills are active. Apply them when relevant:\n\n"
|
prompt += "\n\n---\n\n## Installed Skills\n\nThe following skills are active. Apply them when relevant:\n\n"
|
||||||
@@ -197,6 +205,7 @@ Don't narrate future actions ("Let me...") - just use the tools.
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return prompt
|
return prompt
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user