Skip to content

Commit 481ccac

Browse files
authored
docs: add system message customization section to Python README (#1066)
1 parent 460b48a commit 481ccac

1 file changed

Lines changed: 81 additions & 0 deletions

File tree

python/README.md

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,87 @@ async with await client.create_session(
589589
> - For Azure OpenAI endpoints (`*.openai.azure.com`), you **must** use `type: "azure"`, not `type: "openai"`.
590590
> - The `base_url` should be just the host (e.g., `https://my-resource.openai.azure.com`). Do **not** include `/openai/v1` in the URL - the SDK handles path construction automatically.
591591
592+
## System Message Customization
593+
594+
Control the system prompt using `system_message` in session config:
595+
596+
```python
597+
async with await client.create_session(
598+
on_permission_request=PermissionHandler.approve_all,
599+
model="gpt-5",
600+
system_message={
601+
"mode": "append",
602+
"content": """
603+
<workflow_rules>
604+
- Always check for security vulnerabilities
605+
- Suggest performance improvements when applicable
606+
</workflow_rules>
607+
""",
608+
},
609+
) as session:
610+
...
611+
```
612+
613+
### Customize Mode
614+
615+
Use `mode: "customize"` to selectively override individual sections of the prompt while preserving the rest:
616+
617+
```python
618+
async with await client.create_session(
619+
on_permission_request=PermissionHandler.approve_all,
620+
model="gpt-5",
621+
system_message={
622+
"mode": "customize",
623+
"sections": {
624+
"tone": {"action": "replace", "content": "Respond in a warm, professional tone. Be thorough in explanations."},
625+
"code_change_rules": {"action": "remove"},
626+
"guidelines": {"action": "append", "content": "\n* Always cite data sources"},
627+
},
628+
"content": "Focus on financial analysis and reporting.",
629+
},
630+
) as session:
631+
...
632+
```
633+
634+
Available section IDs: `"identity"`, `"tone"`, `"tool_efficiency"`, `"environment_context"`, `"code_change_rules"`, `"guidelines"`, `"safety"`, `"tool_instructions"`, `"custom_instructions"`, `"last_instructions"`.
635+
636+
Each section override supports four string actions: `"replace"`, `"remove"`, `"append"`, and `"prepend"`. Unknown section IDs are handled gracefully: content is appended to additional instructions, and `"remove"` overrides are silently ignored.
637+
638+
You can also pass a transform callback as the `action` instead of a string. The callback receives the current section content and returns the new content (sync or async):
639+
640+
```python
641+
def redact_paths(content: str) -> str:
642+
return content.replace("/home/user", "/***")
643+
644+
async with await client.create_session(
645+
on_permission_request=PermissionHandler.approve_all,
646+
model="gpt-5",
647+
system_message={
648+
"mode": "customize",
649+
"sections": {
650+
"environment_context": {"action": redact_paths},
651+
},
652+
},
653+
) as session:
654+
...
655+
```
656+
657+
### Replace Mode
658+
659+
For full control (removes all SDK guardrails including security restrictions), use `mode: "replace"`:
660+
661+
```python
662+
async with await client.create_session(
663+
on_permission_request=PermissionHandler.approve_all,
664+
model="gpt-5",
665+
system_message={
666+
"mode": "replace",
667+
"content": "You are a helpful assistant.",
668+
},
669+
) as session:
670+
...
671+
```
672+
592673
## Telemetry
593674

594675
The SDK supports OpenTelemetry for distributed tracing. Provide a `telemetry` config to enable trace export and automatic W3C Trace Context propagation.

0 commit comments

Comments
 (0)