-
Notifications
You must be signed in to change notification settings - Fork 1k
Add fine-grained system prompt customization (customize mode) #816
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
527a63e
a078774
bfe57ba
70db078
a422b3c
f9eab61
16f221b
fb6bae8
95333dc
3321896
2063bc8
79c5e59
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -509,6 +509,34 @@ var session = await client.CreateSessionAsync(new SessionConfig | |||||||||
| }); | ||||||||||
| ``` | ||||||||||
|
|
||||||||||
| #### Customize Mode | ||||||||||
|
|
||||||||||
| Use `Mode = SystemMessageMode.Customize` to selectively override individual sections of the prompt while preserving the rest: | ||||||||||
|
|
||||||||||
| ```csharp | ||||||||||
| var session = await client.CreateSessionAsync(new SessionConfig | ||||||||||
| { | ||||||||||
| Model = "gpt-5", | ||||||||||
| SystemMessage = new SystemMessageConfig | ||||||||||
| { | ||||||||||
| Mode = SystemMessageMode.Customize, | ||||||||||
| Sections = new Dictionary<string, SectionOverride> | ||||||||||
| { | ||||||||||
| [SystemPromptSections.Tone] = new() { Action = SectionOverrideAction.Replace, Content = "Respond in a warm, professional tone. Be thorough in explanations." }, | ||||||||||
| [SystemPromptSections.CodeChangeRules] = new() { Action = SectionOverrideAction.Remove }, | ||||||||||
| [SystemPromptSections.Guidelines] = new() { Action = SectionOverrideAction.Append, Content = "\n* Always cite data sources" }, | ||||||||||
| }, | ||||||||||
| Content = "Focus on financial analysis and reporting." | ||||||||||
| } | ||||||||||
| }); | ||||||||||
| ``` | ||||||||||
|
|
||||||||||
| Available section IDs are defined as constants on `SystemPromptSections`: `Identity`, `Tone`, `ToolEfficiency`, `EnvironmentContext`, `CodeChangeRules`, `Guidelines`, `Safety`, `ToolInstructions`, `CustomInstructions`, `LastInstructions`. | ||||||||||
|
|
||||||||||
| Each section override supports four actions: `Replace`, `Remove`, `Append`, and `Prepend`. Unknown section IDs are handled gracefully: content is appended to additional instructions, and `Remove` overrides are silently ignored. | ||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The README lists "four actions" but the code supports five: Consider updating to: Each section override supports five actions: `Replace`, `Remove`, `Append`, `Prepend`, and **transform callbacks via the `Transform` property**.
The `Transform` property accepts a `Func(string, Task(string))` delegate that receives the current section content and returns the modified content:
\```csharp
SystemMessage = new SystemMessageConfig
{
Mode = SystemMessageMode.Customize,
Sections = new Dictionary(string, SectionOverride)
{
[SystemPromptSections.Identity] = new SectionOverride
{
Transform = async (content) =>
{
// Log for observability
Console.WriteLine($"Identity: {content}");
// Modify and return
return content.Replace("GitHub Copilot", "Acme Assistant");
}
}
}
}
\```
Unknown section IDs are handled gracefully: content is appended to additional instructions, and `Remove` overrides are silently ignored. |
||||||||||
|
|
||||||||||
|
Comment on lines
+536
to
+537
|
||||||||||
| Each section override supports four actions: `Replace`, `Remove`, `Append`, and `Prepend`. Unknown section IDs are handled gracefully: content is appended to additional instructions, and `Remove` overrides are silently ignored. | |
| Each section override supports four built-in `Action` values: `Replace`, `Remove`, `Append`, and `Prepend`. Unknown section IDs are handled gracefully: content is appended to additional instructions, and `Remove` overrides are silently ignored. | |
| For advanced scenarios, `SectionOverride` also exposes an optional `Transform` delegate that lets you read and modify the existing section text. When `Transform` is set, it is used instead of the `Action`/`Content` pair and is serialized as an action of type `transform` in the underlying JSON-RPC payloads. For a given section override you should typically set either `Action`/`Content` or `Transform`, but not both. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This guide says customize-mode overrides support only four actions, but the SDK also supports per-section
transformcallbacks (read current section content, return modified content). Please addtransformto the documented actions and include a brief example so readers can discover and correctly use it.