ants-platform-sdk 3.7.0__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.
- ants_platform/__init__.py +52 -0
- ants_platform/_client/attributes.py +360 -0
- ants_platform/_client/client.py +3245 -0
- ants_platform/_client/constants.py +63 -0
- ants_platform/_client/datasets.py +183 -0
- ants_platform/_client/environment_variables.py +140 -0
- ants_platform/_client/get_client.py +134 -0
- ants_platform/_client/observe.py +530 -0
- ants_platform/_client/resource_manager.py +448 -0
- ants_platform/_client/span.py +2042 -0
- ants_platform/_client/span_processor.py +154 -0
- ants_platform/_client/utils.py +60 -0
- ants_platform/_crewai_bootstrap.py +47 -0
- ants_platform/_task_manager/media_manager.py +310 -0
- ants_platform/_task_manager/media_upload_consumer.py +44 -0
- ants_platform/_task_manager/media_upload_queue.py +12 -0
- ants_platform/_task_manager/score_ingestion_consumer.py +180 -0
- ants_platform/_utils/__init__.py +22 -0
- ants_platform/_utils/environment.py +34 -0
- ants_platform/_utils/error_logging.py +48 -0
- ants_platform/_utils/parse_error.py +101 -0
- ants_platform/_utils/prompt_cache.py +191 -0
- ants_platform/_utils/request.py +140 -0
- ants_platform/_utils/serializer.py +190 -0
- ants_platform/api/__init__.py +445 -0
- ants_platform/api/client.py +248 -0
- ants_platform/api/core/__init__.py +30 -0
- ants_platform/api/core/api_error.py +17 -0
- ants_platform/api/core/client_wrapper.py +120 -0
- ants_platform/api/core/datetime_utils.py +30 -0
- ants_platform/api/core/file.py +43 -0
- ants_platform/api/core/http_client.py +550 -0
- ants_platform/api/core/jsonable_encoder.py +108 -0
- ants_platform/api/core/pydantic_utilities.py +28 -0
- ants_platform/api/core/query_encoder.py +39 -0
- ants_platform/api/core/remove_none_from_dict.py +11 -0
- ants_platform/api/core/request_options.py +32 -0
- ants_platform/api/resources/__init__.py +459 -0
- ants_platform/api/resources/annotation_queues/__init__.py +33 -0
- ants_platform/api/resources/annotation_queues/client.py +1642 -0
- ants_platform/api/resources/annotation_queues/types/__init__.py +35 -0
- ants_platform/api/resources/annotation_queues/types/annotation_queue.py +49 -0
- ants_platform/api/resources/annotation_queues/types/annotation_queue_assignment_request.py +44 -0
- ants_platform/api/resources/annotation_queues/types/annotation_queue_item.py +55 -0
- ants_platform/api/resources/annotation_queues/types/annotation_queue_object_type.py +21 -0
- ants_platform/api/resources/annotation_queues/types/annotation_queue_status.py +21 -0
- ants_platform/api/resources/annotation_queues/types/create_annotation_queue_assignment_response.py +46 -0
- ants_platform/api/resources/annotation_queues/types/create_annotation_queue_item_request.py +51 -0
- ants_platform/api/resources/annotation_queues/types/create_annotation_queue_request.py +46 -0
- ants_platform/api/resources/annotation_queues/types/delete_annotation_queue_assignment_response.py +42 -0
- ants_platform/api/resources/annotation_queues/types/delete_annotation_queue_item_response.py +43 -0
- ants_platform/api/resources/annotation_queues/types/paginated_annotation_queue_items.py +45 -0
- ants_platform/api/resources/annotation_queues/types/paginated_annotation_queues.py +45 -0
- ants_platform/api/resources/annotation_queues/types/update_annotation_queue_item_request.py +43 -0
- ants_platform/api/resources/comments/__init__.py +5 -0
- ants_platform/api/resources/comments/client.py +520 -0
- ants_platform/api/resources/comments/types/__init__.py +7 -0
- ants_platform/api/resources/comments/types/create_comment_request.py +69 -0
- ants_platform/api/resources/comments/types/create_comment_response.py +45 -0
- ants_platform/api/resources/comments/types/get_comments_response.py +45 -0
- ants_platform/api/resources/commons/__init__.py +103 -0
- ants_platform/api/resources/commons/errors/__init__.py +15 -0
- ants_platform/api/resources/commons/errors/access_denied_error.py +10 -0
- ants_platform/api/resources/commons/errors/error.py +10 -0
- ants_platform/api/resources/commons/errors/method_not_allowed_error.py +10 -0
- ants_platform/api/resources/commons/errors/not_found_error.py +10 -0
- ants_platform/api/resources/commons/errors/unauthorized_error.py +10 -0
- ants_platform/api/resources/commons/types/__init__.py +83 -0
- ants_platform/api/resources/commons/types/base_score.py +79 -0
- ants_platform/api/resources/commons/types/base_score_v_1.py +73 -0
- ants_platform/api/resources/commons/types/boolean_score.py +53 -0
- ants_platform/api/resources/commons/types/boolean_score_v_1.py +53 -0
- ants_platform/api/resources/commons/types/categorical_score.py +53 -0
- ants_platform/api/resources/commons/types/categorical_score_v_1.py +53 -0
- ants_platform/api/resources/commons/types/comment.py +54 -0
- ants_platform/api/resources/commons/types/comment_object_type.py +29 -0
- ants_platform/api/resources/commons/types/config_category.py +43 -0
- ants_platform/api/resources/commons/types/create_score_value.py +5 -0
- ants_platform/api/resources/commons/types/dataset.py +50 -0
- ants_platform/api/resources/commons/types/dataset_item.py +61 -0
- ants_platform/api/resources/commons/types/dataset_run.py +82 -0
- ants_platform/api/resources/commons/types/dataset_run_item.py +53 -0
- ants_platform/api/resources/commons/types/dataset_run_with_items.py +48 -0
- ants_platform/api/resources/commons/types/dataset_status.py +21 -0
- ants_platform/api/resources/commons/types/map_value.py +10 -0
- ants_platform/api/resources/commons/types/model.py +112 -0
- ants_platform/api/resources/commons/types/model_price.py +42 -0
- ants_platform/api/resources/commons/types/model_usage_unit.py +41 -0
- ants_platform/api/resources/commons/types/numeric_score.py +48 -0
- ants_platform/api/resources/commons/types/numeric_score_v_1.py +48 -0
- ants_platform/api/resources/commons/types/observation.py +164 -0
- ants_platform/api/resources/commons/types/observation_level.py +29 -0
- ants_platform/api/resources/commons/types/observations_view.py +116 -0
- ants_platform/api/resources/commons/types/score.py +207 -0
- ants_platform/api/resources/commons/types/score_config.py +82 -0
- ants_platform/api/resources/commons/types/score_data_type.py +25 -0
- ants_platform/api/resources/commons/types/score_source.py +25 -0
- ants_platform/api/resources/commons/types/score_v_1.py +189 -0
- ants_platform/api/resources/commons/types/session.py +50 -0
- ants_platform/api/resources/commons/types/session_with_traces.py +46 -0
- ants_platform/api/resources/commons/types/trace.py +109 -0
- ants_platform/api/resources/commons/types/trace_with_details.py +68 -0
- ants_platform/api/resources/commons/types/trace_with_full_details.py +70 -0
- ants_platform/api/resources/commons/types/usage.py +84 -0
- ants_platform/api/resources/dataset_items/__init__.py +13 -0
- ants_platform/api/resources/dataset_items/client.py +640 -0
- ants_platform/api/resources/dataset_items/types/__init__.py +11 -0
- ants_platform/api/resources/dataset_items/types/create_dataset_item_request.py +65 -0
- ants_platform/api/resources/dataset_items/types/delete_dataset_item_response.py +45 -0
- ants_platform/api/resources/dataset_items/types/paginated_dataset_items.py +45 -0
- ants_platform/api/resources/dataset_run_items/__init__.py +5 -0
- ants_platform/api/resources/dataset_run_items/client.py +366 -0
- ants_platform/api/resources/dataset_run_items/types/__init__.py +6 -0
- ants_platform/api/resources/dataset_run_items/types/create_dataset_run_item_request.py +64 -0
- ants_platform/api/resources/dataset_run_items/types/paginated_dataset_run_items.py +45 -0
- ants_platform/api/resources/datasets/__init__.py +15 -0
- ants_platform/api/resources/datasets/client.py +942 -0
- ants_platform/api/resources/datasets/types/__init__.py +13 -0
- ants_platform/api/resources/datasets/types/create_dataset_request.py +44 -0
- ants_platform/api/resources/datasets/types/delete_dataset_run_response.py +42 -0
- ants_platform/api/resources/datasets/types/paginated_dataset_runs.py +45 -0
- ants_platform/api/resources/datasets/types/paginated_datasets.py +45 -0
- ants_platform/api/resources/health/__init__.py +6 -0
- ants_platform/api/resources/health/client.py +154 -0
- ants_platform/api/resources/health/errors/__init__.py +5 -0
- ants_platform/api/resources/health/errors/service_unavailable_error.py +8 -0
- ants_platform/api/resources/health/types/__init__.py +5 -0
- ants_platform/api/resources/health/types/health_response.py +58 -0
- ants_platform/api/resources/ingestion/__init__.py +91 -0
- ants_platform/api/resources/ingestion/client.py +260 -0
- ants_platform/api/resources/ingestion/types/__init__.py +91 -0
- ants_platform/api/resources/ingestion/types/base_event.py +55 -0
- ants_platform/api/resources/ingestion/types/create_event_body.py +45 -0
- ants_platform/api/resources/ingestion/types/create_event_event.py +46 -0
- ants_platform/api/resources/ingestion/types/create_generation_body.py +67 -0
- ants_platform/api/resources/ingestion/types/create_generation_event.py +46 -0
- ants_platform/api/resources/ingestion/types/create_observation_event.py +46 -0
- ants_platform/api/resources/ingestion/types/create_span_body.py +47 -0
- ants_platform/api/resources/ingestion/types/create_span_event.py +46 -0
- ants_platform/api/resources/ingestion/types/ingestion_error.py +45 -0
- ants_platform/api/resources/ingestion/types/ingestion_event.py +422 -0
- ants_platform/api/resources/ingestion/types/ingestion_response.py +45 -0
- ants_platform/api/resources/ingestion/types/ingestion_success.py +43 -0
- ants_platform/api/resources/ingestion/types/ingestion_usage.py +8 -0
- ants_platform/api/resources/ingestion/types/observation_body.py +77 -0
- ants_platform/api/resources/ingestion/types/observation_type.py +53 -0
- ants_platform/api/resources/ingestion/types/open_ai_completion_usage_schema.py +54 -0
- ants_platform/api/resources/ingestion/types/open_ai_response_usage_schema.py +52 -0
- ants_platform/api/resources/ingestion/types/open_ai_usage.py +56 -0
- ants_platform/api/resources/ingestion/types/optional_observation_body.py +61 -0
- ants_platform/api/resources/ingestion/types/score_body.py +88 -0
- ants_platform/api/resources/ingestion/types/score_event.py +46 -0
- ants_platform/api/resources/ingestion/types/sdk_log_body.py +42 -0
- ants_platform/api/resources/ingestion/types/sdk_log_event.py +46 -0
- ants_platform/api/resources/ingestion/types/trace_body.py +61 -0
- ants_platform/api/resources/ingestion/types/trace_event.py +46 -0
- ants_platform/api/resources/ingestion/types/update_event_body.py +45 -0
- ants_platform/api/resources/ingestion/types/update_generation_body.py +67 -0
- ants_platform/api/resources/ingestion/types/update_generation_event.py +46 -0
- ants_platform/api/resources/ingestion/types/update_observation_event.py +46 -0
- ants_platform/api/resources/ingestion/types/update_span_body.py +47 -0
- ants_platform/api/resources/ingestion/types/update_span_event.py +46 -0
- ants_platform/api/resources/ingestion/types/usage_details.py +10 -0
- ants_platform/api/resources/llm_connections/__init__.py +15 -0
- ants_platform/api/resources/llm_connections/client.py +340 -0
- ants_platform/api/resources/llm_connections/types/__init__.py +13 -0
- ants_platform/api/resources/llm_connections/types/llm_adapter.py +37 -0
- ants_platform/api/resources/llm_connections/types/llm_connection.py +85 -0
- ants_platform/api/resources/llm_connections/types/paginated_llm_connections.py +45 -0
- ants_platform/api/resources/llm_connections/types/upsert_llm_connection_request.py +88 -0
- ants_platform/api/resources/media/__init__.py +17 -0
- ants_platform/api/resources/media/client.py +505 -0
- ants_platform/api/resources/media/types/__init__.py +15 -0
- ants_platform/api/resources/media/types/get_media_response.py +72 -0
- ants_platform/api/resources/media/types/get_media_upload_url_request.py +71 -0
- ants_platform/api/resources/media/types/get_media_upload_url_response.py +54 -0
- ants_platform/api/resources/media/types/media_content_type.py +133 -0
- ants_platform/api/resources/media/types/patch_media_body.py +66 -0
- ants_platform/api/resources/metrics/__init__.py +5 -0
- ants_platform/api/resources/metrics/client.py +245 -0
- ants_platform/api/resources/metrics/types/__init__.py +5 -0
- ants_platform/api/resources/metrics/types/metrics_response.py +47 -0
- ants_platform/api/resources/models/__init__.py +5 -0
- ants_platform/api/resources/models/client.py +607 -0
- ants_platform/api/resources/models/types/__init__.py +6 -0
- ants_platform/api/resources/models/types/create_model_request.py +100 -0
- ants_platform/api/resources/models/types/paginated_models.py +45 -0
- ants_platform/api/resources/observations/__init__.py +5 -0
- ants_platform/api/resources/observations/client.py +428 -0
- ants_platform/api/resources/observations/types/__init__.py +6 -0
- ants_platform/api/resources/observations/types/observations.py +45 -0
- ants_platform/api/resources/observations/types/observations_views.py +45 -0
- ants_platform/api/resources/organizations/__init__.py +19 -0
- ants_platform/api/resources/organizations/client.py +750 -0
- ants_platform/api/resources/organizations/types/__init__.py +17 -0
- ants_platform/api/resources/organizations/types/membership_request.py +46 -0
- ants_platform/api/resources/organizations/types/membership_response.py +48 -0
- ants_platform/api/resources/organizations/types/membership_role.py +29 -0
- ants_platform/api/resources/organizations/types/memberships_response.py +43 -0
- ants_platform/api/resources/organizations/types/organization_project.py +48 -0
- ants_platform/api/resources/organizations/types/organization_projects_response.py +43 -0
- ants_platform/api/resources/projects/__init__.py +21 -0
- ants_platform/api/resources/projects/client.py +1090 -0
- ants_platform/api/resources/projects/types/__init__.py +19 -0
- ants_platform/api/resources/projects/types/api_key_deletion_response.py +46 -0
- ants_platform/api/resources/projects/types/api_key_list.py +49 -0
- ants_platform/api/resources/projects/types/api_key_response.py +53 -0
- ants_platform/api/resources/projects/types/api_key_summary.py +58 -0
- ants_platform/api/resources/projects/types/project.py +56 -0
- ants_platform/api/resources/projects/types/project_deletion_response.py +43 -0
- ants_platform/api/resources/projects/types/projects.py +43 -0
- ants_platform/api/resources/prompt_version/__init__.py +2 -0
- ants_platform/api/resources/prompt_version/client.py +197 -0
- ants_platform/api/resources/prompts/__init__.py +43 -0
- ants_platform/api/resources/prompts/client.py +585 -0
- ants_platform/api/resources/prompts/types/__init__.py +43 -0
- ants_platform/api/resources/prompts/types/base_prompt.py +69 -0
- ants_platform/api/resources/prompts/types/chat_message.py +43 -0
- ants_platform/api/resources/prompts/types/chat_message_with_placeholders.py +87 -0
- ants_platform/api/resources/prompts/types/chat_prompt.py +46 -0
- ants_platform/api/resources/prompts/types/create_chat_prompt_request.py +63 -0
- ants_platform/api/resources/prompts/types/create_prompt_request.py +103 -0
- ants_platform/api/resources/prompts/types/create_text_prompt_request.py +62 -0
- ants_platform/api/resources/prompts/types/placeholder_message.py +42 -0
- ants_platform/api/resources/prompts/types/prompt.py +111 -0
- ants_platform/api/resources/prompts/types/prompt_meta.py +52 -0
- ants_platform/api/resources/prompts/types/prompt_meta_list_response.py +45 -0
- ants_platform/api/resources/prompts/types/text_prompt.py +45 -0
- ants_platform/api/resources/scim/__init__.py +41 -0
- ants_platform/api/resources/scim/client.py +1042 -0
- ants_platform/api/resources/scim/types/__init__.py +39 -0
- ants_platform/api/resources/scim/types/authentication_scheme.py +48 -0
- ants_platform/api/resources/scim/types/bulk_config.py +46 -0
- ants_platform/api/resources/scim/types/empty_response.py +44 -0
- ants_platform/api/resources/scim/types/filter_config.py +45 -0
- ants_platform/api/resources/scim/types/resource_meta.py +45 -0
- ants_platform/api/resources/scim/types/resource_type.py +55 -0
- ants_platform/api/resources/scim/types/resource_types_response.py +47 -0
- ants_platform/api/resources/scim/types/schema_extension.py +45 -0
- ants_platform/api/resources/scim/types/schema_resource.py +47 -0
- ants_platform/api/resources/scim/types/schemas_response.py +47 -0
- ants_platform/api/resources/scim/types/scim_email.py +44 -0
- ants_platform/api/resources/scim/types/scim_feature_support.py +42 -0
- ants_platform/api/resources/scim/types/scim_name.py +42 -0
- ants_platform/api/resources/scim/types/scim_user.py +52 -0
- ants_platform/api/resources/scim/types/scim_users_list_response.py +49 -0
- ants_platform/api/resources/scim/types/service_provider_config.py +60 -0
- ants_platform/api/resources/scim/types/user_meta.py +48 -0
- ants_platform/api/resources/score/__init__.py +5 -0
- ants_platform/api/resources/score/client.py +322 -0
- ants_platform/api/resources/score/types/__init__.py +6 -0
- ants_platform/api/resources/score/types/create_score_request.py +92 -0
- ants_platform/api/resources/score/types/create_score_response.py +45 -0
- ants_platform/api/resources/score_configs/__init__.py +5 -0
- ants_platform/api/resources/score_configs/client.py +473 -0
- ants_platform/api/resources/score_configs/types/__init__.py +6 -0
- ants_platform/api/resources/score_configs/types/create_score_config_request.py +72 -0
- ants_platform/api/resources/score_configs/types/score_configs.py +45 -0
- ants_platform/api/resources/score_v_2/__init__.py +25 -0
- ants_platform/api/resources/score_v_2/client.py +463 -0
- ants_platform/api/resources/score_v_2/types/__init__.py +25 -0
- ants_platform/api/resources/score_v_2/types/get_scores_response.py +45 -0
- ants_platform/api/resources/score_v_2/types/get_scores_response_data.py +215 -0
- ants_platform/api/resources/score_v_2/types/get_scores_response_data_boolean.py +46 -0
- ants_platform/api/resources/score_v_2/types/get_scores_response_data_categorical.py +46 -0
- ants_platform/api/resources/score_v_2/types/get_scores_response_data_numeric.py +46 -0
- ants_platform/api/resources/score_v_2/types/get_scores_response_trace_data.py +57 -0
- ants_platform/api/resources/sessions/__init__.py +5 -0
- ants_platform/api/resources/sessions/client.py +367 -0
- ants_platform/api/resources/sessions/types/__init__.py +5 -0
- ants_platform/api/resources/sessions/types/paginated_sessions.py +45 -0
- ants_platform/api/resources/trace/__init__.py +5 -0
- ants_platform/api/resources/trace/client.py +725 -0
- ants_platform/api/resources/trace/types/__init__.py +7 -0
- ants_platform/api/resources/trace/types/delete_trace_response.py +42 -0
- ants_platform/api/resources/trace/types/sort.py +42 -0
- ants_platform/api/resources/trace/types/traces.py +45 -0
- ants_platform/api/resources/utils/__init__.py +5 -0
- ants_platform/api/resources/utils/resources/__init__.py +6 -0
- ants_platform/api/resources/utils/resources/pagination/__init__.py +5 -0
- ants_platform/api/resources/utils/resources/pagination/types/__init__.py +5 -0
- ants_platform/api/resources/utils/resources/pagination/types/meta_response.py +62 -0
- ants_platform/api/tests/utils/test_http_client.py +59 -0
- ants_platform/api/tests/utils/test_query_encoding.py +19 -0
- ants_platform/cli/__init__.py +1 -0
- ants_platform/cli/onboard.py +203 -0
- ants_platform/crewai/__init__.py +3 -0
- ants_platform/crewai/event_listener.py +1132 -0
- ants_platform/guardrails/__init__.py +84 -0
- ants_platform/guardrails/_tracing.py +288 -0
- ants_platform/guardrails/client.py +426 -0
- ants_platform/guardrails/errors.py +51 -0
- ants_platform/guardrails/frameworks.py +158 -0
- ants_platform/guardrails/providers/__init__.py +7 -0
- ants_platform/guardrails/providers/_guardrail_utils.py +135 -0
- ants_platform/guardrails/providers/_tool_calls.py +82 -0
- ants_platform/guardrails/providers/anthropic.py +210 -0
- ants_platform/guardrails/providers/bedrock.py +212 -0
- ants_platform/guardrails/providers/google_genai.py +252 -0
- ants_platform/guardrails/providers/openai_provider.py +222 -0
- ants_platform/guardrails/providers/vertex.py +261 -0
- ants_platform/guardrails/tool_rules.py +375 -0
- ants_platform/guardrails/tools.py +425 -0
- ants_platform/guardrails/types.py +82 -0
- ants_platform/langchain/CallbackHandler.py +1381 -0
- ants_platform/langchain/__init__.py +5 -0
- ants_platform/langchain/utils.py +212 -0
- ants_platform/logger.py +28 -0
- ants_platform/media.py +342 -0
- ants_platform/model.py +494 -0
- ants_platform/openai.py +1341 -0
- ants_platform/py.typed +0 -0
- ants_platform/types.py +86 -0
- ants_platform/version.py +3 -0
- ants_platform_sdk-3.7.0.data/data/ants_platform_crewai.pth +1 -0
- ants_platform_sdk-3.7.0.dist-info/METADATA +48 -0
- ants_platform_sdk-3.7.0.dist-info/RECORD +321 -0
- ants_platform_sdk-3.7.0.dist-info/WHEEL +5 -0
- ants_platform_sdk-3.7.0.dist-info/entry_points.txt +2 -0
- ants_platform_sdk-3.7.0.dist-info/licenses/LICENSE +21 -0
- ants_platform_sdk-3.7.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
""".. include:: ../README.md"""
|
|
2
|
+
|
|
3
|
+
from ._client import client as _client_module
|
|
4
|
+
from ._client.attributes import AntsPlatformOtelSpanAttributes
|
|
5
|
+
from ._client.constants import ObservationTypeLiteral
|
|
6
|
+
from ._client.get_client import get_client
|
|
7
|
+
from ._client.observe import observe
|
|
8
|
+
from ._client.span import (
|
|
9
|
+
AntsPlatformEvent,
|
|
10
|
+
AntsPlatformGeneration,
|
|
11
|
+
AntsPlatformSpan,
|
|
12
|
+
AntsPlatformAgent,
|
|
13
|
+
AntsPlatformTool,
|
|
14
|
+
AntsPlatformChain,
|
|
15
|
+
AntsPlatformEmbedding,
|
|
16
|
+
AntsPlatformEvaluator,
|
|
17
|
+
AntsPlatformRetriever,
|
|
18
|
+
AntsPlatformGuardrail,
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
AntsPlatform = _client_module.AntsPlatform
|
|
22
|
+
|
|
23
|
+
# Guardrails (available as ants_platform.guardrails or top-level imports)
|
|
24
|
+
from .guardrails import ( # noqa: E402
|
|
25
|
+
AntsGuardrailsClient,
|
|
26
|
+
GuardrailViolationError,
|
|
27
|
+
GuardrailResult,
|
|
28
|
+
Violation,
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
__all__ = [
|
|
32
|
+
"AntsPlatform",
|
|
33
|
+
"get_client",
|
|
34
|
+
"observe",
|
|
35
|
+
"ObservationTypeLiteral",
|
|
36
|
+
"AntsPlatformSpan",
|
|
37
|
+
"AntsPlatformGeneration",
|
|
38
|
+
"AntsPlatformEvent",
|
|
39
|
+
"AntsPlatformOtelSpanAttributes",
|
|
40
|
+
"AntsPlatformAgent",
|
|
41
|
+
"AntsPlatformTool",
|
|
42
|
+
"AntsPlatformChain",
|
|
43
|
+
"AntsPlatformEmbedding",
|
|
44
|
+
"AntsPlatformEvaluator",
|
|
45
|
+
"AntsPlatformRetriever",
|
|
46
|
+
"AntsPlatformGuardrail",
|
|
47
|
+
# Guardrails
|
|
48
|
+
"AntsGuardrailsClient",
|
|
49
|
+
"GuardrailViolationError",
|
|
50
|
+
"GuardrailResult",
|
|
51
|
+
"Violation",
|
|
52
|
+
]
|
|
@@ -0,0 +1,360 @@
|
|
|
1
|
+
"""Span attribute management for AntsPlatform OpenTelemetry integration.
|
|
2
|
+
|
|
3
|
+
This module defines constants and functions for managing OpenTelemetry span attributes
|
|
4
|
+
used by AntsPlatform. It provides a structured approach to creating and manipulating
|
|
5
|
+
attributes for different span types (trace, span, generation) while ensuring consistency.
|
|
6
|
+
|
|
7
|
+
The module includes:
|
|
8
|
+
- Attribute name constants organized by category
|
|
9
|
+
- Functions to create attribute dictionaries for different entity types
|
|
10
|
+
- Utilities for serializing and processing attribute values
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
import hashlib
|
|
14
|
+
import json
|
|
15
|
+
import logging
|
|
16
|
+
import warnings
|
|
17
|
+
from datetime import datetime
|
|
18
|
+
from typing import Any, Dict, List, Literal, Optional, Union
|
|
19
|
+
|
|
20
|
+
from ants_platform._client.constants import (
|
|
21
|
+
ObservationTypeGenerationLike,
|
|
22
|
+
ObservationTypeSpanLike,
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
from ants_platform._utils.serializer import EventSerializer
|
|
26
|
+
from ants_platform.model import PromptClient
|
|
27
|
+
from ants_platform.types import MapValue, SpanLevel
|
|
28
|
+
|
|
29
|
+
# Agent name validation constants
|
|
30
|
+
AGENT_NAME_MAX_LENGTH = 255
|
|
31
|
+
|
|
32
|
+
# Configure logger
|
|
33
|
+
logger = logging.getLogger(__name__)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
class AntsPlatformOtelSpanAttributes:
|
|
37
|
+
# AntsPlatform-Trace attributes
|
|
38
|
+
TRACE_NAME = "ants_platform.trace.name"
|
|
39
|
+
TRACE_USER_ID = "user.id"
|
|
40
|
+
TRACE_SESSION_ID = "session.id"
|
|
41
|
+
TRACE_TAGS = "ants_platform.trace.tags"
|
|
42
|
+
TRACE_PUBLIC = "ants_platform.trace.public"
|
|
43
|
+
TRACE_METADATA = "ants_platform.trace.metadata"
|
|
44
|
+
TRACE_INPUT = "ants_platform.trace.input"
|
|
45
|
+
TRACE_OUTPUT = "ants_platform.trace.output"
|
|
46
|
+
|
|
47
|
+
# AntsPlatform-observation attributes
|
|
48
|
+
OBSERVATION_TYPE = "ants_platform.observation.type"
|
|
49
|
+
OBSERVATION_METADATA = "ants_platform.observation.metadata"
|
|
50
|
+
OBSERVATION_LEVEL = "ants_platform.observation.level"
|
|
51
|
+
OBSERVATION_STATUS_MESSAGE = "ants_platform.observation.status_message"
|
|
52
|
+
OBSERVATION_INPUT = "ants_platform.observation.input"
|
|
53
|
+
OBSERVATION_OUTPUT = "ants_platform.observation.output"
|
|
54
|
+
|
|
55
|
+
# AntsPlatform-observation of type Generation attributes
|
|
56
|
+
OBSERVATION_COMPLETION_START_TIME = "ants_platform.observation.completion_start_time"
|
|
57
|
+
OBSERVATION_MODEL = "ants_platform.observation.model.name"
|
|
58
|
+
OBSERVATION_MODEL_PARAMETERS = "ants_platform.observation.model.parameters"
|
|
59
|
+
OBSERVATION_USAGE_DETAILS = "ants_platform.observation.usage_details"
|
|
60
|
+
OBSERVATION_COST_DETAILS = "ants_platform.observation.cost_details"
|
|
61
|
+
OBSERVATION_PROMPT_NAME = "ants_platform.observation.prompt.name"
|
|
62
|
+
OBSERVATION_PROMPT_VERSION = "ants_platform.observation.prompt.version"
|
|
63
|
+
|
|
64
|
+
# General
|
|
65
|
+
ENVIRONMENT = "ants_platform.environment"
|
|
66
|
+
RELEASE = "ants_platform.release"
|
|
67
|
+
VERSION = "ants_platform.version"
|
|
68
|
+
|
|
69
|
+
# Agent identification attributes
|
|
70
|
+
AGENT_ID = "ants_platform.agent.id"
|
|
71
|
+
AGENT_NAME = "ants_platform.agent.name"
|
|
72
|
+
AGENT_DISPLAY_NAME = "ants_platform.agent.display_name"
|
|
73
|
+
|
|
74
|
+
# Internal
|
|
75
|
+
AS_ROOT = "ants_platform.internal.as_root"
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def validate_and_normalize_agent_name(agent_name: Optional[str]) -> Optional[str]:
|
|
79
|
+
"""Validate and normalize agent_name to lowercase snake_case.
|
|
80
|
+
|
|
81
|
+
Applies the following transformations:
|
|
82
|
+
1. Strip whitespace
|
|
83
|
+
2. Convert to lowercase for consistency (Python PEP 8 snake_case convention)
|
|
84
|
+
3. Validate max length (255 chars), truncate with warning if exceeded
|
|
85
|
+
4. Convert empty strings to None
|
|
86
|
+
|
|
87
|
+
Args:
|
|
88
|
+
agent_name: Raw agent name string
|
|
89
|
+
|
|
90
|
+
Returns:
|
|
91
|
+
Normalized agent name (lowercase) or None if invalid/empty
|
|
92
|
+
|
|
93
|
+
Examples:
|
|
94
|
+
>>> validate_and_normalize_agent_name("QA_Agent")
|
|
95
|
+
"qa_agent"
|
|
96
|
+
>>> validate_and_normalize_agent_name("qa_agent")
|
|
97
|
+
"qa_agent"
|
|
98
|
+
>>> validate_and_normalize_agent_name(" QA_Agent ")
|
|
99
|
+
"qa_agent"
|
|
100
|
+
>>> validate_and_normalize_agent_name("")
|
|
101
|
+
None
|
|
102
|
+
>>> validate_and_normalize_agent_name("A" * 300) # Truncates to 255 with warning
|
|
103
|
+
"aaa..."
|
|
104
|
+
"""
|
|
105
|
+
if agent_name is None:
|
|
106
|
+
return None
|
|
107
|
+
|
|
108
|
+
# Strip whitespace
|
|
109
|
+
agent_name = agent_name.strip()
|
|
110
|
+
|
|
111
|
+
# Convert empty strings to None
|
|
112
|
+
if not agent_name:
|
|
113
|
+
return None
|
|
114
|
+
|
|
115
|
+
# Normalize to lowercase for consistency (Python PEP 8 snake_case convention)
|
|
116
|
+
agent_name = agent_name.lower()
|
|
117
|
+
|
|
118
|
+
# Validate max length and truncate if needed
|
|
119
|
+
if len(agent_name) > AGENT_NAME_MAX_LENGTH:
|
|
120
|
+
original_length = len(agent_name)
|
|
121
|
+
agent_name = agent_name[:AGENT_NAME_MAX_LENGTH]
|
|
122
|
+
warning_message = (
|
|
123
|
+
f"agent_name exceeds maximum length of {AGENT_NAME_MAX_LENGTH} characters "
|
|
124
|
+
f"(was {original_length} chars). Truncated to: '{agent_name}'"
|
|
125
|
+
)
|
|
126
|
+
warnings.warn(warning_message, UserWarning, stacklevel=3)
|
|
127
|
+
|
|
128
|
+
return agent_name
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
def generate_agent_id(agent_name: str, project_id: str) -> str:
|
|
132
|
+
"""Generate a stable 16-character hexadecimal agent_id from agent_name and project_id using BLAKE2b-128.
|
|
133
|
+
|
|
134
|
+
The agent_id is a deterministic hash of both agent_name and project_id, ensuring:
|
|
135
|
+
1. Same agent_name in same project = same agent_id (deterministic)
|
|
136
|
+
2. Same agent_name in different projects = different agent_id (project-scoped)
|
|
137
|
+
3. Transfer-safe: projectId doesn't change, so agent_id stays stable
|
|
138
|
+
|
|
139
|
+
Args:
|
|
140
|
+
agent_name: Normalized agent name (should be already validated and normalized)
|
|
141
|
+
project_id: The project ID this agent belongs to
|
|
142
|
+
|
|
143
|
+
Returns:
|
|
144
|
+
str: 16 lowercase hexadecimal characters (64 bits)
|
|
145
|
+
|
|
146
|
+
Examples:
|
|
147
|
+
>>> generate_agent_id("qa_agent", "project-123")
|
|
148
|
+
"a1b2c3d4e5f6g7h8"
|
|
149
|
+
>>> generate_agent_id("qa_agent", "project-123") # Same = same output
|
|
150
|
+
"a1b2c3d4e5f6g7h8"
|
|
151
|
+
>>> generate_agent_id("qa_agent", "project-456") # Different project
|
|
152
|
+
"x9y8z7w6v5u4t3s2"
|
|
153
|
+
|
|
154
|
+
Note:
|
|
155
|
+
Uses BLAKE2b with 8-byte digest (64 bits) to produce 16 hex characters.
|
|
156
|
+
BLAKE2b is faster than SHA-256 and designed for exactly this use case.
|
|
157
|
+
"""
|
|
158
|
+
# Validate inputs
|
|
159
|
+
if not agent_name or not isinstance(agent_name, str):
|
|
160
|
+
raise ValueError("agent_name must be a non-empty string")
|
|
161
|
+
|
|
162
|
+
if not project_id or not isinstance(project_id, str):
|
|
163
|
+
raise ValueError("project_id must be a non-empty string")
|
|
164
|
+
|
|
165
|
+
# Use BLAKE2b with 8-byte digest (64 bits = 16 hex characters)
|
|
166
|
+
# Hash both agent_name and project_id for project-scoped agent IDs
|
|
167
|
+
hasher = hashlib.blake2b(digest_size=8)
|
|
168
|
+
hasher.update(agent_name.encode('utf-8'))
|
|
169
|
+
hasher.update(project_id.encode('utf-8'))
|
|
170
|
+
agent_id = hasher.hexdigest()
|
|
171
|
+
|
|
172
|
+
logger.info(f"[AGENT_ID] Generated: {agent_id} from agent_name: {agent_name}")
|
|
173
|
+
|
|
174
|
+
return agent_id
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
def create_trace_attributes(
|
|
178
|
+
*,
|
|
179
|
+
name: Optional[str] = None,
|
|
180
|
+
user_id: Optional[str] = None,
|
|
181
|
+
session_id: Optional[str] = None,
|
|
182
|
+
agent_name: Optional[str] = None,
|
|
183
|
+
agent_display_name: Optional[str] = None,
|
|
184
|
+
agent_id: Optional[str] = None,
|
|
185
|
+
project_id: Optional[str] = None,
|
|
186
|
+
version: Optional[str] = None,
|
|
187
|
+
release: Optional[str] = None,
|
|
188
|
+
input: Optional[Any] = None,
|
|
189
|
+
output: Optional[Any] = None,
|
|
190
|
+
metadata: Optional[Any] = None,
|
|
191
|
+
tags: Optional[List[str]] = None,
|
|
192
|
+
public: Optional[bool] = None,
|
|
193
|
+
) -> dict:
|
|
194
|
+
"""Create trace attributes with agent identification.
|
|
195
|
+
|
|
196
|
+
Agent Identity Flow:
|
|
197
|
+
- agent_name (immutable): Stable identifier used for agent_id generation
|
|
198
|
+
- agent_display_name (mutable): Optional user-facing name stored in PostgreSQL
|
|
199
|
+
- agent_id: Auto-generated 16-char hex hash of agent_name + project_id using BLAKE2b-64
|
|
200
|
+
|
|
201
|
+
If only agent_name is provided, it serves as both identifier and display name.
|
|
202
|
+
"""
|
|
203
|
+
# Validate and normalize agent_name
|
|
204
|
+
agent_name = validate_and_normalize_agent_name(agent_name)
|
|
205
|
+
|
|
206
|
+
# Generate agent_id from agent_name if agent_name exists but agent_id doesn't
|
|
207
|
+
# Note: This is a fallback; agent_id should be generated in span.py with project_id
|
|
208
|
+
if agent_name and not agent_id:
|
|
209
|
+
if not project_id:
|
|
210
|
+
raise ValueError(
|
|
211
|
+
"project_id is required for agent_id generation. "
|
|
212
|
+
"This is an internal error - agent_id should be generated in span.py."
|
|
213
|
+
)
|
|
214
|
+
agent_id = generate_agent_id(agent_name, project_id)
|
|
215
|
+
logger.info(f"[AGENT_ID] Auto-generated for trace: agent_id={agent_id}, agent_name={agent_name}, project_id={project_id}, agent_display_name={agent_display_name}")
|
|
216
|
+
|
|
217
|
+
attributes = {
|
|
218
|
+
AntsPlatformOtelSpanAttributes.TRACE_NAME: name,
|
|
219
|
+
AntsPlatformOtelSpanAttributes.TRACE_USER_ID: user_id,
|
|
220
|
+
AntsPlatformOtelSpanAttributes.TRACE_SESSION_ID: session_id,
|
|
221
|
+
AntsPlatformOtelSpanAttributes.AGENT_NAME: agent_name,
|
|
222
|
+
AntsPlatformOtelSpanAttributes.AGENT_ID: agent_id,
|
|
223
|
+
AntsPlatformOtelSpanAttributes.AGENT_DISPLAY_NAME: agent_display_name,
|
|
224
|
+
AntsPlatformOtelSpanAttributes.VERSION: version,
|
|
225
|
+
AntsPlatformOtelSpanAttributes.RELEASE: release,
|
|
226
|
+
AntsPlatformOtelSpanAttributes.TRACE_INPUT: _serialize(input),
|
|
227
|
+
AntsPlatformOtelSpanAttributes.TRACE_OUTPUT: _serialize(output),
|
|
228
|
+
AntsPlatformOtelSpanAttributes.TRACE_TAGS: tags,
|
|
229
|
+
AntsPlatformOtelSpanAttributes.TRACE_PUBLIC: public,
|
|
230
|
+
**_flatten_and_serialize_metadata(metadata, "trace"),
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
return {k: v for k, v in attributes.items() if v is not None}
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
def create_span_attributes(
|
|
237
|
+
*,
|
|
238
|
+
metadata: Optional[Any] = None,
|
|
239
|
+
input: Optional[Any] = None,
|
|
240
|
+
output: Optional[Any] = None,
|
|
241
|
+
level: Optional[SpanLevel] = None,
|
|
242
|
+
status_message: Optional[str] = None,
|
|
243
|
+
version: Optional[str] = None,
|
|
244
|
+
agent_name: Optional[str] = None,
|
|
245
|
+
agent_display_name: Optional[str] = None,
|
|
246
|
+
agent_id: Optional[str] = None,
|
|
247
|
+
observation_type: Optional[
|
|
248
|
+
Union[ObservationTypeSpanLike, Literal["event"]]
|
|
249
|
+
] = "span",
|
|
250
|
+
) -> dict:
|
|
251
|
+
# Validate and normalize agent_name
|
|
252
|
+
agent_name = validate_and_normalize_agent_name(agent_name)
|
|
253
|
+
|
|
254
|
+
# Note: agent_id should always be provided by span.py when agent_name is provided
|
|
255
|
+
# This function does NOT generate agent_id - that happens in span.py with project_id
|
|
256
|
+
# If agent_name exists but agent_id doesn't, it's an internal error that should be caught in span.py
|
|
257
|
+
|
|
258
|
+
attributes = {
|
|
259
|
+
AntsPlatformOtelSpanAttributes.OBSERVATION_TYPE: observation_type,
|
|
260
|
+
AntsPlatformOtelSpanAttributes.OBSERVATION_LEVEL: level,
|
|
261
|
+
AntsPlatformOtelSpanAttributes.OBSERVATION_STATUS_MESSAGE: status_message,
|
|
262
|
+
AntsPlatformOtelSpanAttributes.VERSION: version,
|
|
263
|
+
AntsPlatformOtelSpanAttributes.AGENT_NAME: agent_name,
|
|
264
|
+
AntsPlatformOtelSpanAttributes.AGENT_ID: agent_id,
|
|
265
|
+
AntsPlatformOtelSpanAttributes.AGENT_DISPLAY_NAME: agent_display_name,
|
|
266
|
+
AntsPlatformOtelSpanAttributes.OBSERVATION_INPUT: _serialize(input),
|
|
267
|
+
AntsPlatformOtelSpanAttributes.OBSERVATION_OUTPUT: _serialize(output),
|
|
268
|
+
**_flatten_and_serialize_metadata(metadata, "observation"),
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
return {k: v for k, v in attributes.items() if v is not None}
|
|
272
|
+
|
|
273
|
+
|
|
274
|
+
def create_generation_attributes(
|
|
275
|
+
*,
|
|
276
|
+
name: Optional[str] = None,
|
|
277
|
+
completion_start_time: Optional[datetime] = None,
|
|
278
|
+
metadata: Optional[Any] = None,
|
|
279
|
+
level: Optional[SpanLevel] = None,
|
|
280
|
+
status_message: Optional[str] = None,
|
|
281
|
+
version: Optional[str] = None,
|
|
282
|
+
agent_name: Optional[str] = None,
|
|
283
|
+
agent_display_name: Optional[str] = None,
|
|
284
|
+
agent_id: Optional[str] = None,
|
|
285
|
+
model: Optional[str] = None,
|
|
286
|
+
model_parameters: Optional[Dict[str, MapValue]] = None,
|
|
287
|
+
input: Optional[Any] = None,
|
|
288
|
+
output: Optional[Any] = None,
|
|
289
|
+
usage_details: Optional[Dict[str, int]] = None,
|
|
290
|
+
cost_details: Optional[Dict[str, float]] = None,
|
|
291
|
+
prompt: Optional[PromptClient] = None,
|
|
292
|
+
observation_type: Optional[ObservationTypeGenerationLike] = "generation",
|
|
293
|
+
) -> dict:
|
|
294
|
+
# Validate and normalize agent_name
|
|
295
|
+
agent_name = validate_and_normalize_agent_name(agent_name)
|
|
296
|
+
|
|
297
|
+
# Note: agent_id should always be provided by span.py when agent_name is provided
|
|
298
|
+
# This function does NOT generate agent_id - that happens in span.py with project_id
|
|
299
|
+
# If agent_name exists but agent_id doesn't, it's an internal error that should be caught in span.py
|
|
300
|
+
|
|
301
|
+
attributes = {
|
|
302
|
+
AntsPlatformOtelSpanAttributes.OBSERVATION_TYPE: observation_type,
|
|
303
|
+
AntsPlatformOtelSpanAttributes.OBSERVATION_LEVEL: level,
|
|
304
|
+
AntsPlatformOtelSpanAttributes.OBSERVATION_STATUS_MESSAGE: status_message,
|
|
305
|
+
AntsPlatformOtelSpanAttributes.VERSION: version,
|
|
306
|
+
AntsPlatformOtelSpanAttributes.AGENT_NAME: agent_name,
|
|
307
|
+
AntsPlatformOtelSpanAttributes.AGENT_ID: agent_id,
|
|
308
|
+
AntsPlatformOtelSpanAttributes.AGENT_DISPLAY_NAME: agent_display_name,
|
|
309
|
+
AntsPlatformOtelSpanAttributes.OBSERVATION_INPUT: _serialize(input),
|
|
310
|
+
AntsPlatformOtelSpanAttributes.OBSERVATION_OUTPUT: _serialize(output),
|
|
311
|
+
AntsPlatformOtelSpanAttributes.OBSERVATION_MODEL: model,
|
|
312
|
+
AntsPlatformOtelSpanAttributes.OBSERVATION_PROMPT_NAME: prompt.name
|
|
313
|
+
if prompt and not prompt.is_fallback
|
|
314
|
+
else None,
|
|
315
|
+
AntsPlatformOtelSpanAttributes.OBSERVATION_PROMPT_VERSION: prompt.version
|
|
316
|
+
if prompt and not prompt.is_fallback
|
|
317
|
+
else None,
|
|
318
|
+
AntsPlatformOtelSpanAttributes.OBSERVATION_USAGE_DETAILS: _serialize(usage_details),
|
|
319
|
+
AntsPlatformOtelSpanAttributes.OBSERVATION_COST_DETAILS: _serialize(cost_details),
|
|
320
|
+
AntsPlatformOtelSpanAttributes.OBSERVATION_COMPLETION_START_TIME: _serialize(
|
|
321
|
+
completion_start_time
|
|
322
|
+
),
|
|
323
|
+
AntsPlatformOtelSpanAttributes.OBSERVATION_MODEL_PARAMETERS: _serialize(
|
|
324
|
+
model_parameters
|
|
325
|
+
),
|
|
326
|
+
**_flatten_and_serialize_metadata(metadata, "observation"),
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
return {k: v for k, v in attributes.items() if v is not None}
|
|
330
|
+
|
|
331
|
+
|
|
332
|
+
def _serialize(obj: Any) -> Optional[str]:
|
|
333
|
+
if obj is None or isinstance(obj, str):
|
|
334
|
+
return obj
|
|
335
|
+
|
|
336
|
+
return json.dumps(obj, cls=EventSerializer)
|
|
337
|
+
|
|
338
|
+
|
|
339
|
+
def _flatten_and_serialize_metadata(
|
|
340
|
+
metadata: Any, type: Literal["observation", "trace"]
|
|
341
|
+
) -> dict:
|
|
342
|
+
prefix = (
|
|
343
|
+
AntsPlatformOtelSpanAttributes.OBSERVATION_METADATA
|
|
344
|
+
if type == "observation"
|
|
345
|
+
else AntsPlatformOtelSpanAttributes.TRACE_METADATA
|
|
346
|
+
)
|
|
347
|
+
|
|
348
|
+
metadata_attributes: Dict[str, Union[str, int, None]] = {}
|
|
349
|
+
|
|
350
|
+
if not isinstance(metadata, dict):
|
|
351
|
+
metadata_attributes[prefix] = _serialize(metadata)
|
|
352
|
+
else:
|
|
353
|
+
for key, value in metadata.items():
|
|
354
|
+
metadata_attributes[f"{prefix}.{key}"] = (
|
|
355
|
+
value
|
|
356
|
+
if isinstance(value, str) or isinstance(value, int)
|
|
357
|
+
else _serialize(value)
|
|
358
|
+
)
|
|
359
|
+
|
|
360
|
+
return metadata_attributes
|