chore: import upstream snapshot with attribution
dotnet-build-and-test / dotnet-test-functions (push) Has been cancelled
dotnet-build-and-test / paths-filter (push) Has been cancelled
dotnet-build-and-test / dotnet-build (Debug, windows-latest, net9.0) (push) Has been cancelled
dotnet-build-and-test / dotnet-build (Release, ubuntu-latest, net10.0) (push) Has been cancelled
dotnet-build-and-test / dotnet-build (Release, ubuntu-latest, net8.0) (push) Has been cancelled
dotnet-build-and-test / dotnet-build (Release, windows-latest, net472) (push) Has been cancelled
dotnet-build-and-test / dotnet-test (Release, integration, true, ubuntu-latest, net10.0) (push) Has been cancelled
dotnet-build-and-test / dotnet-test (Release, integration, true, windows-latest, net472) (push) Has been cancelled
dotnet-build-and-test / dotnet-foundry-hosted-it (push) Has been cancelled
dotnet-build-and-test / dotnet-build-and-test-check (push) Has been cancelled
dotnet-build-and-test / Integration Test Report (push) Has been cancelled
CodeQL / Analyze (csharp) (push) Has been cancelled
CodeQL / Analyze (python) (push) Has been cancelled

This commit is contained in:
wehub-resource-sync
2026-07-13 13:39:25 +08:00
commit db620d33df
5151 changed files with 925932 additions and 0 deletions
@@ -0,0 +1,30 @@
# Copyright (c) Microsoft. All rights reserved.
import importlib.metadata
from ._bedrock_client import AnthropicBedrockClient, RawAnthropicBedrockClient
from ._chat_client import (
AnthropicChatOptions,
AnthropicClient,
RawAnthropicClient,
)
from ._foundry_client import AnthropicFoundryClient, RawAnthropicFoundryClient
from ._vertex_client import AnthropicVertexClient, RawAnthropicVertexClient
try:
__version__ = importlib.metadata.version(__name__)
except importlib.metadata.PackageNotFoundError:
__version__ = "0.0.0" # Fallback for development mode
__all__ = [
"AnthropicBedrockClient",
"AnthropicChatOptions",
"AnthropicClient",
"AnthropicFoundryClient",
"AnthropicVertexClient",
"RawAnthropicBedrockClient",
"RawAnthropicClient",
"RawAnthropicFoundryClient",
"RawAnthropicVertexClient",
"__version__",
]
@@ -0,0 +1,168 @@
# Copyright (c) Microsoft. All rights reserved.
from __future__ import annotations
from collections.abc import Sequence
from typing import Any, ClassVar, Generic, TypedDict
from agent_framework import (
ChatAndFunctionMiddlewareTypes,
ChatMiddlewareLayer,
FunctionInvocationConfiguration,
FunctionInvocationLayer,
)
from agent_framework._settings import SecretString, load_settings
from agent_framework._telemetry import get_user_agent
from agent_framework.observability import ChatTelemetryLayer
from anthropic.lib.bedrock import AsyncAnthropicBedrock
from ._chat_client import AnthropicOptionsT, RawAnthropicClient
class AnthropicBedrockSettings(TypedDict, total=False):
"""Resolved settings for Anthropic Bedrock wrappers."""
aws_access_key_id: SecretString | None
aws_secret_access_key: SecretString | None
aws_region: str | None
aws_profile: str | None
aws_session_token: SecretString | None
anthropic_bedrock_base_url: str | None
anthropic_chat_model: str | None
class RawAnthropicBedrockClient(RawAnthropicClient[AnthropicOptionsT], Generic[AnthropicOptionsT]):
"""Raw Anthropic Bedrock chat client without middleware, telemetry, or function invocation support."""
OTEL_PROVIDER_NAME: ClassVar[str] = "aws.bedrock"
def __init__(
self,
*,
model: str | None = None,
aws_secret_key: str | None = None,
aws_access_key: str | None = None,
aws_region: str | None = None,
aws_profile: str | None = None,
aws_session_token: str | None = None,
base_url: str | None = None,
anthropic_client: AsyncAnthropicBedrock | None = None,
additional_beta_flags: list[str] | None = None,
additional_properties: dict[str, Any] | None = None,
env_file_path: str | None = None,
env_file_encoding: str | None = None,
) -> None:
"""Initialize a raw Anthropic Bedrock client.
Keyword Args:
model: The Anthropic model to use.
aws_secret_key: AWS secret access key.
aws_access_key: AWS access key ID.
aws_region: AWS region.
aws_profile: AWS profile name.
aws_session_token: AWS session token.
base_url: Optional custom Anthropic Bedrock base URL.
anthropic_client: Existing AsyncAnthropicBedrock client to reuse.
additional_beta_flags: Additional beta flags to enable on the client.
additional_properties: Additional properties stored on the client instance.
env_file_path: Path to environment file for loading settings.
env_file_encoding: Encoding of the environment file.
"""
settings = load_settings(
AnthropicBedrockSettings,
env_prefix="",
aws_access_key_id=aws_access_key,
aws_secret_access_key=aws_secret_key,
aws_region=aws_region,
aws_profile=aws_profile,
aws_session_token=aws_session_token,
anthropic_bedrock_base_url=base_url,
anthropic_chat_model=model,
env_file_path=env_file_path,
env_file_encoding=env_file_encoding,
)
model_setting = settings.get("anthropic_chat_model")
access_key_secret = settings.get("aws_access_key_id")
secret_key_secret = settings.get("aws_secret_access_key")
session_token_secret = settings.get("aws_session_token")
if anthropic_client is None:
anthropic_client = AsyncAnthropicBedrock(
aws_secret_key=secret_key_secret.get_secret_value() if secret_key_secret is not None else None,
aws_access_key=access_key_secret.get_secret_value() if access_key_secret is not None else None,
aws_region=settings.get("aws_region"),
aws_profile=settings.get("aws_profile"),
aws_session_token=session_token_secret.get_secret_value() if session_token_secret is not None else None,
base_url=settings.get("anthropic_bedrock_base_url"),
default_headers={"User-Agent": get_user_agent()},
)
super().__init__(
model=model_setting,
anthropic_client=anthropic_client,
additional_beta_flags=additional_beta_flags,
additional_properties=additional_properties,
)
class AnthropicBedrockClient(
FunctionInvocationLayer[AnthropicOptionsT],
ChatMiddlewareLayer[AnthropicOptionsT],
ChatTelemetryLayer[AnthropicOptionsT],
RawAnthropicBedrockClient[AnthropicOptionsT],
Generic[AnthropicOptionsT],
):
"""Anthropic Bedrock chat client with middleware, telemetry, and function invocation support."""
def __init__(
self,
*,
model: str | None = None,
aws_secret_key: str | None = None,
aws_access_key: str | None = None,
aws_region: str | None = None,
aws_profile: str | None = None,
aws_session_token: str | None = None,
base_url: str | None = None,
anthropic_client: AsyncAnthropicBedrock | None = None,
additional_beta_flags: list[str] | None = None,
additional_properties: dict[str, Any] | None = None,
middleware: Sequence[ChatAndFunctionMiddlewareTypes] | None = None,
function_invocation_configuration: FunctionInvocationConfiguration | None = None,
env_file_path: str | None = None,
env_file_encoding: str | None = None,
) -> None:
"""Initialize an Anthropic Bedrock client.
Keyword Args:
model: The Anthropic model to use.
aws_secret_key: AWS secret access key.
aws_access_key: AWS access key ID.
aws_region: AWS region.
aws_profile: AWS profile name.
aws_session_token: AWS session token.
base_url: Optional custom Anthropic Bedrock base URL.
anthropic_client: Existing AsyncAnthropicBedrock client to reuse.
additional_beta_flags: Additional beta flags to enable on the client.
additional_properties: Additional properties stored on the client instance.
middleware: Optional middleware to apply to the client.
function_invocation_configuration: Optional function invocation configuration override.
env_file_path: Path to environment file for loading settings.
env_file_encoding: Encoding of the environment file.
"""
super().__init__(
model=model,
aws_secret_key=aws_secret_key,
aws_access_key=aws_access_key,
aws_region=aws_region,
aws_profile=aws_profile,
aws_session_token=aws_session_token,
base_url=base_url,
anthropic_client=anthropic_client,
additional_beta_flags=additional_beta_flags,
additional_properties=additional_properties,
middleware=middleware,
function_invocation_configuration=function_invocation_configuration,
env_file_path=env_file_path,
env_file_encoding=env_file_encoding,
)
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,166 @@
# Copyright (c) Microsoft. All rights reserved.
from __future__ import annotations
from collections.abc import Awaitable, Callable, Sequence
from typing import Any, ClassVar, Generic, TypedDict
from agent_framework import (
ChatAndFunctionMiddlewareTypes,
ChatMiddlewareLayer,
FunctionInvocationConfiguration,
FunctionInvocationLayer,
)
from agent_framework._settings import SecretString, load_settings
from agent_framework._telemetry import get_user_agent
from agent_framework.observability import ChatTelemetryLayer
from anthropic import AsyncAnthropicFoundry
from ._chat_client import AnthropicOptionsT, RawAnthropicClient
AnthropicFoundryAzureADTokenProvider = Callable[[], str | Awaitable[str]]
class AnthropicFoundrySettings(TypedDict, total=False):
"""Resolved settings for Anthropic Foundry wrappers."""
anthropic_foundry_api_key: SecretString | None
anthropic_foundry_resource: str | None
anthropic_foundry_base_url: str | None
anthropic_chat_model: str | None
class RawAnthropicFoundryClient(RawAnthropicClient[AnthropicOptionsT], Generic[AnthropicOptionsT]):
"""Raw Anthropic Foundry chat client without middleware, telemetry, or function invocation support."""
OTEL_PROVIDER_NAME: ClassVar[str] = "azure.ai.foundry"
def __init__(
self,
*,
model: str | None = None,
resource: str | None = None,
api_key: str | None = None,
azure_ad_token_provider: AnthropicFoundryAzureADTokenProvider | None = None,
base_url: str | None = None,
anthropic_client: AsyncAnthropicFoundry | None = None,
additional_beta_flags: list[str] | None = None,
additional_properties: dict[str, Any] | None = None,
env_file_path: str | None = None,
env_file_encoding: str | None = None,
) -> None:
"""Initialize a raw Anthropic Foundry client.
Keyword Args:
model: The Anthropic model to use.
resource: The Foundry resource name.
api_key: The Foundry Anthropic API key.
azure_ad_token_provider: Azure AD token provider used by the Anthropic SDK.
base_url: Full Anthropic-compatible Foundry base URL.
anthropic_client: Existing AsyncAnthropicFoundry client to reuse.
additional_beta_flags: Additional beta flags to enable on the client.
additional_properties: Additional properties stored on the client instance.
env_file_path: Path to environment file for loading settings.
env_file_encoding: Encoding of the environment file.
"""
settings = load_settings(
AnthropicFoundrySettings,
env_prefix="",
anthropic_foundry_api_key=api_key,
anthropic_foundry_resource=resource,
anthropic_foundry_base_url=base_url,
anthropic_chat_model=model,
env_file_path=env_file_path,
env_file_encoding=env_file_encoding,
)
api_key_secret = settings.get("anthropic_foundry_api_key")
model_setting = settings.get("anthropic_chat_model")
resource_setting = settings.get("anthropic_foundry_resource")
base_url_setting = settings.get("anthropic_foundry_base_url")
api_key_value = api_key_secret.get_secret_value() if api_key_secret is not None else None
if anthropic_client is None:
if base_url_setting is None and resource_setting is None:
message = (
"Anthropic Foundry requires either `resource`/`ANTHROPIC_FOUNDRY_RESOURCE` "
"or `base_url`/`ANTHROPIC_FOUNDRY_BASE_URL`."
)
raise ValueError(message)
if base_url_setting is not None:
anthropic_client = AsyncAnthropicFoundry(
base_url=base_url_setting,
api_key=api_key_value,
azure_ad_token_provider=azure_ad_token_provider,
default_headers={"User-Agent": get_user_agent()},
)
else:
anthropic_client = AsyncAnthropicFoundry(
resource=resource_setting,
api_key=api_key_value,
azure_ad_token_provider=azure_ad_token_provider,
default_headers={"User-Agent": get_user_agent()},
)
super().__init__(
model=model_setting,
anthropic_client=anthropic_client,
additional_beta_flags=additional_beta_flags,
additional_properties=additional_properties,
)
class AnthropicFoundryClient(
FunctionInvocationLayer[AnthropicOptionsT],
ChatMiddlewareLayer[AnthropicOptionsT],
ChatTelemetryLayer[AnthropicOptionsT],
RawAnthropicFoundryClient[AnthropicOptionsT],
Generic[AnthropicOptionsT],
):
"""Anthropic Foundry chat client with middleware, telemetry, and function invocation support."""
def __init__(
self,
*,
model: str | None = None,
resource: str | None = None,
api_key: str | None = None,
azure_ad_token_provider: AnthropicFoundryAzureADTokenProvider | None = None,
base_url: str | None = None,
anthropic_client: AsyncAnthropicFoundry | None = None,
additional_beta_flags: list[str] | None = None,
additional_properties: dict[str, Any] | None = None,
middleware: Sequence[ChatAndFunctionMiddlewareTypes] | None = None,
function_invocation_configuration: FunctionInvocationConfiguration | None = None,
env_file_path: str | None = None,
env_file_encoding: str | None = None,
) -> None:
"""Initialize an Anthropic Foundry client.
Keyword Args:
model: The Anthropic model to use.
resource: The Foundry resource name.
api_key: The Foundry Anthropic API key.
azure_ad_token_provider: Azure AD token provider used by the Anthropic SDK.
base_url: Full Anthropic-compatible Foundry base URL.
anthropic_client: Existing AsyncAnthropicFoundry client to reuse.
additional_beta_flags: Additional beta flags to enable on the client.
additional_properties: Additional properties stored on the client instance.
middleware: Optional middleware to apply to the client.
function_invocation_configuration: Optional function invocation configuration override.
env_file_path: Path to environment file for loading settings.
env_file_encoding: Encoding of the environment file.
"""
super().__init__(
model=model,
resource=resource,
api_key=api_key,
azure_ad_token_provider=azure_ad_token_provider,
base_url=base_url,
anthropic_client=anthropic_client,
additional_beta_flags=additional_beta_flags,
additional_properties=additional_properties,
middleware=middleware,
function_invocation_configuration=function_invocation_configuration,
env_file_path=env_file_path,
env_file_encoding=env_file_encoding,
)
@@ -0,0 +1,161 @@
# Copyright (c) Microsoft. All rights reserved.
from __future__ import annotations
from collections.abc import Sequence
from typing import TYPE_CHECKING, Any, ClassVar, Generic, TypedDict
from agent_framework import (
ChatAndFunctionMiddlewareTypes,
ChatMiddlewareLayer,
FunctionInvocationConfiguration,
FunctionInvocationLayer,
)
from agent_framework._settings import load_settings
from agent_framework._telemetry import get_user_agent
from agent_framework.observability import ChatTelemetryLayer
from anthropic import NOT_GIVEN
from anthropic.lib.vertex import AsyncAnthropicVertex
from ._chat_client import AnthropicOptionsT, RawAnthropicClient
if TYPE_CHECKING:
from google.auth.credentials import Credentials as GoogleCredentials
class AnthropicVertexSettings(TypedDict, total=False):
"""Resolved settings for Anthropic Vertex wrappers."""
cloud_ml_region: str | None
anthropic_vertex_project_id: str | None
anthropic_vertex_base_url: str | None
anthropic_chat_model: str | None
class RawAnthropicVertexClient(RawAnthropicClient[AnthropicOptionsT], Generic[AnthropicOptionsT]):
"""Raw Anthropic Vertex chat client without middleware, telemetry, or function invocation support."""
OTEL_PROVIDER_NAME: ClassVar[str] = "google.vertex.ai"
def __init__(
self,
*,
model: str | None = None,
region: str | None = None,
project_id: str | None = None,
access_token: str | None = None,
credentials: GoogleCredentials | None = None,
base_url: str | None = None,
anthropic_client: AsyncAnthropicVertex | None = None,
additional_beta_flags: list[str] | None = None,
additional_properties: dict[str, Any] | None = None,
env_file_path: str | None = None,
env_file_encoding: str | None = None,
) -> None:
"""Initialize a raw Anthropic Vertex client.
Keyword Args:
model: The Anthropic model to use.
region: Vertex region. Falls back to `CLOUD_ML_REGION`.
project_id: Vertex project ID. Falls back to `ANTHROPIC_VERTEX_PROJECT_ID`.
access_token: Explicit OAuth access token.
credentials: Google credentials object.
base_url: Optional custom Anthropic Vertex base URL.
anthropic_client: Existing AsyncAnthropicVertex client to reuse.
additional_beta_flags: Additional beta flags to enable on the client.
additional_properties: Additional properties stored on the client instance.
env_file_path: Path to environment file for loading settings.
env_file_encoding: Encoding of the environment file.
"""
settings = load_settings(
AnthropicVertexSettings,
env_prefix="",
cloud_ml_region=region,
anthropic_vertex_project_id=project_id,
anthropic_vertex_base_url=base_url,
anthropic_chat_model=model,
env_file_path=env_file_path,
env_file_encoding=env_file_encoding,
)
model_setting = settings.get("anthropic_chat_model")
region_setting = settings.get("cloud_ml_region")
project_id_setting = settings.get("anthropic_vertex_project_id")
if anthropic_client is None:
resolved_region = region_setting if region_setting is not None else NOT_GIVEN
resolved_project_id = project_id_setting if project_id_setting is not None else NOT_GIVEN
anthropic_client = AsyncAnthropicVertex(
region=resolved_region,
project_id=resolved_project_id,
access_token=access_token,
credentials=credentials,
base_url=settings.get("anthropic_vertex_base_url"),
default_headers={"User-Agent": get_user_agent()},
)
super().__init__(
model=model_setting,
anthropic_client=anthropic_client,
additional_beta_flags=additional_beta_flags,
additional_properties=additional_properties,
)
class AnthropicVertexClient(
FunctionInvocationLayer[AnthropicOptionsT],
ChatMiddlewareLayer[AnthropicOptionsT],
ChatTelemetryLayer[AnthropicOptionsT],
RawAnthropicVertexClient[AnthropicOptionsT],
Generic[AnthropicOptionsT],
):
"""Anthropic Vertex chat client with middleware, telemetry, and function invocation support."""
def __init__(
self,
*,
model: str | None = None,
region: str | None = None,
project_id: str | None = None,
access_token: str | None = None,
credentials: GoogleCredentials | None = None,
base_url: str | None = None,
anthropic_client: AsyncAnthropicVertex | None = None,
additional_beta_flags: list[str] | None = None,
additional_properties: dict[str, Any] | None = None,
middleware: Sequence[ChatAndFunctionMiddlewareTypes] | None = None,
function_invocation_configuration: FunctionInvocationConfiguration | None = None,
env_file_path: str | None = None,
env_file_encoding: str | None = None,
) -> None:
"""Initialize an Anthropic Vertex client.
Keyword Args:
model: The Anthropic model to use.
region: Vertex region. Falls back to `CLOUD_ML_REGION`.
project_id: Vertex project ID. Falls back to `ANTHROPIC_VERTEX_PROJECT_ID`.
access_token: Explicit OAuth access token.
credentials: Google credentials object.
base_url: Optional custom Anthropic Vertex base URL.
anthropic_client: Existing AsyncAnthropicVertex client to reuse.
additional_beta_flags: Additional beta flags to enable on the client.
additional_properties: Additional properties stored on the client instance.
middleware: Optional middleware to apply to the client.
function_invocation_configuration: Optional function invocation configuration override.
env_file_path: Path to environment file for loading settings.
env_file_encoding: Encoding of the environment file.
"""
super().__init__(
model=model,
region=region,
project_id=project_id,
access_token=access_token,
credentials=credentials,
base_url=base_url,
anthropic_client=anthropic_client,
additional_beta_flags=additional_beta_flags,
additional_properties=additional_properties,
middleware=middleware,
function_invocation_configuration=function_invocation_configuration,
env_file_path=env_file_path,
env_file_encoding=env_file_encoding,
)