azure-ai-agentserver-core 1.0.0b2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. azure/ai/agentserver/__init__.py +1 -0
  2. azure/ai/agentserver/core/__init__.py +14 -0
  3. azure/ai/agentserver/core/_version.py +9 -0
  4. azure/ai/agentserver/core/constants.py +13 -0
  5. azure/ai/agentserver/core/logger.py +161 -0
  6. azure/ai/agentserver/core/models/__init__.py +7 -0
  7. azure/ai/agentserver/core/models/_create_response.py +12 -0
  8. azure/ai/agentserver/core/models/openai/__init__.py +16 -0
  9. azure/ai/agentserver/core/models/projects/__init__.py +820 -0
  10. azure/ai/agentserver/core/models/projects/_enums.py +767 -0
  11. azure/ai/agentserver/core/models/projects/_models.py +15049 -0
  12. azure/ai/agentserver/core/models/projects/_patch.py +39 -0
  13. azure/ai/agentserver/core/models/projects/_patch_evaluations.py +48 -0
  14. azure/ai/agentserver/core/models/projects/_utils/__init__.py +6 -0
  15. azure/ai/agentserver/core/models/projects/_utils/model_base.py +1237 -0
  16. azure/ai/agentserver/core/models/projects/_utils/serialization.py +2030 -0
  17. azure/ai/agentserver/core/py.typed +0 -0
  18. azure/ai/agentserver/core/server/__init__.py +1 -0
  19. azure/ai/agentserver/core/server/base.py +324 -0
  20. azure/ai/agentserver/core/server/common/__init__.py +1 -0
  21. azure/ai/agentserver/core/server/common/agent_run_context.py +76 -0
  22. azure/ai/agentserver/core/server/common/id_generator/__init__.py +5 -0
  23. azure/ai/agentserver/core/server/common/id_generator/foundry_id_generator.py +136 -0
  24. azure/ai/agentserver/core/server/common/id_generator/id_generator.py +19 -0
  25. azure_ai_agentserver_core-1.0.0b2.dist-info/METADATA +149 -0
  26. azure_ai_agentserver_core-1.0.0b2.dist-info/RECORD +29 -0
  27. azure_ai_agentserver_core-1.0.0b2.dist-info/WHEEL +5 -0
  28. azure_ai_agentserver_core-1.0.0b2.dist-info/licenses/LICENSE +21 -0
  29. azure_ai_agentserver_core-1.0.0b2.dist-info/top_level.txt +1 -0
@@ -0,0 +1 @@
1
+ __path__ = __import__("pkgutil").extend_path(__path__, __name__) # type: ignore
@@ -0,0 +1,14 @@
1
+ # ---------------------------------------------------------
2
+ # Copyright (c) Microsoft Corporation. All rights reserved.
3
+ # ---------------------------------------------------------
4
+ __path__ = __import__("pkgutil").extend_path(__path__, __name__)
5
+
6
+ from ._version import VERSION
7
+ from .logger import configure as config_logging
8
+ from .server.base import FoundryCBAgent
9
+ from .server.common.agent_run_context import AgentRunContext
10
+
11
+ config_logging()
12
+
13
+ __all__ = ["FoundryCBAgent", "AgentRunContext"]
14
+ __version__ = VERSION
@@ -0,0 +1,9 @@
1
+ # coding=utf-8
2
+ # --------------------------------------------------------------------------
3
+ # Copyright (c) Microsoft Corporation. All rights reserved.
4
+ # Licensed under the MIT License. See License.txt in the project root for license information.
5
+ # Code generated by Microsoft (R) Python Code Generator.
6
+ # Changes may cause incorrect behavior and will be lost if the code is regenerated.
7
+ # --------------------------------------------------------------------------
8
+
9
+ VERSION = "1.0.0b2"
@@ -0,0 +1,13 @@
1
+ # ---------------------------------------------------------
2
+ # Copyright (c) Microsoft Corporation. All rights reserved.
3
+ # ---------------------------------------------------------
4
+ class Constants:
5
+ # well-known environment variables
6
+ AZURE_AI_PROJECT_ENDPOINT = "AZURE_AI_PROJECT_ENDPOINT"
7
+ AGENT_ID = "AGENT_ID"
8
+ AGENT_NAME = "AGENT_NAME"
9
+ AGENT_PROJECT_RESOURCE_ID = "AGENT_PROJECT_NAME"
10
+ OTEL_EXPORTER_ENDPOINT = "OTEL_EXPORTER_ENDPOINT"
11
+ AGENT_LOG_LEVEL = "AGENT_LOG_LEVEL"
12
+ AGENT_DEBUG_ERRORS = "AGENT_DEBUG_ERRORS"
13
+ ENABLE_APPLICATION_INSIGHTS_LOGGER = "AGENT_APP_INSIGHTS_ENABLED"
@@ -0,0 +1,161 @@
1
+ # pylint: disable=broad-exception-caught,dangerous-default-value
2
+ # ---------------------------------------------------------
3
+ # Copyright (c) Microsoft Corporation. All rights reserved.
4
+ # ---------------------------------------------------------
5
+ import contextvars
6
+ import logging
7
+ import os
8
+ from logging import config
9
+
10
+ from ._version import VERSION
11
+ from .constants import Constants
12
+
13
+ default_log_config = {
14
+ "version": 1,
15
+ "disable_existing_loggers": False,
16
+ "loggers": {
17
+ "azure.ai.agentserver": {
18
+ "handlers": ["console"],
19
+ "level": "INFO",
20
+ "propagate": False,
21
+ },
22
+ },
23
+ "handlers": {
24
+ "console": {"formatter": "std_out", "class": "logging.StreamHandler", "level": "INFO"},
25
+ },
26
+ "formatters": {"std_out": {"format": "%(asctime)s - %(name)s - %(levelname)s - %(message)s"}},
27
+ }
28
+
29
+ request_context = contextvars.ContextVar("request_context", default=None)
30
+
31
+ APPINSIGHT_CONNSTR_ENV_NAME = "APPLICATIONINSIGHTS_CONNECTION_STRING"
32
+
33
+
34
+ def get_dimensions():
35
+ env_values = {name: value for name, value in vars(Constants).items() if not name.startswith("_")}
36
+ res = {"azure.ai.agentserver.version": VERSION}
37
+ for name, env_name in env_values.items():
38
+ if isinstance(env_name, str) and not env_name.startswith("_"):
39
+ runtime_value = os.environ.get(env_name)
40
+ if runtime_value:
41
+ res[f"azure.ai.agentserver.{name.lower()}"] = runtime_value
42
+ return res
43
+
44
+
45
+ def get_project_endpoint():
46
+ project_resource_id = os.environ.get(Constants.AGENT_PROJECT_RESOURCE_ID)
47
+ if project_resource_id:
48
+ last_part = project_resource_id.split("/")[-1]
49
+
50
+ parts = last_part.split("@")
51
+ if len(parts) < 2:
52
+ print(f"invalid project resource id: {project_resource_id}")
53
+ return None
54
+ account = parts[0]
55
+ project = parts[1]
56
+ return f"https://{account}.services.ai.azure.com/api/projects/{project}"
57
+ print("environment variable AGENT_PROJECT_RESOURCE_ID not set.")
58
+ return None
59
+
60
+
61
+ def get_application_insights_connstr():
62
+ try:
63
+ conn_str = os.environ.get(APPINSIGHT_CONNSTR_ENV_NAME)
64
+ if not conn_str:
65
+ print(f"environment variable {APPINSIGHT_CONNSTR_ENV_NAME} not set.")
66
+ project_endpoint = get_project_endpoint()
67
+ if project_endpoint:
68
+ # try to get the project connected application insights
69
+ from azure.ai.projects import AIProjectClient
70
+ from azure.identity import DefaultAzureCredential
71
+
72
+ project_client = AIProjectClient(credential=DefaultAzureCredential(), endpoint=project_endpoint)
73
+ conn_str = project_client.telemetry.get_application_insights_connection_string()
74
+ if not conn_str:
75
+ print(f"no connected application insights found for project:{project_endpoint}")
76
+ else:
77
+ os.environ[APPINSIGHT_CONNSTR_ENV_NAME] = conn_str
78
+ return conn_str
79
+ except Exception as e:
80
+ print(f"failed to get application insights with error: {e}")
81
+ return None
82
+
83
+
84
+ class CustomDimensionsFilter(logging.Filter):
85
+ def filter(self, record):
86
+ # Add custom dimensions to every log record
87
+ dimensions = get_dimensions()
88
+ for key, value in dimensions.items():
89
+ setattr(record, key, value)
90
+ cur_request_context = request_context.get()
91
+ if cur_request_context:
92
+ for key, value in cur_request_context.items():
93
+ setattr(record, key, value)
94
+ return True
95
+
96
+
97
+ def configure(log_config: dict = default_log_config):
98
+ """
99
+ Configure logging based on the provided configuration dictionary.
100
+ The dictionary should contain the logging configuration in a format compatible with `logging.config.dictConfig`.
101
+
102
+ :param log_config: A dictionary containing logging configuration.
103
+ :type log_config: dict
104
+ """
105
+ try:
106
+ config.dictConfig(log_config)
107
+
108
+ application_insights_connection_string = get_application_insights_connstr()
109
+ enable_application_insights_logger = (
110
+ os.environ.get(Constants.ENABLE_APPLICATION_INSIGHTS_LOGGER, "true").lower() == "true"
111
+ )
112
+ if application_insights_connection_string and enable_application_insights_logger:
113
+ from opentelemetry._logs import set_logger_provider
114
+ from opentelemetry.sdk._logs import (
115
+ LoggerProvider,
116
+ LoggingHandler,
117
+ )
118
+ from opentelemetry.sdk._logs.export import BatchLogRecordProcessor
119
+ from opentelemetry.sdk.resources import Resource
120
+
121
+ from azure.monitor.opentelemetry.exporter import AzureMonitorLogExporter
122
+
123
+ logger_provider = LoggerProvider(resource=Resource.create({"service.name": "azure.ai.agentserver"}))
124
+ set_logger_provider(logger_provider)
125
+
126
+ exporter = AzureMonitorLogExporter(connection_string=application_insights_connection_string)
127
+
128
+ logger_provider.add_log_record_processor(BatchLogRecordProcessor(exporter))
129
+ handler = LoggingHandler(logger_provider=logger_provider)
130
+ handler.name = "appinsights_handler"
131
+
132
+ # Add custom filter to inject dimensions
133
+ custom_filter = CustomDimensionsFilter()
134
+ handler.addFilter(custom_filter)
135
+
136
+ # Only add to azure.ai.agentserver namespace to avoid infrastructure logs
137
+ app_logger = logging.getLogger("azure.ai.agentserver")
138
+ app_logger.setLevel(get_log_level())
139
+ app_logger.addHandler(handler)
140
+
141
+ except Exception as e:
142
+ print(f"Failed to configure logging: {e}")
143
+
144
+
145
+ def get_log_level():
146
+ log_level = os.getenv(Constants.AGENT_LOG_LEVEL, "INFO").upper()
147
+ valid_levels = ["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"]
148
+ if log_level not in valid_levels:
149
+ print(f"Invalid log level '{log_level}' specified. Defaulting to 'INFO'.")
150
+ log_level = "INFO"
151
+ return log_level
152
+
153
+
154
+ def get_logger() -> logging.Logger:
155
+ """
156
+ If the logger is not already configured, it will be initialized with default settings.
157
+
158
+ :return: Configured logger instance.
159
+ :rtype: logging.Logger
160
+ """
161
+ return logging.getLogger("azure.ai.agentserver")
@@ -0,0 +1,7 @@
1
+ # ---------------------------------------------------------
2
+ # Copyright (c) Microsoft Corporation. All rights reserved.
3
+ # ---------------------------------------------------------
4
+ from ._create_response import CreateResponse # type: ignore
5
+ from .projects import Response, ResponseStreamEvent
6
+
7
+ __all__ = ["CreateResponse", "Response", "ResponseStreamEvent"] # type: ignore[var-annotated]
@@ -0,0 +1,12 @@
1
+ # ---------------------------------------------------------
2
+ # Copyright (c) Microsoft Corporation. All rights reserved.
3
+ # ---------------------------------------------------------
4
+ # pylint: disable=no-name-in-module
5
+ from typing import Optional
6
+
7
+ from .openai import response_create_params # type: ignore
8
+ from . import projects as _azure_ai_projects_models
9
+
10
+ class CreateResponse(response_create_params.ResponseCreateParamsBase, total=False): # type: ignore
11
+ agent: Optional[_azure_ai_projects_models.AgentReference]
12
+ stream: Optional[bool]
@@ -0,0 +1,16 @@
1
+ # ---------------------------------------------------------
2
+ # Copyright (c) Microsoft Corporation. All rights reserved.
3
+ # ---------------------------------------------------------
4
+ """
5
+ Re-exports of OpenAI SDK response types.
6
+
7
+ This module re-exports types from the OpenAI SDK for convenience.
8
+ These types are fully documented in the OpenAI SDK documentation.
9
+
10
+ .. note::
11
+ This module re-exports OpenAI SDK types. For detailed documentation,
12
+ please refer to the `OpenAI Python SDK documentation <https://github.com/openai/openai-python>`_.
13
+ """
14
+ from openai.types.responses import * # pylint: disable=unused-wildcard-import
15
+
16
+ __all__ = [name for name in globals() if not name.startswith("_")] # type: ignore[var-annotated]