Skip to content

v1.16.0

Latest

Choose a tag to compare

@zastrowm zastrowm released this 12 Nov 21:06
· 4 commits to main since this release
8cae18c

Major Features

Async Hooks Support - PR#1119

Hooks now support asynchronous callbacks, allowing your hook code to run concurrently with other async tasks without blocking the event loop. This is particularly beneficial for async agent invocations and scenarios where hooks perform I/O operations.

import asyncio
from strands import Agent
from strands.hooks import BeforeInvocationEvent, HookProvider, HookRegistry

class AsyncHook(HookProvider):
    def register_hooks(self, registry: HookRegistry, **kwargs) -> None:
        registry.add_callback(BeforeInvocationEvent, self.async_callback)

    async def async_callback(self, event: BeforeInvocationEvent) -> None:
        # Perform async operations without blocking the event loop
        await asyncio.sleep(1)
        print("Hook executed asynchronously!")

agent = Agent(hooks=[AsyncHook()])
await agent.invoke_async("Hello!")

Thread Context Sharing - PR#1146

Context variables (contextvars) are now automatically copied from the main thread to agent threads when using synchronous invocations. This ensures that context-dependent tools and hooks work correctly.

from contextvars import ContextVar
from strands import Agent, tool

request_id = ContextVar('request_id')

@tool
def my_tool():
    # Context variables are now accessible within tools
    current_request_id = request_id.get()
    return f"Processing request: {current_request_id}"

request_id.set("abc-123")
agent = Agent(tools=[my_tool])
response = agent.invoke_async("Use my tool")  # Context is properly propagated

Enhanced Telemetry with Tool Definitions - PR#1113

Tool definitions are now included in OpenTelemetry traces via semantic convention opt-in, providing better observability into agent tool usage, following the OpenTelemetry semantic conventions for GenAI.

Opt-in via environment variable:

OTEL_SEMCONV_STABILITY_OPT_IN=gen_ai_tool_definitions
from strands import Agent, tool
from strands_tools import calculator

# Tool definition will appear in telemetry traces
agent = Agent(tools=[calculator])
agent("What is 5 + 3?")

String Descriptions in Annotated Tool Parameters - PR#1089

You can now use simple string descriptions directly in Annotated type hints for tool parameters, improving code readability and reducing boilerplate.

from typing import Annotated
from strands import tool

@tool
def get_weather(
    location: Annotated[str, "The city and state, e.g., San Francisco, CA"],
    units: Annotated[str, "Temperature units: 'celsius' or 'fahrenheit'"] = "celsius"
):
    """Get weather for a location."""
    return f"Weather in {location}: 72°{units[0].upper()}"

# Previously required more verbose Field() syntax or using a doc-string

Major Bug Fixes

  • Anthropic "Prompt Too Long" Error Handling - PR#1137
    The SDK now properly handles and surfaces Anthropic's "prompt is too long" errors, making it easier to diagnose and fix context window issues.
  • MCP Server 5xx Error Resilience - PR#1169
    The SDK no longer hangs when Model Context Protocol (MCP) servers return 5xx errors, improving reliability when working with external services.
  • Gemini Non-JSON Error Message Handling - PR#1062
    The Gemini model provider now gracefully handles non-JSON error responses, preventing unexpected crashes.

All changes

  • fix(models/gemini): handle non-JSON error messages from Gemini API by @Ratish1 in #1062
  • fix: Handle "prompt is too long" from Anthropic by @zastrowm in #1137
  • feat(telemetry): Add tool definitions to traces via semconv opt-in by @Ratish1 in #1113
  • fix: Strip argument sections out of inputSpec top-level description by @zastrowm in #1142
  • share thread context by @pgrayy in #1146
  • async hooks by @pgrayy in #1119
  • feat(tools): Support string descriptions in Annotated parameters by @Ratish1 in #1089
  • chore(telemetry): updated opt-in attributes to internal by @poshinchen in #1152
  • feat(models): allow SystemContentBlocks in LiteLLMModel by @dbschmigelski in #1141
  • share interrupt state by @pgrayy in #1148
  • fix: Don't hang when MCP server returns 5xx by @zastrowm in #1169
  • fix(models): allow setter on system_prompt and system_prompt_content by @dbschmigelski in #1171

Full Changelog: v1.15.0...v1.16.0