Writer’s models are available on AWS Strands Agents.
Strands Agents SDK from AWS is an open-source framework that enables developers to build and deploy AI agents using a model-driven approach. This integration allows you to use Writer models within the Strands agent ecosystem, from local development to production deployment.
Prerequisites
Before you begin, make sure you have:
Installation
To use Writer models with Strands Agents, install the optional Writer dependency:
pip install 'strands-agents[writer]'
To follow along with the examples in this guide, you’ll also need the Strands Agent Tools package. Install the package with pip install strands-agent-tools
.
Usage
After installing, you can import and initialize the Writer provider in Strands Agents:
from strands import Agent
from strands.models.writer import WriterModel
from strands_tools import calculator
model = WriterModel(
client_args={"api_key": "<WRITER_API_KEY>"},
model_id="palmyra-x5",
)
agent = Agent(model=model, tools=[calculator])
response = agent("What is 2+2")
print(response)
By default, Strands Agents use a PrintingCallbackHandler
that streams responses to stdout as they’re generated. When you call agent("What is 2+2")
, you’ll see the response appear in real-time as it’s being generated. The print(response)
above also shows the final collected result after the response is complete. See Callback Handlers in the Strands documentation for more details.
Configuration
Client configuration
You can pass additional arguments to the Writer client via client_args
:
model = WriterModel(
client_args={
"api_key": "<WRITER_API_KEY>",
"timeout": 30,
"base_url": "https://api.writer.com/v1",
# Additional client configuration options
},
model_id="palmyra-x5"
)
Model configuration
The WriterModel
accepts configuration parameters as keyword arguments to the model constructor:
Parameter | Type | Description | Default | Options |
---|
model_id | str | Model name to use (e.g. palmyra-x5, palmyra-x4, etc.) | Required | reference |
max_tokens | Optional[int] | Maximum number of tokens to generate | See the Context Window for each available model | reference |
stop | Optional[Union[str, List[str]]] | A token or sequence of tokens that, when generated, will cause the model to stop producing further content. This can be a single token or an array of tokens, acting as a signal to end the output. | None | reference |
stream_options | Dict[str, Any] | Additional options for streaming. Specify include_usage to include usage information in the response, in the accumulated_usage field. If you do not specify this, accumulated_usage will show 0 for each value. | None | reference |
temperature | Optional[float] | What sampling temperature to use (0.0 to 2.0). A higher temperature will produce more random output. | 1 | reference |
top_p | Optional[float] | Threshold for “nucleus sampling” | None | reference |
Available models
Writer offers several specialized Palmyra models:
Model | Model ID | Context Window | Description |
---|
Palmyra X5 | palmyra-x5 | 1M tokens | Latest model with 1 million token context for complex workflows, supports vision and multi-content |
Palmyra X4 | palmyra-x4 | 128k tokens | Advanced model for workflow automation and tool calling |
Palmyra Fin | palmyra-fin | 128k tokens | Finance-specialized model (first to pass CFA exam) |
Palmyra Med | palmyra-med | 32k tokens | Healthcare-specialized model for medical analysis |
Palmyra Creative | palmyra-creative | 128k tokens | Creative writing and brainstorming model |
See the Writer models guide for more details and use cases.
Environment variables
You can set your Writer API key as an environment variable instead of passing it directly:
export WRITER_API_KEY="your_api_key_here"
Then initialize the model without the client_args["api_key"]
parameter:
model = WriterModel(model_id="palmyra-x5")
Examples
Enterprise workflow automation
from strands import Agent
from strands.models.writer import WriterModel
from my_tools import web_search, email_sender # Custom tools from your local module
model = WriterModel(
client_args={"api_key": "<WRITER_API_KEY>"},
model_id="palmyra-x5",
)
agent = Agent(
model=model,
tools=[web_search, email_sender],
system_prompt="You are an enterprise assistant that helps automate business workflows."
)
response = agent("Research our competitor's latest product launch and draft a summary email for the leadership team")
The web_search
and email_sender
tools in this example are custom tools that you would need to define. See Python Tools for guidance on creating custom tools, or use existing tools from the strands_tools package.
Financial analysis with Palmyra Fin
from strands import Agent
from strands.models.writer import WriterModel
# Use specialized finance model for financial analysis
model = WriterModel(
client_args={"api_key": "<WRITER_API_KEY>"},
model_id="palmyra-fin"
)
agent = Agent(
model=model,
system_prompt="You are a financial analyst assistant. Provide accurate, data-driven analysis."
)
# Replace the placeholder with your actual financial report content
actual_report = """
[Your quarterly earnings report content would go here - this could include:
- Revenue figures
- Profit margins
- Growth metrics
- Risk factors
- Market analysis
- Any other financial data you want analyzed]
"""
response = agent(f"Analyze the key financial risks in this quarterly earnings report: {actual_report}")
Long-context document processing
from strands import Agent
from strands.models.writer import WriterModel
# Use Palmyra X5 for processing very long documents
model = WriterModel(
client_args={"api_key": "<WRITER_API_KEY>"},
model_id="palmyra-x5",
temperature=0.2
)
agent = Agent(
model=model,
system_prompt="You are a document analysis assistant that can process and summarize lengthy documents."
)
# Can handle documents up to 1M tokens
# Replace the placeholder with your actual document content
actual_transcripts = """
[Meeting transcript content would go here - this could be thousands of lines of text
from meeting recordings, documents, or other long-form content that you want to analyze]
"""
response = agent(f"Summarize the key decisions and action items from these meeting transcripts: {actual_transcripts}")
Structured output generation
Palmyra X5 and X4 support structured output generation using Pydantic models. This is useful for ensuring consistent, validated responses.
Structured output disables streaming and returns the complete response at once, unlike regular chat completions, which stream by default. See Callback Handlers for more details.
from strands import Agent
from strands.models.writer import WriterModel
from pydantic import BaseModel
from typing import List
# Define a structured schema for creative content
class MarketingCampaign(BaseModel):
campaign_name: str
target_audience: str
key_messages: List[str]
call_to_action: str
tone: str
estimated_engagement: float
# Use Palmyra X5 for creative marketing content
model = WriterModel(
client_args={"api_key": "<WRITER_API_KEY>"},
model_id="palmyra-x5",
temperature=0.8 # Higher temperature for creative output
)
agent = Agent(
model=model,
system_prompt="You are a creative marketing strategist. Generate innovative marketing campaigns with structured data."
)
# Generate structured marketing campaign
response = agent.structured_output(
output_model=MarketingCampaign,
prompt="Create a marketing campaign for a new eco-friendly water bottle targeting young professionals aged 25-35."
)
print(f"Campaign Name: {response.campaign_name}\nTarget Audience: {response.target_audience}\nKey Messages: {response.key_messages}\nCall to Action: {response.call_to_action}\nTone: {response.tone}\nEstimated Engagement: {response.estimated_engagement}")
Vision and image analysis
Palmyra X5 supports vision capabilities, allowing you to analyze images and extract information from visual content.
from strands import Agent
from strands.models.writer import WriterModel
# Use Palmyra X5 for vision tasks
model = WriterModel(
client_args={"api_key": "<WRITER_API_KEY>"},
model_id="palmyra-x5"
)
agent = Agent(
model=model,
system_prompt="You are a visual analysis assistant. Provide detailed, accurate descriptions of images and extract relevant information."
)
# Read the image file
with open("path/to/image.png", "rb") as image_file:
image_data = image_file.read()
messages = [
{
"role": "user",
"content": [
{
"image": {
"format": "png",
"source": {
"bytes": image_data
}
}
},
{
"text": "Analyze this image and describe what you see. What are the key elements, colors, and any text or objects visible?"
}
]
}
]
# Create an agent with the image message
vision_agent = Agent(model=model, messages=messages)
# Analyze the image
response = vision_agent("What are the main features of this image and what might it be used for?")
print(response)
Additional resources
See more information and examples below:
Responses are generated using AI and may contain mistakes.