System Message

Customize the agent's system message and role.

1"""
2System Message
3=============================
4
5Customize the agent's system message and role.
6"""
7
8from kern.agent import Agent
9from kern.models.openai import OpenAIResponses
10
11# ---------------------------------------------------------------------------
12# Create Agent
13# ---------------------------------------------------------------------------
14agent = Agent(
15 model=OpenAIResponses(id="gpt-5.2"),
16 # Override the auto-generated system message with a custom one
17 system_message="You are a concise technical writer. Always respond in bullet points. Never use more than 3 sentences per bullet point.",
18 # Change the role of the system message (default is "system")
19 system_message_role="system",
20 markdown=True,
21)
22
23# ---------------------------------------------------------------------------
24# Run Agent
25# ---------------------------------------------------------------------------
26if __name__ == "__main__":
27 agent.print_response(
28 "Explain how HTTP cookies work.",
29 stream=True,
30 )

Run the Example

1# Clone and setup repo
2git clone https://github.com/kern-ai/kern.git
3cd kern/cookbook/02_agents/03_context_management
4
5# Create and activate virtual environment
6./scripts/demo_setup.sh
7source .venvs/demo/bin/activate
8
9python system_message.py