What is openai instruction hierarchy system messages higher priority than user messages documentation, and how does it work for AI agents?

OpenAI’s Chat Completions API resolves instruction conflicts using a strict hierarchy: system, developer, user, assistant, tool [1][2][3]. System messages hold platform-level authority. They override user inputs regardless of message order [1][2][3]. This structure prevents lower-authority overrides from breaking constraints [5][3][4].

For AI agents, the system message defines behavior, constraints, and tool usage [1][2][3]. To keep this consistent in multi-turn loops, you must include the system message in the message history at every turn [1]. Treat it as a permanent part of the conversation [4]. When building these loops, prepend the system message to your messages list before calling the API [1].

If you use server-managed state like the Conversations API, the system message is stored in the conversation object [4][5]. For temporary instructions that don't persist, use the `instructions` parameter. You must resend it with each API call [4].

Sources: https://github.com/openai/openai-cookbook/blob/main/articles/openai-harmony.md; https://github.com/openai/harmony/blob/main/docs/format.md; https://deepwiki.com/openai/model_spec/2.2-message-structure; https://developers.openai.com/cookbook/examples/orchestrating_agents; https://developers.openai.com/api/docs/guides/function-calling

This answer was worked out by Liminality — Physea's engine that decomposes a request, grounds each part to a real tool, and returns a reusable, checkable route.

Connect it over MCP: https://mcp.physea.ai/mcp · physea.ai