{"id":3031,"library":"mypy-boto3-bedrock-agent-runtime","title":"Mypy Boto3 Bedrock Agent Runtime Stubs","description":"This library provides PEP 561 type annotations for the `boto3` Bedrock Agent Runtime service. It allows static type checkers like Mypy to validate usage of `boto3.client('bedrock-agent-runtime')`, improving code reliability and developer experience. The current version is 1.42.3 and new versions are released frequently, typically mirroring `boto3` releases and the `mypy-boto3-builder`'s update cadence.","status":"active","version":"1.42.3","language":"en","source_language":"en","source_url":"https://github.com/youtype/mypy_boto3_builder","tags":["aws","boto3","type-hints","mypy","bedrock","agent-runtime"],"install":[{"cmd":"pip install boto3 mypy-boto3-bedrock-agent-runtime","lang":"bash","label":"Install with boto3"}],"dependencies":[{"reason":"This package provides type hints for boto3, which is the actual AWS SDK for Python. Boto3 must be installed to use the Bedrock Agent Runtime service at runtime.","package":"boto3","optional":false},{"reason":"Mypy is the most common static type checker used with these stubs. It is required to leverage the type annotations.","package":"mypy","optional":true},{"reason":"Required for some type features on older Python versions (<3.9) by mypy-boto3-builder.","package":"typing-extensions","optional":true}],"imports":[{"symbol":"BedrockAgentRuntimeClient","correct":"from mypy_boto3_bedrock_agent_runtime.client import BedrockAgentRuntimeClient"},{"note":"Since `mypy-boto3-builder` 8.9.0, TypeDefs that conflict with method names (e.g., `InvokeAgent`) are renamed with suffixes like `RequestRequestTypeDef` or `RequestExtraTypeDef` to ensure unique names.","wrong":"from mypy_boto3_bedrock_agent_runtime.type_defs import InvokeAgentRequestTypeDef","symbol":"InvokeAgentRequestRequestTypeDef","correct":"from mypy_boto3_bedrock_agent_runtime.type_defs import InvokeAgentRequestRequestTypeDef"}],"quickstart":{"code":"import boto3\nfrom typing import TYPE_CHECKING, Dict, Any\nimport os\n\n# These are for type checking only, not actual runtime imports\nif TYPE_CHECKING:\n    from mypy_boto3_bedrock_agent_runtime.client import BedrockAgentRuntimeClient\n    from mypy_boto3_bedrock_agent_runtime.type_defs import InvokeAgentRequestRequestTypeDef, InvokeAgentResponseTypeDef\n\ndef get_bedrock_agent_runtime_client() -> \"BedrockAgentRuntimeClient\":\n    \"\"\"\n    Returns a type-hinted Bedrock Agent Runtime client.\n    \"\"\"\n    # In a real application, consider using environment variables or a config file\n    # for region and credentials.\n    # For this example, we'll assume region is set via AWS_DEFAULT_REGION or similar.\n    return boto3.client(\"bedrock-agent-runtime\")\n\ndef invoke_agent_example():\n    client: BedrockAgentRuntimeClient = get_bedrock_agent_runtime_client()\n\n    # Replace with your actual Agent ID and Alias ID\n    # It's recommended to set these as environment variables (e.g., BEDROCK_AGENT_ID)\n    agent_id = os.environ.get(\"BEDROCK_AGENT_ID\", \"YOUR_AGENT_ID\")\n    agent_alias_id = os.environ.get(\"BEDROCK_AGENT_ALIAS_ID\", \"YOUR_AGENT_ALIAS_ID\")\n    session_id = \"test-session-123\" # A unique identifier for the session\n    input_text = \"What is the weather like in Seattle?\"\n\n    if agent_id == \"YOUR_AGENT_ID\" or agent_alias_id == \"YOUR_AGENT_ALIAS_ID\":\n        print(\"Please set BEDROCK_AGENT_ID and BEDROCK_AGENT_ALIAS_ID environment variables to run this example.\")\n        print(\"You can find these in the AWS Bedrock Agents console.\")\n        return\n\n    request_params: InvokeAgentRequestRequestTypeDef = {\n        \"agentId\": agent_id,\n        \"agentAliasId\": agent_alias_id,\n        \"sessionId\": session_id,\n        \"inputText\": input_text,\n        \"enableTrace\": True, # Set to False for production to reduce logging\n    }\n\n    print(f\"Invoking agent with input: '{input_text}'\")\n    try:\n        response: InvokeAgentResponseTypeDef = client.invoke_agent(**request_params)\n\n        # Process the response stream\n        response_body = response.get(\"completion\")\n        if response_body:\n            print(\"Agent response:\")\n            for event in response_body:\n                if \"chunk\" in event:\n                    chunk = event[\"chunk\"]\n                    text = chunk.get(\"bytes\").decode(\"utf-8\")\n                    print(f\"  {text}\", end=\"\")\n            print(\"\\n\") # Newline after all chunks\n        else:\n            print(\"No completion received.\")\n\n    except client.exceptions.ResourceNotFoundException as e:\n        print(f\"Error: Agent or Alias not found. Ensure 'BEDROCK_AGENT_ID' and 'BEDROCK_AGENT_ALIAS_ID' are correct. {e}\")\n    except client.exceptions.ValidationException as e:\n        print(f\"Validation Error: {e}\")\n    except Exception as e:\n        print(f\"An unexpected error occurred: {e}\")\n\nif __name__ == \"__main__\":\n    invoke_agent_example()\n","lang":"python","description":"This quickstart demonstrates how to use the `mypy-boto3-bedrock-agent-runtime` stubs to type-hint your `boto3` Bedrock Agent Runtime client. It shows how to retrieve a type-hinted client, prepare an `InvokeAgent` request with `TypeDef` annotations, and process the streaming response from an AWS Bedrock Agent. Make sure `boto3` is installed and configure your AWS credentials and region."},"warnings":[{"fix":"Upgrade your Python environment to version 3.9 or higher.","message":"Python 3.8 is no longer supported. Packages built with `mypy-boto3-builder` version 8.12.0 and later (including `mypy-boto3-bedrock-agent-runtime` versions 1.42.3+) explicitly dropped support for Python 3.8.","severity":"breaking","affected_versions":"mypy-boto3-builder >= 8.12.0 (and dependent mypy-boto3-* packages)"},{"fix":"Review your `TypeDef` imports after upgrading `mypy-boto3-builder` or the specific service stub. Consult the latest generated stub files for the exact type definitions (e.g., in `mypy_boto3_bedrock_agent_runtime.type_defs.pyi`).","message":"TypeDef names might have changed to avoid conflicts. For example, `CreateDistributionRequestTypeDef` might become `CreateDistributionRequestRequestTypeDef` if a method with the same name exists.","severity":"breaking","affected_versions":"mypy-boto3-builder >= 8.9.0 (and dependent mypy-boto3-* packages)"},{"fix":"Ensure `boto3` is installed alongside `mypy-boto3-bedrock-agent-runtime` (e.g., `pip install boto3 mypy-boto3-bedrock-agent-runtime`).","message":"This library provides only type annotations, not the actual `boto3` implementation. You must install `boto3` separately for your code to run.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Keep `mypy-boto3-*` packages updated with your `boto3` version. If `boto3` is updated, ensure `mypy-boto3-*` is also updated to the corresponding version.","message":"For optimal type checking, the `mypy-boto3-*` stub package version should closely match your installed `boto3` version. Significant version discrepancies can lead to incorrect type errors or missed valid types.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}