This document explains how to use Context Mode in Prompt Optimizer: what it is, when to use it, and common pitfalls.
In the UI, Context Mode is the top-level Function Mode: Context. It provides two sub-modes:
- Multi-message: message-level optimization in a conversation (multi-turn)
- Variable: single user prompt optimization with variables & tools
When “single prompt optimization” feels unstable, it often lacks real context: prior constraints, examples, available tools, or variable values.
Context Mode helps by sending your configured messages / variables / tools together as the optimization context, so the output better matches the real execution environment.
Use this table as a quick decision:
| Your goal | Recommended sub-mode |
|---|---|
| You are doing role-play or multi-turn chat, and want to optimize one specific system/user message while keeping style consistent with the conversation | Multi-message |
| You have one user prompt, but many reusable parameters (name/date/spec/output format) and want to manage them via {{var}} for reuse & testing | Variable |
| You want to configure tools (Function Calling) and verify tool behavior during testing | Variable |
Both sub-modes support the test area (multi-column comparison) on the right.
Best for: optimizing a single system/user message inside a conversation (not generating a reply).
- Select Function Mode: Context
- Select sub-mode Multi-message
Add/edit conversation messages on the left:
- system/user/assistant/tool can all exist as context
- but the usual optimization targets are system or user messages
You must select a system/user message; otherwise the Optimize button is disabled.
Start with the built-in recommended template:
- General Message Optimization (Recommended)
This template enforces a few critical rules:
- Optimization is NOT replying
- Keep the original role (system stays system, user stays user)
- Preserve all
{{var}}placeholders as-is
Multi-message optimization uses a per-message version chain:
- V0: original content (for rollback)
- V1: optimized content (usually applied back to the conversation by default)
If the optimization gets worse, switch versions (e.g. back to V0) instead of manual copy/paste rollback.
Treat testing as acceptance:
- Fill variable values (if your messages contain
{{var}}) - Run tests (use multi-column variants to compare)
- Check format, tone, constraints, and tool behavior
Best for: optimizing one user prompt with reusable variables and optional tools.
- Select Function Mode: Context
- Select sub-mode Variable
Example:
Create a plan for {{product_name}}.
Output format: {{output_format}}.
Constraints: budget {{budget}}, deadline {{deadline}}.
Tip: typing {{}} often triggers variable auto-completion.
If you still see {{var}} in preview/test outputs, that variable has no value. Set it first, then re-run preview or test.
If your prompt is meant to run with tools:
- Define tools in Tool Manager (name/description/parameters)
- Validate tool calling behavior in the test area
Variable-mode templates usually focus on rewriting the user prompt to be clear, executable, and verifiable, while preserving all {{var}} placeholders.
Recommended starting template:
- Contextual User Prompt Basic Refinement
- “It replies instead of optimizing”: check your template instructions; the recommended multi-message template is explicitly optimization-only.
- “Optimize button disabled”: in Multi-message mode, you likely didn't select a target message or didn't choose model/template.
- “The message content changed after optimize”: expected behavior; use version switching to revert to V0.
- “I still see {{var}} in preview/output”: that variable has no value yet. Set the variable value, then re-run preview/test.
If you are preparing a reply for Issue #240, you can link this doc (docs/user/context-mode_en.md) and quote the decision table in Section 2. That usually helps users pick the correct sub-mode quickly.