#10Build the chat messages listEasyLLMsAgentic AI
Build the chat messages list
Background
Every LLM call in this course uses the same shape: a list of role-tagged messages. ResearchAgent.run() builds a system message (the agent's instructions) followed by a user message (the query), then passes them to llm.chat(messages).
[
{"role": "system", "content": "..."},
{"role": "user", "content": "..."},
]
Problem statement
Implement build_messages(system_prompt, user_query) returning the two-message list.
Input
system_prompt— the system instruction string.user_query— the user's question string.
Output
Returns a list of two dicts: a "system" message then a "user" message, each with "role" and "content" keys.
Examples
Example 1
Input: system_prompt = "You are a research assistant.", user_query = "What is RL?"
Output: [{"role": "system", "content": "You are a research assistant."},
{"role": "user", "content": "What is RL?"}]
Constraints
- System message first, user message second.
- Each dict has exactly
"role"and"content".
Notes
- Keeping this format fixed is what lets the same agent talk to a mock, OpenAI, or Anthropic without changes.
Python
Loading...
▶ Run executes the 3 visible sample tests below in your browser. Submit runs the full suite — including hidden tests — on the server for an official verdict.
- •Reference example: research assistant and What is RL?
- •Sample: system then user structure
- •Reference: empty strings still produce two messages