📖 Lesson content
Summary
The code we've written so far simulates a very simple exchange with Claude. But what happens when you want to continue a conversation? When you ask a follow-up question like "And 3 more?" after asking "What's 1+1?", you might expect Claude to understand you're asking about adding 3 to the previous result of 2.

However, there's something critical you need to understand about the Bedrock API and Claude itself.
No Message Storage
Bedrock and Claude do not store any messages. None of the messages you send get stored, and none of the responses you receive are stored either. Each API call is completely independent.

To have a conversation with multiple messages that maintain context, you need to:
- Manually maintain a list of all messages in your code
- Provide that entire list of messages with each follow-up request
Why Context Matters
Let's see what happens without proper context. If you send just "And 3 more?" as a standalone message, Claude has no idea what you're referring to. It will do its best to respond, but the answer won't make sense because it lacks the context of your previous conversation.

When you send only the follow-up question, Claude sees just that isolated message and tries to respond without knowing about the previous "What's 1+1?" exchange.

Building Conversation Context
To maintain context, you need to include the full conversation history in each request. Here's how it works:

Your message list should contain all previous exchanges - both user messages and assistant responses. When you send this complete context, Claude can understand that "And 3 more?" refers to adding 3 to the previous result of 2.
Helper Functions for Message Management
To make conversation management easier, you can create helper functions:
def add_user_message(messages, text):
user_message = {
"role": "user",
"content": [
{"text": text}
]
}
messages.append(user_message)
def add_assistant_message(messages, text):
assistant_message = {
"role": "assistant",
"content": [
{"text": text}
]
}
messages.append(assistant_message)
def chat(messages):
response = client.converse(
modelId=model_id,
messages=messages
)
return response["output"]["message"]["content"][0]["text"]
Implementing Multi-Turn Conversations
Here's how to build a conversation step by step:
messages = []
add_user_message(messages, "What's 1+1?")
answer = chat(messages)
add_assistant_message(messages, answer)
add_user_message(messages, "And 3 more added to that?")
answer = chat(messages)
print(answer)
This approach ensures Claude has the full context and can respond appropriately: "Starting with the result of 1+1 = 2, if we add 3 more to that, we get: 2 + 3 = 5"
Message Role Alternation
When building your message list, always ensure that message roles alternate properly:

Your conversation should follow the pattern: user → assistant → user → assistant. Never have two user messages in a row or two assistant messages in a row. This alternating pattern is required by the API and reflects natural conversation flow.
While this manual message management might seem tedious at first, you'll quickly get used to it. This pattern is fundamental to building any application that needs to maintain conversational context with Claude.
🔁 Related lessons
- Next: Chat bot exercise
- Previous: Making a request
- Same section: Overview of Claude Models · Accessing the API · Making a request
- Part of paths: Path C
- Reference docs: Glossary · Skills atlas · By use-case
📚 Source & attribution
- Original Anthropic Academy lesson: https://anthropic.skilljar.com/claude-in-amazon-bedrock/276722
- © 2025 Anthropic. Educational fair-use only.