Sypha AI Docs
Features

New Chat Button Integration

Documentation for the New Chat Button feature and context window management.

New Chat Button Integration (Context Window Threshold)

This guide documents the New Chat Button feature that appears when a conversation approaches the context window limit.

Overview

  • Shows a "New Chat" button when recent token usage reaches 85% of the allowed context window.
  • Clicking the button immediately triggers a new task by calling the service with the /newtask command.
  • The button is rendered beneath the chat input only when the threshold is met.

Files Added

  • webview-ui/src/utils/contextWindowUtils.ts
    • Provides getContextWindowThresholds(contextWindow); currently returns the full window.
  • webview-ui/src/hooks/useContextWindowStatus.ts
    • Computes shouldShowNewChatButton, usagePercentage, and isNearCapacity from lastApiReqTotalTokens and the model contextWindow.
  • webview-ui/src/components/chat/NewChatButton.tsx
    • UI for the usage text and gradient "New Chat" button.
    • On click: TaskServiceClient.newTask(NewTaskRequest.create({ text: "/newtask", images: [], files: [] })).

Files Updated

  • webview-ui/src/components/chat/ChatView.tsx
    • Imports the hook and button, computes contextWindow from selectedModelInfo, and renders the button below the input when shouldShowNewChatButton is true.

How It Works

  1. ChatView.tsx derives:
    • lastApiReqTotalTokens from the latest api_req_started message.
    • contextWindow via normalizeApiConfiguration(...).selectedModelInfo.
  2. useContextWindowStatus(lastApiReqTotalTokens, contextWindow) returns:
    • shouldShowNewChatButton: true when lastApiReqTotalTokens >= 0.85 * maxAllowedSize.
    • usagePercentage: (lastApiReqTotalTokens / contextWindow) * 100.
    • isNearCapacity: true when lastApiReqTotalTokens >= maxAllowedSize.
  3. When shouldShowNewChatButton is true, ChatView renders NewChatButton under the input.
  4. Clicking NewChatButton immediately invokes TaskServiceClient.newTask with /newtask.

Configuration

  • Headroom logic lives in getContextWindowThresholds(contextWindow).
    • Default: maxAllowedSize = contextWindow.
    • To add headroom, change to e.g. Math.floor(contextWindow * 0.95).
  • Display threshold is fixed at 85% of maxAllowedSize inside the hook.

Usage

No user settings required. The button appears automatically as context usage approaches the configured threshold.

Getting Started Workflow (New Users)

  1. Open Sypha chat and start a conversation normally.
  2. Watch the usage indicator; when near limit, a “New Chat” button appears.
  3. Click “New Chat” to spawn a fresh task (internally sends /newtask).
  4. Continue in the new chat to keep context small and focused.

Testing

  1. Start a chat and generate API requests (send messages, run tools) until usage approaches 85%.
  2. Verify the button appears beneath the input when the threshold is reached.
  3. Click the button and confirm a new task is created (service call) and the UI reflects the new task/session.

Troubleshooting

  • Button doesn’t appear:
    • Ensure at least one API request has non-zero tokens in the current session.
    • Confirm the selected model has a valid contextWindow.
  • Button click does nothing:
    • Check the console for errors from TaskServiceClient.newTask.
    • Verify generated proto types and @/services/grpc-client are available.
  • docs/SyphaFeature/Prompt-Enhancer-Integration.md
  • docs/SyphaFeature/Mermaid-Diagram-Integration.md

On this page