# Copyright (c) Microsoft. All rights reserved.

"""Public API surface for Agent Framework core.

This module exposes the primary abstractions for agents, chat clients, tools, sessions,
middleware, observability, and workflows. Connector namespaces such as
``agent_framework.azure`` and ``agent_framework.anthropic`` provide provider-specific
integrations, many of which are lazy-loaded from optional packages.
"""

import importlib.metadata
from typing import Final

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

from ._agents import Agent, BaseAgent, RawAgent, SupportsAgentRun
from ._clients import (
    BaseChatClient,
    BaseEmbeddingClient,
    SupportsChatGetResponse,
    SupportsCodeInterpreterTool,
    SupportsFileSearchTool,
    SupportsGetEmbeddings,
    SupportsImageGenerationTool,
    SupportsMCPTool,
    SupportsWebSearchTool,
)
from ._compaction import (
    COMPACTION_STATE_KEY,
    EXCLUDE_REASON_KEY,
    EXCLUDED_KEY,
    GROUP_ANNOTATION_KEY,
    GROUP_HAS_REASONING_KEY,
    GROUP_ID_KEY,
    GROUP_INDEX_KEY,
    GROUP_KIND_KEY,
    GROUP_TOKEN_COUNT_KEY,
    SUMMARIZED_BY_SUMMARY_ID_KEY,
    SUMMARY_OF_GROUP_IDS_KEY,
    SUMMARY_OF_MESSAGE_IDS_KEY,
    CharacterEstimatorTokenizer,
    CompactionProvider,
    CompactionStrategy,
    ContextWindowCompactionStrategy,
    SelectiveToolCallCompactionStrategy,
    SlidingWindowStrategy,
    SummarizationStrategy,
    TokenBudgetComposedStrategy,
    TokenizerProtocol,
    ToolResultCompactionStrategy,
    TruncationStrategy,
    annotate_message_groups,
    apply_compaction,
    included_messages,
    included_token_count,
)
from ._evaluation import (
    AgentEvalConverter,
    CheckResult,
    ConversationSplit,
    ConversationSplitter,
    EvalItem,
    EvalItemResult,
    EvalNotPassedError,
    EvalResults,
    EvalScoreResult,
    Evaluator,
    ExpectedToolCall,
    LocalEvaluator,
    RubricScore,
    evaluate_agent,
    evaluate_workflow,
    evaluator,
    keyword_check,
    tool_call_args_match,
    tool_called_check,
    tool_calls_present,
)
from ._feature_stage import ExperimentalFeature, ReleaseCandidateFeature
from ._harness._agent import (
    DEFAULT_HARNESS_INSTRUCTIONS,
    create_harness_agent,
)
from ._harness._background_agents import (
    DEFAULT_BACKGROUND_AGENTS_SOURCE_ID,
    BackgroundAgentsProvider,
    BackgroundTaskInfo,
    BackgroundTaskStatus,
)
from ._harness._file_access import (
    DEFAULT_FILE_ACCESS_INSTRUCTIONS,
    DEFAULT_FILE_ACCESS_SOURCE_ID,
    AgentFileStore,
    FileAccessProvider,
    FileSearchMatch,
    FileSearchResult,
    FileSystemAgentFileStore,
    InMemoryAgentFileStore,
)
from ._harness._memory import (
    DEFAULT_MEMORY_SOURCE_ID,
    MemoryContextProvider,
    MemoryFileStore,
    MemoryIndexEntry,
    MemoryStore,
    MemoryTopicRecord,
)
from ._harness._mode import (
    DEFAULT_MODE_SOURCE_ID,
    AgentModeProvider,
    get_agent_mode,
    set_agent_mode,
)
from ._harness._todo import (
    DEFAULT_TODO_SOURCE_ID,
    TodoFileStore,
    TodoInput,
    TodoItem,
    TodoProvider,
    TodoSessionStore,
    TodoStore,
)
from ._mcp import MCPStdioTool, MCPStreamableHTTPTool, MCPWebsocketTool
from ._middleware import (
    AgentContext,
    AgentMiddleware,
    AgentMiddlewareLayer,
    AgentMiddlewareTypes,
    ChatAndFunctionMiddlewareTypes,
    ChatContext,
    ChatMiddleware,
    ChatMiddlewareLayer,
    ChatMiddlewareTypes,
    FunctionInvocationContext,
    FunctionMiddleware,
    FunctionMiddlewareTypes,
    MiddlewareTermination,
    MiddlewareType,
    MiddlewareTypes,
    agent_middleware,
    chat_middleware,
    function_middleware,
)
from ._sessions import (
    AgentSession,
    ContextProvider,
    FileHistoryProvider,
    HistoryProvider,
    InMemoryHistoryProvider,
    SessionContext,
    register_state_type,
)
from ._settings import SecretString, load_settings
from ._skills import (
    AggregatingSkillsSource,
    ClassSkill,
    DeduplicatingSkillsSource,
    DelegatingSkillsSource,
    FileSkill,
    FileSkillScript,
    FileSkillsSource,
    FilteringSkillsSource,
    InlineSkill,
    InlineSkillResource,
    InlineSkillScript,
    InMemorySkillsSource,
    MCPSkill,
    MCPSkillResource,
    MCPSkillsSource,
    Skill,
    SkillFrontmatter,
    SkillResource,
    SkillScript,
    SkillScriptRunner,
    SkillsProvider,
    SkillsSource,
)
from ._telemetry import (
    AGENT_FRAMEWORK_USER_AGENT,
    APP_INFO,
    USER_AGENT_KEY,
    USER_AGENT_TELEMETRY_DISABLED_ENV_VAR,
    prepend_agent_framework_to_user_agent,
)
from ._tools import (
    SKIP_PARSING,
    FunctionInvocationConfiguration,
    FunctionInvocationLayer,
    FunctionTool,
    ToolTypes,
    normalize_function_invocation_configuration,
    tool,
)
from ._types import (
    AgentResponse,
    AgentResponseUpdate,
    AgentRunInputs,
    Annotation,
    ChatOptions,
    ChatResponse,
    ChatResponseUpdate,
    Content,
    ContinuationToken,
    Embedding,
    EmbeddingGenerationOptions,
    EmbeddingInputT,
    EmbeddingT,
    FinalT,
    FinishReason,
    FinishReasonLiteral,
    GeneratedEmbeddings,
    Message,
    OuterFinalT,
    OuterUpdateT,
    ResponseStream,
    Role,
    RoleLiteral,
    TextSpanRegion,
    ToolMode,
    UpdateT,
    UsageDetails,
    add_usage_details,
    detect_media_type_from_base64,
    map_chat_to_agent_update,
    merge_chat_options,
    normalize_messages,
    normalize_tools,
    prepend_instructions_to_messages,
    validate_chat_options,
    validate_tool_mode,
    validate_tools,
)
from ._workflows._agent import WorkflowAgent
from ._workflows._agent_executor import (
    AgentExecutor,
    AgentExecutorRequest,
    AgentExecutorResponse,
)
from ._workflows._agent_utils import resolve_agent_id
from ._workflows._checkpoint import (
    CheckpointStorage,
    FileCheckpointStorage,
    InMemoryCheckpointStorage,
    WorkflowCheckpoint,
)
from ._workflows._const import (
    DEFAULT_MAX_ITERATIONS,
)
from ._workflows._edge import (
    Case,
    Default,
    Edge,
    EdgeCondition,
    FanInEdgeGroup,
    FanOutEdgeGroup,
    SingleEdgeGroup,
    SwitchCaseEdgeGroup,
    SwitchCaseEdgeGroupCase,
    SwitchCaseEdgeGroupDefault,
)
from ._workflows._edge_runner import create_edge_runner
from ._workflows._events import (
    WorkflowErrorDetails,
    WorkflowEvent,
    WorkflowEventSource,
    WorkflowEventType,
    WorkflowRunState,
)
from ._workflows._executor import (
    Executor,
    handler,
)
from ._workflows._function_executor import FunctionExecutor, executor
from ._workflows._functional import (
    FunctionalWorkflow,
    FunctionalWorkflowAgent,
    RunContext,
    StepWrapper,
    get_run_context,
    step,
    workflow,
)
from ._workflows._request_info_mixin import response_handler
from ._workflows._runner import Runner
from ._workflows._runner_context import (
    InProcRunnerContext,
    RunnerContext,
    WorkflowMessage,
)
from ._workflows._validation import (
    EdgeDuplicationError,
    GraphConnectivityError,
    TypeCompatibilityError,
    ValidationTypeEnum,
    WorkflowValidationError,
    validate_workflow_graph,
)
from ._workflows._viz import WorkflowViz
from ._workflows._workflow import Workflow, WorkflowRunResult
from ._workflows._workflow_builder import WorkflowBuilder
from ._workflows._workflow_context import WorkflowContext
from ._workflows._workflow_executor import (
    SubWorkflowRequestMessage,
    SubWorkflowResponseMessage,
    WorkflowExecutor,
)
from .exceptions import (
    AgentFrameworkException,
    MiddlewareException,
    UserInputRequiredException,
    WorkflowCheckpointException,
    WorkflowConvergenceException,
    WorkflowException,
    WorkflowRunnerException,
)

__all__ = [
    "AGENT_FRAMEWORK_USER_AGENT",
    "APP_INFO",
    "COMPACTION_STATE_KEY",
    "DEFAULT_BACKGROUND_AGENTS_SOURCE_ID",
    "DEFAULT_FILE_ACCESS_INSTRUCTIONS",
    "DEFAULT_FILE_ACCESS_SOURCE_ID",
    "DEFAULT_HARNESS_INSTRUCTIONS",
    "DEFAULT_MAX_ITERATIONS",
    "DEFAULT_MEMORY_SOURCE_ID",
    "DEFAULT_MODE_SOURCE_ID",
    "DEFAULT_TODO_SOURCE_ID",
    "EXCLUDED_KEY",
    "EXCLUDE_REASON_KEY",
    "GROUP_ANNOTATION_KEY",
    "GROUP_HAS_REASONING_KEY",
    "GROUP_ID_KEY",
    "GROUP_INDEX_KEY",
    "GROUP_KIND_KEY",
    "GROUP_TOKEN_COUNT_KEY",
    "SKIP_PARSING",
    "SUMMARIZED_BY_SUMMARY_ID_KEY",
    "SUMMARY_OF_GROUP_IDS_KEY",
    "SUMMARY_OF_MESSAGE_IDS_KEY",
    "USER_AGENT_KEY",
    "USER_AGENT_TELEMETRY_DISABLED_ENV_VAR",
    "Agent",
    "AgentContext",
    "AgentEvalConverter",
    "AgentExecutor",
    "AgentExecutorRequest",
    "AgentExecutorResponse",
    "AgentFileStore",
    "AgentFrameworkException",
    "AgentMiddleware",
    "AgentMiddlewareLayer",
    "AgentMiddlewareTypes",
    "AgentModeProvider",
    "AgentResponse",
    "AgentResponseUpdate",
    "AgentRunInputs",
    "AgentSession",
    "AggregatingSkillsSource",
    "Annotation",
    "BackgroundAgentsProvider",
    "BackgroundTaskInfo",
    "BackgroundTaskStatus",
    "BaseAgent",
    "BaseChatClient",
    "BaseEmbeddingClient",
    "Case",
    "CharacterEstimatorTokenizer",
    "ChatAndFunctionMiddlewareTypes",
    "ChatContext",
    "ChatMiddleware",
    "ChatMiddlewareLayer",
    "ChatMiddlewareTypes",
    "ChatOptions",
    "ChatResponse",
    "ChatResponseUpdate",
    "CheckResult",
    "CheckpointStorage",
    "ClassSkill",
    "CompactionProvider",
    "CompactionStrategy",
    "Content",
    "ContextProvider",
    "ContextWindowCompactionStrategy",
    "ContinuationToken",
    "ConversationSplit",
    "ConversationSplitter",
    "DeduplicatingSkillsSource",
    "Default",
    "DelegatingSkillsSource",
    "Edge",
    "EdgeCondition",
    "EdgeDuplicationError",
    "Embedding",
    "EmbeddingGenerationOptions",
    "EmbeddingInputT",
    "EmbeddingT",
    "EvalItem",
    "EvalItemResult",
    "EvalNotPassedError",
    "EvalResults",
    "EvalScoreResult",
    "Evaluator",
    "Executor",
    "ExpectedToolCall",
    "ExperimentalFeature",
    "FanInEdgeGroup",
    "FanOutEdgeGroup",
    "FileAccessProvider",
    "FileCheckpointStorage",
    "FileHistoryProvider",
    "FileSearchMatch",
    "FileSearchResult",
    "FileSkill",
    "FileSkillScript",
    "FileSkillsSource",
    "FileSystemAgentFileStore",
    "FilteringSkillsSource",
    "FinalT",
    "FinishReason",
    "FinishReasonLiteral",
    "FunctionExecutor",
    "FunctionInvocationConfiguration",
    "FunctionInvocationContext",
    "FunctionInvocationLayer",
    "FunctionMiddleware",
    "FunctionMiddlewareTypes",
    "FunctionTool",
    "FunctionalWorkflow",
    "FunctionalWorkflowAgent",
    "GeneratedEmbeddings",
    "GraphConnectivityError",
    "HistoryProvider",
    "InMemoryAgentFileStore",
    "InMemoryCheckpointStorage",
    "InMemoryHistoryProvider",
    "InMemorySkillsSource",
    "InProcRunnerContext",
    "InlineSkill",
    "InlineSkillResource",
    "InlineSkillScript",
    "LocalEvaluator",
    "MCPStdioTool",
    "MCPStreamableHTTPTool",
    "MCPWebsocketTool",
    "MCPSkill",
    "MCPSkillResource",
    "MCPSkillsSource",
    "MemoryContextProvider",
    "MemoryFileStore",
    "MemoryIndexEntry",
    "MemoryStore",
    "MemoryTopicRecord",
    "Message",
    "MiddlewareException",
    "MiddlewareTermination",
    "MiddlewareType",
    "MiddlewareTypes",
    "OuterFinalT",
    "OuterUpdateT",
    "RawAgent",
    "ReleaseCandidateFeature",
    "ResponseStream",
    "Role",
    "RoleLiteral",
    "RubricScore",
    "RunContext",
    "Runner",
    "RunnerContext",
    "SecretString",
    "SelectiveToolCallCompactionStrategy",
    "SessionContext",
    "SingleEdgeGroup",
    "Skill",
    "SkillFrontmatter",
    "SkillResource",
    "SkillScript",
    "SkillScriptRunner",
    "SkillsProvider",
    "SkillsSource",
    "SlidingWindowStrategy",
    "StepWrapper",
    "SubWorkflowRequestMessage",
    "SubWorkflowResponseMessage",
    "SummarizationStrategy",
    "SupportsAgentRun",
    "SupportsChatGetResponse",
    "SupportsCodeInterpreterTool",
    "SupportsFileSearchTool",
    "SupportsGetEmbeddings",
    "SupportsImageGenerationTool",
    "SupportsMCPTool",
    "SupportsWebSearchTool",
    "SwitchCaseEdgeGroup",
    "SwitchCaseEdgeGroupCase",
    "SwitchCaseEdgeGroupDefault",
    "TextSpanRegion",
    "TodoFileStore",
    "TodoInput",
    "TodoItem",
    "TodoProvider",
    "TodoSessionStore",
    "TodoStore",
    "TokenBudgetComposedStrategy",
    "TokenizerProtocol",
    "ToolMode",
    "ToolResultCompactionStrategy",
    "ToolTypes",
    "TruncationStrategy",
    "TypeCompatibilityError",
    "UpdateT",
    "UsageDetails",
    "UserInputRequiredException",
    "ValidationTypeEnum",
    "Workflow",
    "WorkflowAgent",
    "WorkflowBuilder",
    "WorkflowCheckpoint",
    "WorkflowCheckpointException",
    "WorkflowContext",
    "WorkflowConvergenceException",
    "WorkflowErrorDetails",
    "WorkflowEvent",
    "WorkflowEventSource",
    "WorkflowEventType",
    "WorkflowException",
    "WorkflowExecutor",
    "WorkflowMessage",
    "WorkflowRunResult",
    "WorkflowRunState",
    "WorkflowRunnerException",
    "WorkflowValidationError",
    "WorkflowViz",
    "__version__",
    "add_usage_details",
    "agent_middleware",
    "annotate_message_groups",
    "apply_compaction",
    "chat_middleware",
    "create_edge_runner",
    "create_harness_agent",
    "detect_media_type_from_base64",
    "evaluate_agent",
    "evaluate_workflow",
    "evaluator",
    "executor",
    "function_middleware",
    "get_agent_mode",
    "get_run_context",
    "handler",
    "included_messages",
    "included_token_count",
    "keyword_check",
    "load_settings",
    "map_chat_to_agent_update",
    "merge_chat_options",
    "normalize_function_invocation_configuration",
    "normalize_messages",
    "normalize_tools",
    "prepend_agent_framework_to_user_agent",
    "prepend_instructions_to_messages",
    "register_state_type",
    "resolve_agent_id",
    "response_handler",
    "set_agent_mode",
    "step",
    "tool",
    "tool_call_args_match",
    "tool_called_check",
    "tool_calls_present",
    "validate_chat_options",
    "validate_tool_mode",
    "validate_tools",
    "validate_workflow_graph",
    "workflow",
]
