github anthropics/anthropic-sdk-python v2.16.0

one hour ago

Features

  • api: add support for Claude Managed Agents on Amazon Bedrock

  • api: add the storage_not_ready error code

  • tools: add max_concurrent_calls to the session tool runner and the environment worker

    With a value above 1, or None for no limit, the calls of different session threads run concurrently. Calls still run one at a time by default.

Bug Fixes

  • environments: claim a work item before serving it and do not stop items whose lease was lost

    • The poller's auto_stop now sends a force stop.
    • handle_item() logs a failure instead of raising it if the lease was lost. It raises errors as they are, not in an ExceptionGroup.
    • Memory files are also uploaded when the session goes idle, and the skills of subagents are downloaded too. Of two skills with one name, the first is kept (was the last).
  • tools: kill what the bash tool's shell started, and save long output to a file

    • A timeout or a cancellation kills the shell and its background jobs. Once a shell has ended, bash refuses calls until one passes restart.
    • A command may run for 295 seconds (was 120). Output is stdout and then stderr (stderr first for a failed command), cut after 30,000 characters (was the last 100 KiB), with the path of a file that has the rest.
    • read asks for a view_range above 110,000 bytes (was 256 KiB).
    • Use BashSession.start(), because BashSession() takes other arguments.
  • tools: run only the session tool calls that the session is waiting on

    • A running async tool is cancelled when the session no longer accepts its result or the runner stops. The tool timeout is 325 seconds (was 150).
    • bash keeps one shell for each session thread.
    • A permanent API error from reading the session, such as the 404 for a deleted session, is raised.
    • Async tools must shield what they await to clean up (anyio.CancelScope(shield=True)), and run blocking work with anyio.to_thread.run_sync, which is awaited on a cancel.
  • tools: wait at most 150 seconds for a cancelled tool when the session tool runner stops

Performance Improvements

  • streaming: construct stream events directly instead of reflectively

  • structured outputs: generate a model's JSON schema once in transform_schema()

    A model whose JSON schema changes after it is first passed to transform_schema() keeps its first schema, as it already does with parse() and stream(). Pass Model.model_json_schema() instead to generate the schema on every call.

Don't miss a new anthropic-sdk-python release

NewReleases is sending notifications on new releases.