Prompts¶
In the Strands Agents SDK, system prompts and user messages are the primary way to communicate with AI models. The SDK provides a flexible system for managing prompts, including both system prompts and user messages.
System Prompts¶
System prompts provide high-level instructions to the model about its role, capabilities, and constraints. They set the foundation for how the model should behave throughout the conversation. You can specify the system prompt when initializing an Agent:
from strands import Agent
agent = Agent(
system_prompt=(
"You are a financial advisor specialized in retirement planning. "
"Use tools to gather information and provide personalized advice. "
"Always explain your reasoning and cite sources when possible."
)
)
If you do not specify a system prompt, the model will behave according to its default settings.
User Messages¶
These are your queries or requests to the agent. The SDK supports multiple techniques for prompting.
Text Prompt¶
The simplest way to interact with an agent is through a text prompt:
Multi-Modal Prompting¶
The SDK also supports multi-modal prompts, allowing you to include images, documents, and other content types in your messages:
with open("path/to/image.png", "rb") as fp:
image_bytes = fp.read()
response = agent([
{"text": "What can you see in this image?"},
{
"image": {
"format": "png",
"source": {
"bytes": image_bytes,
},
},
},
])
For a complete list of supported content types, please refer to the API Reference.
Direct Tool Calls¶
Prompting is a primary functionality of Strands that allows you to invoke tools through natural language requests. However, if at any point you require more programmatic control, Strands also allows you to invoke tools directly:
Direct tool calls bypass the natural language interface and execute the tool using specified parameters. These calls are added to the conversation history by default. However, you can opt out of this behavior by setting record_direct_tool_call=False
.
Prompt Engineering¶
For guidance on how to write safe and responsible prompts, please refer to our Safety & Security - Prompt Engineering documentation.
Further resources: