Inject Maple UX context to help assistant guide users - #733
Draft
ldstreet wants to merge 3 commits into
Draft
Conversation
Deploying maple with
|
| Latest commit: |
175b129
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://eb328ea6.maple-ca8.pages.dev |
| Branch Preview URL: | https://agent-maple.maple-ca8.pages.dev |
ldstreet
marked this pull request as draft
August 4, 2026 16:02
Fixes #511. When web search is toggled off mid-conversation, the model can remember that web_search was available in previous turns and attempt to use it. Since the tool isn't in the current request's tools array, the tool call fails silently, leaving the user with no output. This change detects when: - Response completes successfully - Tool calls were attempted but produced no outputs (failed) - No assistant message text was generated In this case, we now show a user-friendly error: "The model attempted to use a feature that's not currently available. Try rephrasing your request without requiring that feature." This gives users actionable feedback instead of a silent failure. Also retains debug logging to help verify the fix works correctly. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Fixes #511 properly. When web search is toggled mid-conversation, the model can remember that web_search was available in earlier turns and attempt to use it even though it's not in the current request's tools array. Instead of catching the failure after the fact, this change proactively tells the model what tools are available by prepending context to the user's message: - When web search is OFF in a follow-up turn: "[System context: Web search is not available for this request. Please respond without using web search capabilities.]" - When web search is ON in a follow-up turn: "[System context: Web search is available for this request.]" This allows the model to understand the tool availability upfront during reasoning and respond appropriately - either using the tool or explaining it can't search - rather than attempting a tool call that will fail. The context is only added for follow-up messages in existing conversations where tool availability might differ from previous turns. New conversations don't need this context since there's no prior tool usage to remember. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Automatically provides UI context to the Maple assistant on the first message of each conversation, enabling it to guide users through the app. **Changes**: **src/components/UnifiedChat.tsx**: - Detect first message vs follow-up (new `isFirstMessage` flag) - Inject Maple UX context as system message prefix on first message - Context includes: - Web search toggle (globe icon) with current state - File upload menu (+ icon) for images and documents - Project picker (folder icon) - Model selection (Quick vs Powerful) - Settings access - Instruction to reference UI only when in app (not API/proxy) **src/instructions/maple-ux-context.ts**: - Exportable UX instruction constant - Concise UI element descriptions - Used for inline injection (not as stored instruction) **How it works**: - First message: Prepends full UX context with current web search state - Follow-up messages: Only includes web search availability context - Assistant knows about UI and can say "tap the globe icon to enable search" **Example**: User: "How do I search the web?" Assistant: "Web search is currently enabled (the globe icon is highlighted). I can search for current information. To toggle it off, tap the globe icon in your composer toolbar at the bottom." Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Contributor
|
Something like this shouldn't live in the app, we have server managed context and roles, and I also do not want to be adding this to system instructions as a whole, it should be hidden behind a tool use. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Enables the Maple assistant to understand and guide users through the app interface by automatically injecting UX context into the first message of every conversation.
The Problem
When users ask Maple how to use features in the app ("how do I search the web?", "can you see images?"), the assistant doesn't know about the UI elements available in Maple. It can't tell users to "tap the globe icon" or "use the + button" because it has no context about what interface the user is seeing.
The Solution
Auto-inject UX context on first message: Prepend a system context block to the first user message of each conversation that describes the Maple UI elements available.
Implementation
Changes
frontend/src/components/UnifiedChat.tsx:isFirstMessageflag)[System: ...]prefixfrontend/src/instructions/maple-ux-context.ts:How It Works
First message of a conversation:
Follow-up messages: Only tool availability context (existing behavior)
Benefits
✅ Context-aware guidance: "Tap the globe icon to toggle web search"
✅ Dynamic state: Shows current web search enabled/disabled state
✅ Zero user setup: Works automatically for all conversations
✅ No backend changes: Pure frontend implementation
✅ Minimal overhead: ~300 tokens only on first message
Example Interactions
Before (no UX context):
After (with UX context):
Before (no UX context):
After (with UX context):
Testing
To test:
Future Enhancements
Potential improvements:
Notes
[System: ...]pattern already in UnifiedChat for tool context🤖 Generated with Claude Code