Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions python/.vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
],
"[python]": {
"editor.codeActionsOnSave": {
"source.organizeImports": "explicit",
"source.fixAll": "explicit"
"source.organizeImports.ruff": "always",
"source.fixAll.ruff": "always"
},
"editor.formatOnSave": true,
"editor.formatOnPaste": true,
Expand All @@ -36,4 +36,4 @@
"depth": 2
}
]
}
}
2 changes: 1 addition & 1 deletion python/packages/azure/tests/unit/test_azure_chat_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
TextContent,
)
from agent_framework.exceptions import ServiceInitializationError, ServiceResponseException
from agent_framework.openai.exceptions import (
from agent_framework.openai import (
ContentFilterResultSeverity,
OpenAIContentFilterException,
)
Expand Down
65 changes: 6 additions & 59 deletions python/packages/main/agent_framework/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,68 +2,15 @@

import importlib
import importlib.metadata
from typing import Any

try:
__version__ = importlib.metadata.version(__name__)
except importlib.metadata.PackageNotFoundError:
__version__ = "0.0.0" # Fallback for development mode

_IMPORTS = {
"AFBaseModel": "._pydantic",
"AFBaseSettings": "._pydantic",
"Agent": "._agents",
"AgentRunResponse": "._types",
"AgentRunResponseUpdate": "._types",
"AgentThread": "._agents",
"AITool": "._tools",
"AIFunction": "._tools",
"AIContent": "._types",
"AIContents": "._types",
"ChatClient": "._clients",
"ChatClientAgent": "._agents",
"ChatClientAgentThread": "._agents",
"ChatClientAgentThreadType": "._agents",
"ChatClientBase": "._clients",
"ChatFinishReason": "._types",
"ChatMessage": "._types",
"ChatOptions": "._types",
"ChatResponse": "._types",
"ChatResponseUpdate": "._types",
"ChatRole": "._types",
"ChatToolMode": "._types",
"DataContent": "._types",
"EmbeddingGenerator": "._clients",
"ErrorContent": "._types",
"FunctionCallContent": "._types",
"FunctionResultContent": "._types",
"GeneratedEmbeddings": "._types",
"HttpsUrl": "._pydantic",
"InputGuardrail": ".guard_rails",
"OutputGuardrail": ".guard_rails",
"SpeechToTextOptions": "._types",
"StructuredResponse": "._types",
"TextContent": "._types",
"TextReasoningContent": "._types",
"TextToSpeechOptions": "._types",
"UriContent": "._types",
"UsageContent": "._types",
"UsageDetails": "._types",
"ai_function": "._tools",
"get_logger": "._logging",
"use_tool_calling": "._clients",
}


def __getattr__(name: str) -> Any:
if name == "__version__":
return __version__
if name in _IMPORTS:
submod_name = _IMPORTS[name]
module = importlib.import_module(submod_name, package=__name__)
return getattr(module, name)
raise AttributeError(f"module {__name__} has no attribute {name}")


def __dir__() -> list[str]:
return [*list(_IMPORTS.keys()), "__version__"]
from ._agents import * # noqa: F403
from ._clients import * # noqa: F403
from ._logging import * # noqa: F403
from ._pydantic import * # noqa: F403
from ._tools import * # noqa: F403
from ._types import * # noqa: F403
81 changes: 0 additions & 81 deletions python/packages/main/agent_framework/__init__.pyi

This file was deleted.

10 changes: 10 additions & 0 deletions python/packages/main/agent_framework/_agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@

# region AgentThread

__all__ = [
"Agent",
"AgentBase",
"AgentThread",
"ChatClientAgent",
"ChatClientAgentThread",
"ChatClientAgentThreadType",
"MessagesRetrievableThread",
]


class AgentThread(AFBaseModel):
"""Base class for agent threads."""
Expand Down
14 changes: 11 additions & 3 deletions python/packages/main/agent_framework/_clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@

logger = get_logger()

__all__ = [
"ChatClient",
"ChatClientBase",
"EmbeddingGenerator",
"use_tool_calling",
]

# region: Tool Calling Functions and Decorators


Expand Down Expand Up @@ -88,7 +95,8 @@ def _prepare_tools_and_tool_choice(chat_options: ChatOptions) -> None:
chat_options.tool_choice = ChatToolMode.NONE.mode
return
chat_options.tools = [
(_tool_to_json_schema_spec(t) if isinstance(t, AITool) else t) for t in chat_options._ai_tools or []
(_tool_to_json_schema_spec(t) if isinstance(t, AITool) else t)
for t in chat_options._ai_tools or [] # type: ignore[reportPrivateUsage]
]
if not chat_options.tools:
chat_options.tool_choice = ChatToolMode.NONE.mode
Expand Down Expand Up @@ -126,7 +134,7 @@ async def wrapper(
_auto_invoke_function(
function_call,
custom_args=kwargs,
tool_map={t.name: t for t in chat_options._ai_tools or [] if isinstance(t, AIFunction)},
tool_map={t.name: t for t in chat_options._ai_tools or [] if isinstance(t, AIFunction)}, # type: ignore[reportPrivateUsage]
sequence_index=seq_idx,
request_index=attempt_idx,
)
Expand Down Expand Up @@ -203,7 +211,7 @@ async def wrapper(
_auto_invoke_function(
function_call,
custom_args=kwargs,
tool_map={t.name: t for t in chat_options._ai_tools or [] if isinstance(t, AIFunction)},
tool_map={t.name: t for t in chat_options._ai_tools or [] if isinstance(t, AIFunction)}, # type: ignore[reportPrivateUsage]
sequence_index=seq_idx,
request_index=attempt_idx,
)
Expand Down
2 changes: 2 additions & 0 deletions python/packages/main/agent_framework/_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
datefmt="%Y-%m-%d %H:%M:%S",
)

__all__ = ["get_logger"]


def get_logger(name: str = "agent_framework") -> logging.Logger:
"""Get a logger with the specified name, defaulting to 'agent_framework'.
Expand Down
2 changes: 2 additions & 0 deletions python/packages/main/agent_framework/_pydantic.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

HttpsUrl = Annotated[AnyUrl, UrlConstraints(max_length=2083, allowed_schemes=["https"])]

__all__ = ["AFBaseModel", "AFBaseSettings", "HttpsUrl"]


class AFBaseModel(BaseModel):
"""Base class for all pydantic models in the Agent Framework."""
Expand Down
2 changes: 2 additions & 0 deletions python/packages/main/agent_framework/_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

from pydantic import BaseModel, create_model

__all__ = ["AIFunction", "AITool", "ai_function"]


@runtime_checkable
class AITool(Protocol):
Expand Down
28 changes: 28 additions & 0 deletions python/packages/main/agent_framework/_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,34 @@
]


__all__ = [
"AIContent",
"AIContents",
"AgentRunResponse",
"AgentRunResponseUpdate",
"ChatFinishReason",
"ChatMessage",
"ChatOptions",
"ChatResponse",
"ChatResponseUpdate",
"ChatRole",
"ChatToolMode",
"DataContent",
"ErrorContent",
"FunctionCallContent",
"FunctionResultContent",
"GeneratedEmbeddings",
"SpeechToTextOptions",
"StructuredResponse",
"TextContent",
"TextReasoningContent",
"TextToSpeechOptions",
"UriContent",
"UsageContent",
"UsageDetails",
]


class UsageDetails(AFBaseModel):
"""Provides usage details about a request/response.

Expand Down
26 changes: 10 additions & 16 deletions python/packages/main/agent_framework/azure/__init__.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,28 @@
# Copyright (c) Microsoft. All rights reserved.

import importlib
from typing import TYPE_CHECKING, Any
from typing import Any

PACKAGE_NAME = "agent_framework_azure"
PACKAGE_EXTRA = "azure"

_IMPORTS = {
"__version__": "agent_framework_azure",
"AzureChatClient": "agent_framework_azure",
"get_entra_auth_token": "agent_framework_azure",
}
_IMPORTS = [
"AzureChatClient",
"get_entra_auth_token",
"__version__",
]


def __getattr__(name: str) -> Any:
if name in _IMPORTS:
submod_name = _IMPORTS[name]
try:
module = importlib.import_module(submod_name, package=__name__)
return getattr(module, name)
return getattr(importlib.import_module(PACKAGE_NAME), name)
except ModuleNotFoundError as exc:
raise ModuleNotFoundError(
f"The '{PACKAGE_EXTRA}' extra is not installed, "
f"please do `pip install agent-framework[{PACKAGE_EXTRA}]`"
) from exc
raise AttributeError(f"module {__name__} has no attribute {name}")
raise AttributeError(f"Module {PACKAGE_NAME} has no attribute {name}.")


def __dir__() -> list[str]:
return list(_IMPORTS.keys())


if TYPE_CHECKING:
from agent_framework_azure import __version__ # noqa: F401
return _IMPORTS
13 changes: 13 additions & 0 deletions python/packages/main/agent_framework/azure/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright (c) Microsoft. All rights reserved.

from agent_framework_azure import (
AzureChatClient,
__version__,
get_entra_auth_token,
)

__all__ = [
"AzureChatClient",
"__version__",
"get_entra_auth_token",
]
2 changes: 2 additions & 0 deletions python/packages/main/agent_framework/guard_rails.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
TInput = TypeVar("TInput")
TResponse = TypeVar("TResponse")

__all__ = ["InputGuardrail", "OutputGuardrail"]


@runtime_checkable
class InputGuardrail(Protocol, Generic[TInput]):
Expand Down
12 changes: 3 additions & 9 deletions python/packages/main/agent_framework/openai/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
# Copyright (c) Microsoft. All rights reserved.


from ._chat_client import OpenAIChatClient
from ._shared import OpenAIHandler, OpenAIModelTypes, OpenAISettings

__all__ = [
"OpenAIChatClient",
"OpenAIHandler",
"OpenAIModelTypes",
"OpenAISettings",
]
from ._chat_client import * # noqa: F403
from ._exceptions import * # noqa: F403
from ._shared import * # noqa: F403
2 changes: 2 additions & 0 deletions python/packages/main/agent_framework/openai/_chat_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
from ..exceptions import ServiceInitializationError, ServiceInvalidResponseError
from ._shared import OpenAIConfigBase, OpenAIHandler, OpenAIModelTypes, OpenAISettings

__all__ = ["OpenAIChatClient"]


# Implements agent_framework.ChatClient protocol, through ChatClientBase
@use_tool_calling
Expand Down
Loading
Loading