github strands-agents/sdk-python v1.22.0

9 hours ago

Major Features

MCP Resource Operations - PR#1117

The MCP client now supports resource operations, enabling agents to list, read, and work with resources provided by MCP servers. This includes static resources, binary resources, and parameterized resource templates.

from strands.tools.mcp import MCPClient

with MCPClient(server_transport) as client:
    # List available resources
    resources = client.list_resources_sync()
    for resource in resources.resources:
        print(f"Resource: {resource.name} at {resource.uri}")
    
    # Read a specific resource
    content = client.read_resource_sync("file://documents/report.txt")
    text = content.contents[0].text
    
    # List resource templates (parameterized resources)
    templates = client.list_resource_templates_sync()
    for template in templates.resourceTemplates:
        print(f"Template: {template.uriTemplate}")

Bedrock Guardrails Latest Message Option - PR#1224

Bedrock models now support the guardrail_latest_message parameter, which sends only the latest user message to AWS Bedrock Guardrails for evaluation instead of the entire conversation history. This reduces token usage and enables conversation recovery after guardrail interventions.

from strands.models.bedrock import BedrockModel

model = BedrockModel(
    model_id="us.anthropic.claude-sonnet-4-20250514-v1:0",
    guardrail_id="your-guardrail-id",
    guardrail_version="DRAFT",
    guardrail_latest_message=True  # Only evaluate the latest user message
)

See the Bedrock Guardrails documentation for more details.

LiteLLM Non-Streaming Support - PR#512

The LiteLLM model provider now correctly handles non-streaming responses, fixing an issue where stream=False would raise an error. Both streaming and non-streaming modes now work seamlessly.

from strands.models.litellm import LiteLLMModel

# Use non-streaming mode for simpler response handling
model = LiteLLMModel(
    model_id="gpt-3.5-turbo",
    params={"stream": False}
)

# Works correctly now - no more ValueError
agent = Agent(model=model)
result = agent("What is 2+2?")

Major Bug Fixes

  • Concurrent Agent Invocations - PR#1453
    Fixed critical agent state corruption when multiple concurrent invocations occurred on the same agent instance. A new ConcurrencyException is now raised to prevent concurrent invocations and protect agent state integrity.

  • Gemini Empty Stream Handling - PR#1420
    Fixed UnboundLocalError crash when Gemini returns an empty event stream by properly initializing variables before the stream loop.

  • Deprecation Warning on Import - PR#1380
    Fixed unwanted deprecation warnings appearing when importing strands by using lazy __getattr__ to emit warnings only when deprecated aliases are actually accessed.


What's Changed

  • docs: update github agent action to reference S3_SESSION_BUCKET by @dbschmigelski in #1418
  • feat: provide extra command content as the the prompt to the agent by @zastrowm in #1419
  • [FEATURE] add MCP resource operations in MCP Tools by @xiehust in #1117
  • fix: import errors for models with optional imports by @mehtarac in #1384
  • add BidiGeminiLiveModel and BidiOpenAIRealtimeModel to the init by @mehtarac in #1383
  • bidi - async - remove cancelling call by @pgrayy in #1357
  • feat(bedrock): add guardrail_latest_message option by @aiancheruk in #1224
  • fix(gemini): UnboundLocal Exception Fix by @emattiza in #1420
  • fix! Litellm handle non streaming response fix for issue #477 by @schleidl in #512
  • feat(agent-interface): introduce AgentBase Protocol as the interface for agent classes to implement by @awsarron in #1126
  • ci: update pytest requirement from <9.0.0,>=8.0.0 to >=8.0.0,<10.0.0 in the dev-dependencies group by @dependabot[bot] in #1161
  • feat: pass invocation_state to model providers by @tirth14 in #1414
  • Add Security.md file by @yonib05 in #1454
  • chore: Update release notes sop by @zastrowm in #1456
  • fix(integ): make calculator tool more robust to LLM output variations by @cagataycali in #1445
  • fix: resolve string formatting error in MCP client error handling by @cagataycali in #1446
  • bidi - move 3.12 check to nova sonic module by @pgrayy in #1439
  • ci: update sphinx requirement from <9.0.0,>=5.0.0 to >=5.0.0,<10.0.0 by @dependabot[bot] in #1426
  • fix: add concurrency protection to prevent parallel invocations from corrupting agent state by @zastrowm in #1453
  • fix(mcp): propagate contextvars to background thread by @cagataycali in #1444
  • Update to opus 4.5 by @Unshure in #1471

New Contributors

Full Changelog: v1.21.0...v1.22.0

Don't miss a new sdk-python release

NewReleases is sending notifications on new releases.