Prerequisites
Before you begin, make sure you have:- Python 3.10 or higher installed
- A Writer AI Studio account
- A Writer API key. See instructions in the API Quickstart
- Basic familiarity with Python and AWS Strands
Installation
To use Writer models with Strands Agents, install the optional Writer dependency: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: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 viaclient_args
:
Model configuration
TheWriterModel
accepts configuration parameters as keyword arguments to the model constructor:
Parameter | Type | Description | Default | Options |
---|---|---|---|---|
model_id | str | Model name to use (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 don’t specify this, accumulated_usage 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 |
Environment variables
You can set your Writer API key as an environment variable instead of passing it directly:client_args["api_key"]
parameter:
Examples
Enterprise workflow automation
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
Long-context document processing
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.