Evaluate Strands Agents with Promptfoo
Promptfoo example evaluating a Strands Agents SDK weather agent with tool-usage and rubric-based assertions.
code-scan-action-0.1Add to Favorites
Why it matters
This asset allows developers to evaluate the performance and reliability of Strands Agents SDK integrations using the promptfoo evaluation framework. It streamlines the process of testing agent behavior and code generation capabilities.
Outcomes
What it gets done
Integrate Strands Agents SDK with promptfoo for automated testing.
Evaluate agent performance on code generation tasks.
Debug and refine agent logic based on evaluation results.
Benchmark different agent configurations.
Install
Add it to your toolbox
Run in your project directory:
curl -fsSL https://spark.entire.vc/get/pfoo-integration-strands-agents | bash Steps
Steps in the chain
Overview
Integration Strands Agents
A promptfoo example running a Strands Agents SDK weather agent through promptfoo's Python provider, tested with tool-usage, chaining, fallback, and llm-rubric assertions. Use when your agent is built on the Strands Agents SDK and you need a starting template for evaluating its tool usage and multi-tool chaining.
What it does
This example demonstrates how to evaluate the Strands Agents SDK with promptfoo. Strands Agents is an open-source, model-driven AI agent framework developed by AWS. The example builds a Strands agent with two custom tools defined via the @tool decorator - get_weather (returns mock weather data for New York, London, Tokyo, Paris, Seattle, and San Francisco) and convert_temperature (converts between Fahrenheit and Celsius) - and exercises it through promptfoo's assertion system.
When to use - and when NOT to
Use this example when your agent is built on the Strands Agents SDK and you want to verify its tool usage, multi-tool chaining, and graceful handling of edge cases (like unknown cities) through promptfoo assertions. It is not a general Strands tutorial; it documents specifically how to wire a Strands agent into promptfoo's Python provider and test it with a representative assertion mix.
Inputs and outputs
Requires Python 3.9+ and an OpenAI API key by default (or another supported provider). Install dependencies with pip install -r requirements.txt, which pulls in strands-agents[openai] (the Strands SDK with OpenAI support) and pydantic (data validation required by Strands), then set OPENAI_API_KEY. To use Anthropic instead, install strands-agents[anthropic], set ANTHROPIC_API_KEY, and modify agent.py to use AnthropicModel instead of OpenAIModel; Amazon Bedrock is supported via strands-agents[bedrock]. Scaffold and run:
npx promptfoo@latest init --example integration-strands-agents
cd integration-strands-agents
Then npx promptfoo eval to run the evaluation and npx promptfoo view to see results in the web UI. The agent lives in agent.py, and agent_provider.py exposes a call_api function that promptfoo's Python provider calls to interact with it. The config includes 5 test cases: a basic weather query for New York (contains-any, llm-rubric, latency), a London query verifying temperature format (contains-any, javascript, latency), a case-insensitive Tokyo query (icontains, javascript, latency), a multi-tool weather-plus-conversion chain (llm-rubric, javascript, latency), and an unknown-city fallback test (icontains, not-contains, latency).
Integrations
Integrates the Strands Agents SDK (AWS's model-driven agent framework, with OpenAI, Anthropic, or Amazon Bedrock as the underlying model provider) with promptfoo's Python provider interface. Assertion types used: latency (applied to every test via defaultTest, enforcing a 30-second response ceiling), contains-any (verifies expected city names/weather data from the mock tool appear), icontains (case-insensitive city-name matching), not-contains (confirms unknown cities are handled without error messages), javascript (validates temperature-symbol formatting and response length), and llm-rubric (semantically checks that the agent correctly chains weather lookup with temperature conversion).
Who it's for
Teams building agents on the Strands Agents SDK who want a representative promptfoo assertion suite - tool-usage checks, multi-tool chaining, graceful fallback, and rubric-graded semantic correctness - as a starting template for their own agent evals.
Source README
integration-strands-agents (Strands Agents SDK example)
This example demonstrates how to evaluate Strands Agents SDK with promptfoo.
Strands Agents is an open-source AI agent framework developed by AWS that provides a model-driven approach to building AI agents.
You can run this example with:
npx promptfoo@latest init --example integration-strands-agents
cd integration-strands-agents
Overview
This example showcases:
- Creating a Strands agent with custom tools
- Using the
@tooldecorator to define agent capabilities - Evaluating agent responses with various promptfoo assertions
- Testing tool usage with mock weather and temperature conversion tools
Prerequisites
- Python 3.9+
- OpenAI API key (default) or other supported provider
Setup
1. Install Python dependencies
pip install -r requirements.txt
This installs:
strands-agents[openai]- The Strands Agents SDK with OpenAI supportpydantic- Data validation library required by Strands
2. Set environment variables
export OPENAI_API_KEY=your-api-key-here
Alternative: use Anthropic or Bedrock
Strands supports multiple model providers. To use Anthropic:
pip install 'strands-agents[anthropic]'
export ANTHROPIC_API_KEY=your-key
Then modify agent.py to use AnthropicModel instead of OpenAIModel.
To use Amazon Bedrock:
pip install 'strands-agents[bedrock]'
Running the example
### Run evaluation
npx promptfoo eval
### View results in the web UI
npx promptfoo view
How it works
Agent structure
The agent is defined in agent.py using the Strands Agent class with two tools:
get_weather: Returns mock weather data for cities (New York, London, Tokyo, Paris, Seattle, San Francisco)convert_temperature: Converts temperatures between Fahrenheit and Celsius
Tools are defined using the @tool decorator which automatically exposes them to the LLM based on their docstrings.
Provider integration
agent_provider.py exposes a call_api function that promptfoo's Python provider calls to interact with the Strands agent.
Test cases and assertion types
The promptfoo config includes 5 test cases that demonstrate different assertion types:
| Test | Description | Assertion types used |
|---|---|---|
| Weather query for New York | Basic tool usage | contains-any, llm-rubric, latency |
| Weather query for London | Verify temperature format | contains-any, javascript, latency |
| Weather query for Tokyo | Case-insensitive matching | icontains, javascript, latency |
| Weather with temperature conversion | Multi-tool chaining | llm-rubric, javascript, latency |
| Weather for unknown city | Graceful fallback handling | icontains, not-contains, latency |
Assertion types explained
latency- Ensures responses complete within 30 seconds (applied to all tests viadefaultTest)contains-any- Verifies the agent returns expected city names and weather data from the mock toolicontains- Case-insensitive matching to verify city names appear regardless of formattingnot-contains- Ensures the agent handles unknown cities gracefully without error messagesjavascript- Validates temperature format (°F/°C symbols) and response length requirementsllm-rubric- Semantically evaluates whether the agent correctly chains weather lookup with temperature conversion
FAQ
Common questions
Discussion
Questions & comments · 0
Sign In Sign in to leave a comment.