gatewaysdk 0.3.2__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.
- gatewaysdk/__init__.py +540 -0
- gatewaysdk/adapter/__init__.py +15 -0
- gatewaysdk/adapter/base.py +94 -0
- gatewaysdk/adapter/messages.py +270 -0
- gatewaysdk/adapter/triplet.py +1026 -0
- gatewaysdk/algorithm/__init__.py +39 -0
- gatewaysdk/algorithm/apo/__init__.py +5 -0
- gatewaysdk/algorithm/apo/apo.py +898 -0
- gatewaysdk/algorithm/apo/prompts/apply_edit_variant01.poml +22 -0
- gatewaysdk/algorithm/apo/prompts/apply_edit_variant02.poml +18 -0
- gatewaysdk/algorithm/apo/prompts/text_gradient_variant01.poml +18 -0
- gatewaysdk/algorithm/apo/prompts/text_gradient_variant02.poml +16 -0
- gatewaysdk/algorithm/apo/prompts/text_gradient_variant03.poml +107 -0
- gatewaysdk/algorithm/base.py +262 -0
- gatewaysdk/algorithm/decorator.py +264 -0
- gatewaysdk/algorithm/evals/__init__.py +7 -0
- gatewaysdk/algorithm/evals/evals.py +217 -0
- gatewaysdk/algorithm/fast.py +250 -0
- gatewaysdk/algorithm/gepa/__init__.py +61 -0
- gatewaysdk/algorithm/gepa/adapter.py +495 -0
- gatewaysdk/algorithm/gepa/gepa.py +570 -0
- gatewaysdk/algorithm/gepa/lib/__init__.py +18 -0
- gatewaysdk/algorithm/gepa/lib/adapters/README.md +12 -0
- gatewaysdk/algorithm/gepa/lib/adapters/__init__.py +0 -0
- gatewaysdk/algorithm/gepa/lib/adapters/anymaths_adapter/README.md +341 -0
- gatewaysdk/algorithm/gepa/lib/adapters/anymaths_adapter/__init__.py +1 -0
- gatewaysdk/algorithm/gepa/lib/adapters/anymaths_adapter/anymaths_adapter.py +174 -0
- gatewaysdk/algorithm/gepa/lib/adapters/anymaths_adapter/requirements.txt +1 -0
- gatewaysdk/algorithm/gepa/lib/adapters/default_adapter/README.md +0 -0
- gatewaysdk/algorithm/gepa/lib/adapters/default_adapter/__init__.py +0 -0
- gatewaysdk/algorithm/gepa/lib/adapters/default_adapter/default_adapter.py +209 -0
- gatewaysdk/algorithm/gepa/lib/adapters/dspy_adapter/README.md +7 -0
- gatewaysdk/algorithm/gepa/lib/adapters/dspy_adapter/__init__.py +0 -0
- gatewaysdk/algorithm/gepa/lib/adapters/dspy_adapter/dspy_adapter.py +307 -0
- gatewaysdk/algorithm/gepa/lib/adapters/dspy_full_program_adapter/README.md +99 -0
- gatewaysdk/algorithm/gepa/lib/adapters/dspy_full_program_adapter/dspy_program_proposal_signature.py +137 -0
- gatewaysdk/algorithm/gepa/lib/adapters/dspy_full_program_adapter/full_program_adapter.py +268 -0
- gatewaysdk/algorithm/gepa/lib/adapters/generic_rag_adapter/GEPA_RAG.md +621 -0
- gatewaysdk/algorithm/gepa/lib/adapters/generic_rag_adapter/__init__.py +56 -0
- gatewaysdk/algorithm/gepa/lib/adapters/generic_rag_adapter/evaluation_metrics.py +226 -0
- gatewaysdk/algorithm/gepa/lib/adapters/generic_rag_adapter/generic_rag_adapter.py +496 -0
- gatewaysdk/algorithm/gepa/lib/adapters/generic_rag_adapter/rag_pipeline.py +238 -0
- gatewaysdk/algorithm/gepa/lib/adapters/generic_rag_adapter/vector_store_interface.py +212 -0
- gatewaysdk/algorithm/gepa/lib/adapters/generic_rag_adapter/vector_stores/__init__.py +2 -0
- gatewaysdk/algorithm/gepa/lib/adapters/generic_rag_adapter/vector_stores/chroma_store.py +196 -0
- gatewaysdk/algorithm/gepa/lib/adapters/generic_rag_adapter/vector_stores/lancedb_store.py +422 -0
- gatewaysdk/algorithm/gepa/lib/adapters/generic_rag_adapter/vector_stores/milvus_store.py +409 -0
- gatewaysdk/algorithm/gepa/lib/adapters/generic_rag_adapter/vector_stores/qdrant_store.py +368 -0
- gatewaysdk/algorithm/gepa/lib/adapters/generic_rag_adapter/vector_stores/weaviate_store.py +418 -0
- gatewaysdk/algorithm/gepa/lib/adapters/mcp_adapter/README.md +552 -0
- gatewaysdk/algorithm/gepa/lib/adapters/mcp_adapter/__init__.py +37 -0
- gatewaysdk/algorithm/gepa/lib/adapters/mcp_adapter/mcp_adapter.py +699 -0
- gatewaysdk/algorithm/gepa/lib/adapters/mcp_adapter/mcp_client.py +364 -0
- gatewaysdk/algorithm/gepa/lib/adapters/terminal_bench_adapter/README.md +9 -0
- gatewaysdk/algorithm/gepa/lib/adapters/terminal_bench_adapter/__init__.py +0 -0
- gatewaysdk/algorithm/gepa/lib/adapters/terminal_bench_adapter/terminal_bench_adapter.py +217 -0
- gatewaysdk/algorithm/gepa/lib/api.py +382 -0
- gatewaysdk/algorithm/gepa/lib/core/__init__.py +0 -0
- gatewaysdk/algorithm/gepa/lib/core/adapter.py +180 -0
- gatewaysdk/algorithm/gepa/lib/core/data_loader.py +74 -0
- gatewaysdk/algorithm/gepa/lib/core/engine.py +379 -0
- gatewaysdk/algorithm/gepa/lib/core/result.py +233 -0
- gatewaysdk/algorithm/gepa/lib/core/state.py +636 -0
- gatewaysdk/algorithm/gepa/lib/examples/__init__.py +0 -0
- gatewaysdk/algorithm/gepa/lib/examples/aime.py +24 -0
- gatewaysdk/algorithm/gepa/lib/examples/anymaths-bench/eval_default.py +111 -0
- gatewaysdk/algorithm/gepa/lib/examples/anymaths-bench/prompt-templates/instruction_prompt.txt +9 -0
- gatewaysdk/algorithm/gepa/lib/examples/anymaths-bench/prompt-templates/optimal_prompt.txt +24 -0
- gatewaysdk/algorithm/gepa/lib/examples/anymaths-bench/train_anymaths.py +177 -0
- gatewaysdk/algorithm/gepa/lib/examples/dspy_full_program_evolution/arc_agi.ipynb +25705 -0
- gatewaysdk/algorithm/gepa/lib/examples/dspy_full_program_evolution/example.ipynb +348 -0
- gatewaysdk/algorithm/gepa/lib/examples/mcp_adapter/__init__.py +4 -0
- gatewaysdk/algorithm/gepa/lib/examples/mcp_adapter/mcp_optimization_example.py +456 -0
- gatewaysdk/algorithm/gepa/lib/examples/rag_adapter/RAG_GUIDE.md +613 -0
- gatewaysdk/algorithm/gepa/lib/examples/rag_adapter/__init__.py +9 -0
- gatewaysdk/algorithm/gepa/lib/examples/rag_adapter/rag_optimization.py +820 -0
- gatewaysdk/algorithm/gepa/lib/examples/rag_adapter/requirements-rag.txt +29 -0
- gatewaysdk/algorithm/gepa/lib/examples/terminal-bench/prompt-templates/instruction_prompt.txt +16 -0
- gatewaysdk/algorithm/gepa/lib/examples/terminal-bench/prompt-templates/terminus.txt +9 -0
- gatewaysdk/algorithm/gepa/lib/examples/terminal-bench/train_terminus.py +161 -0
- gatewaysdk/algorithm/gepa/lib/gepa_utils.py +117 -0
- gatewaysdk/algorithm/gepa/lib/logging/__init__.py +0 -0
- gatewaysdk/algorithm/gepa/lib/logging/experiment_tracker.py +187 -0
- gatewaysdk/algorithm/gepa/lib/logging/logger.py +75 -0
- gatewaysdk/algorithm/gepa/lib/logging/utils.py +103 -0
- gatewaysdk/algorithm/gepa/lib/proposer/__init__.py +0 -0
- gatewaysdk/algorithm/gepa/lib/proposer/base.py +31 -0
- gatewaysdk/algorithm/gepa/lib/proposer/merge.py +357 -0
- gatewaysdk/algorithm/gepa/lib/proposer/reflective_mutation/__init__.py +0 -0
- gatewaysdk/algorithm/gepa/lib/proposer/reflective_mutation/base.py +49 -0
- gatewaysdk/algorithm/gepa/lib/proposer/reflective_mutation/reflective_mutation.py +176 -0
- gatewaysdk/algorithm/gepa/lib/py.typed +0 -0
- gatewaysdk/algorithm/gepa/lib/strategies/__init__.py +0 -0
- gatewaysdk/algorithm/gepa/lib/strategies/batch_sampler.py +77 -0
- gatewaysdk/algorithm/gepa/lib/strategies/candidate_selector.py +50 -0
- gatewaysdk/algorithm/gepa/lib/strategies/component_selector.py +36 -0
- gatewaysdk/algorithm/gepa/lib/strategies/eval_policy.py +64 -0
- gatewaysdk/algorithm/gepa/lib/strategies/instruction_proposal.py +126 -0
- gatewaysdk/algorithm/gepa/lib/utils/__init__.py +10 -0
- gatewaysdk/algorithm/gepa/lib/utils/stop_condition.py +196 -0
- gatewaysdk/algorithm/gepa/tracing.py +105 -0
- gatewaysdk/algorithm/utils.py +177 -0
- gatewaysdk/algorithm/verl/__init__.py +5 -0
- gatewaysdk/algorithm/verl/interface.py +202 -0
- gatewaysdk/automations.py +111 -0
- gatewaysdk/benchmark_hub/README.md +88 -0
- gatewaysdk/benchmark_hub/__init__.py +119 -0
- gatewaysdk/benchmark_hub/_archive.py +189 -0
- gatewaysdk/benchmark_hub/_tar.py +6 -0
- gatewaysdk/benchmark_hub/client.py +992 -0
- gatewaysdk/benchmark_hub/dispatch_shard.py +34 -0
- gatewaysdk/benchmark_hub/eval_config.py +20 -0
- gatewaysdk/benchmark_hub/evals.py +351 -0
- gatewaysdk/benchmark_hub/harbor_adapter.py +673 -0
- gatewaysdk/benchmark_hub/path_utils.py +81 -0
- gatewaysdk/benchmark_hub/save_utils.py +101 -0
- gatewaysdk/benchmark_hub/verifiers_adapter.py +327 -0
- gatewaysdk/benchmark_hub/versioning.py +72 -0
- gatewaysdk/build.py +515 -0
- gatewaysdk/cli/__init__.py +58 -0
- gatewaysdk/cli/agent_runner.py +132 -0
- gatewaysdk/cli/http_client.py +115 -0
- gatewaysdk/cli/platform.py +4086 -0
- gatewaysdk/cli/prometheus.py +115 -0
- gatewaysdk/cli/release_gate.py +215 -0
- gatewaysdk/cli/store.py +131 -0
- gatewaysdk/cli/vllm.py +29 -0
- gatewaysdk/client.py +406 -0
- gatewaysdk/config.py +348 -0
- gatewaysdk/connectors/__init__.py +25 -0
- gatewaysdk/connectors/client.py +203 -0
- gatewaysdk/connectors/skill.py +25 -0
- gatewaysdk/connectors/template.py +106 -0
- gatewaysdk/context.py +606 -0
- gatewaysdk/emitter/__init__.py +43 -0
- gatewaysdk/emitter/annotation.py +370 -0
- gatewaysdk/emitter/exception.py +54 -0
- gatewaysdk/emitter/message.py +61 -0
- gatewaysdk/emitter/object.py +117 -0
- gatewaysdk/emitter/reward.py +320 -0
- gatewaysdk/env_var.py +156 -0
- gatewaysdk/environment/__init__.py +108 -0
- gatewaysdk/environment/_bundle.py +281 -0
- gatewaysdk/environment/_harbor.py +276 -0
- gatewaysdk/environment/_materialize.py +97 -0
- gatewaysdk/environment/_tar.py +33 -0
- gatewaysdk/environment/_world.py +346 -0
- gatewaysdk/environment/core.py +527 -0
- gatewaysdk/environment/errors.py +58 -0
- gatewaysdk/environment/runtime.py +150 -0
- gatewaysdk/environment/schema/__init__.py +35 -0
- gatewaysdk/environment/schema/__main__.py +225 -0
- gatewaysdk/environment/schema/_slack_fidelity.py +116 -0
- gatewaysdk/environment/schema/_slack_scenario.py +183 -0
- gatewaysdk/environment/schema/api.py +1628 -0
- gatewaysdk/environment/schema/batch.py +755 -0
- gatewaysdk/environment/schema/compiler.py +615 -0
- gatewaysdk/environment/schema/conform.py +428 -0
- gatewaysdk/environment/schema/connector.py +777 -0
- gatewaysdk/environment/schema/connectors/apple-business-manager/handlers.py +17 -0
- gatewaysdk/environment/schema/connectors/apple-business-manager/parity.json +28 -0
- gatewaysdk/environment/schema/connectors/apple-business-manager/provenance.json +233 -0
- gatewaysdk/environment/schema/connectors/apple-business-manager/scope.toml +112 -0
- gatewaysdk/environment/schema/connectors/apple-business-manager/world.json +1380 -0
- gatewaysdk/environment/schema/connectors/base.json +28 -0
- gatewaysdk/environment/schema/connectors/custom/handlers.py +18 -0
- gatewaysdk/environment/schema/connectors/custom/world.json +123 -0
- gatewaysdk/environment/schema/connectors/github/handlers.py +81 -0
- gatewaysdk/environment/schema/connectors/github/parity.json +37 -0
- gatewaysdk/environment/schema/connectors/github/provenance.json +134 -0
- gatewaysdk/environment/schema/connectors/github/scope.toml +158 -0
- gatewaysdk/environment/schema/connectors/github/world.json +5869 -0
- gatewaysdk/environment/schema/connectors/google-calendar/handlers.py +23 -0
- gatewaysdk/environment/schema/connectors/google-calendar/world.json +209 -0
- gatewaysdk/environment/schema/connectors/google-drive/handlers.py +18 -0
- gatewaysdk/environment/schema/connectors/google-drive/world.json +286 -0
- gatewaysdk/environment/schema/connectors/jamf/handlers.py +34 -0
- gatewaysdk/environment/schema/connectors/jamf/parity.json +49 -0
- gatewaysdk/environment/schema/connectors/jamf/provenance.json +181 -0
- gatewaysdk/environment/schema/connectors/jamf/scope.toml +128 -0
- gatewaysdk/environment/schema/connectors/jamf/world.json +2218 -0
- gatewaysdk/environment/schema/connectors/jira/handlers.py +28 -0
- gatewaysdk/environment/schema/connectors/jira/world.json +389 -0
- gatewaysdk/environment/schema/connectors/kandji/handlers.py +38 -0
- gatewaysdk/environment/schema/connectors/kandji/parity.json +29 -0
- gatewaysdk/environment/schema/connectors/kandji/provenance.json +152 -0
- gatewaysdk/environment/schema/connectors/kandji/scope.toml +120 -0
- gatewaysdk/environment/schema/connectors/kandji/world.json +765 -0
- gatewaysdk/environment/schema/connectors/linear/handlers.py +20 -0
- gatewaysdk/environment/schema/connectors/linear/world.json +363 -0
- gatewaysdk/environment/schema/connectors/microsoft-teams/fidelity.json +45 -0
- gatewaysdk/environment/schema/connectors/microsoft-teams/handlers.py +1 -0
- gatewaysdk/environment/schema/connectors/microsoft-teams/provenance.json +851 -0
- gatewaysdk/environment/schema/connectors/microsoft-teams/scope.md +231 -0
- gatewaysdk/environment/schema/connectors/microsoft-teams/teams-types.json +1710 -0
- gatewaysdk/environment/schema/connectors/microsoft-teams/world.json +858 -0
- gatewaysdk/environment/schema/connectors/netsuite/handlers.py +32 -0
- gatewaysdk/environment/schema/connectors/netsuite/parity.json +50 -0
- gatewaysdk/environment/schema/connectors/netsuite/provenance.json +137 -0
- gatewaysdk/environment/schema/connectors/netsuite/scope.toml +78 -0
- gatewaysdk/environment/schema/connectors/netsuite/world.json +16243 -0
- gatewaysdk/environment/schema/connectors/salesforce/handlers.py +806 -0
- gatewaysdk/environment/schema/connectors/salesforce/parity.json +46 -0
- gatewaysdk/environment/schema/connectors/salesforce/provenance.json +143 -0
- gatewaysdk/environment/schema/connectors/salesforce/scope.toml +174 -0
- gatewaysdk/environment/schema/connectors/salesforce/world.json +4695 -0
- gatewaysdk/environment/schema/connectors/slack/MODEL.md +236 -0
- gatewaysdk/environment/schema/connectors/slack/capabilities.json +1039 -0
- gatewaysdk/environment/schema/connectors/slack/handlers.py +762 -0
- gatewaysdk/environment/schema/connectors/slack/parity.json +65 -0
- gatewaysdk/environment/schema/connectors/slack/provenance.json +294 -0
- gatewaysdk/environment/schema/connectors/slack/scope.toml +44 -0
- gatewaysdk/environment/schema/connectors/slack/world.json +4993 -0
- gatewaysdk/environment/schema/connectors/workday/handlers.py +75 -0
- gatewaysdk/environment/schema/connectors/workday/parity.json +36 -0
- gatewaysdk/environment/schema/connectors/workday/provenance.json +179 -0
- gatewaysdk/environment/schema/connectors/workday/scope.toml +180 -0
- gatewaysdk/environment/schema/connectors/workday/world.json +806 -0
- gatewaysdk/environment/schema/data.py +593 -0
- gatewaysdk/environment/schema/extract.py +263 -0
- gatewaysdk/environment/schema/host.py +2437 -0
- gatewaysdk/environment/schema/host_surfaces.py +275 -0
- gatewaysdk/environment/schema/platform.py +1272 -0
- gatewaysdk/environment/schema/scaffold.py +250 -0
- gatewaysdk/environment/schema/skill.py +118 -0
- gatewaysdk/environment/schema/skills/agents/connector-template-author.md +202 -0
- gatewaysdk/environment/schema/skills/connector-schema-authoring/CONNECTORS.md +331 -0
- gatewaysdk/environment/schema/skills/connector-schema-authoring/CONVENTIONS.md +100 -0
- gatewaysdk/environment/schema/skills/connector-schema-authoring/SKILL.md +313 -0
- gatewaysdk/environment/schema/skills/world-data-ingestion/ROWS.md +223 -0
- gatewaysdk/environment/schema/skills/world-data-ingestion/SKILL.md +293 -0
- gatewaysdk/environment/schema/skills/worlds-getting-started/SKILL.md +390 -0
- gatewaysdk/environment/schema/slack.py +757 -0
- gatewaysdk/environment/schema/snapshot.py +479 -0
- gatewaysdk/environment/schema/store.py +904 -0
- gatewaysdk/environment/schema/tasks.py +525 -0
- gatewaysdk/environment/schema/tools_world.py +322 -0
- gatewaysdk/environment/schema/validation.py +577 -0
- gatewaysdk/environment/schema/worker.py +78 -0
- gatewaysdk/environment/schema/workers.py +500 -0
- gatewaysdk/environment/schema/world_tests.py +336 -0
- gatewaysdk/environments/__init__.py +24 -0
- gatewaysdk/environments/client.py +486 -0
- gatewaysdk/environments/types.py +318 -0
- gatewaysdk/execution/__init__.py +15 -0
- gatewaysdk/execution/base.py +64 -0
- gatewaysdk/execution/client_server.py +443 -0
- gatewaysdk/execution/events.py +69 -0
- gatewaysdk/execution/inter_process.py +16 -0
- gatewaysdk/execution/shared_memory.py +282 -0
- gatewaysdk/experiments/__init__.py +90 -0
- gatewaysdk/experiments/assignment.py +177 -0
- gatewaysdk/experiments/client.py +877 -0
- gatewaysdk/experiments/exposure.py +222 -0
- gatewaysdk/experiments/types.py +81 -0
- gatewaysdk/importers/__init__.py +49 -0
- gatewaysdk/importers/_normalize.py +91 -0
- gatewaysdk/importers/builder.py +173 -0
- gatewaysdk/importers/client.py +95 -0
- gatewaysdk/importers/langsmith.py +196 -0
- gatewaysdk/importers/recipes.py +249 -0
- gatewaysdk/instrumentation/__init__.py +300 -0
- gatewaysdk/instrumentation/agentops.py +314 -0
- gatewaysdk/instrumentation/agentops_langchain.py +45 -0
- gatewaysdk/instrumentation/base.py +119 -0
- gatewaysdk/instrumentation/litellm.py +83 -0
- gatewaysdk/instrumentation/registry.py +273 -0
- gatewaysdk/instrumentation/vllm.py +81 -0
- gatewaysdk/instrumentation/weave.py +500 -0
- gatewaysdk/integrations/__init__.py +15 -0
- gatewaysdk/integrations/gateway/__init__.py +11 -0
- gatewaysdk/integrations/gateway/client.py +171 -0
- gatewaysdk/integrations/tool_access.py +549 -0
- gatewaysdk/litagent/__init__.py +11 -0
- gatewaysdk/litagent/decorator.py +536 -0
- gatewaysdk/litagent/litagent.py +252 -0
- gatewaysdk/llm_proxy.py +1742 -0
- gatewaysdk/logging.py +370 -0
- gatewaysdk/memory.py +278 -0
- gatewaysdk/personas.py +186 -0
- gatewaysdk/platform/__init__.py +17 -0
- gatewaysdk/platform/builder.py +221 -0
- gatewaysdk/platform/compatibility.py +67 -0
- gatewaysdk/platform/manifest.py +185 -0
- gatewaysdk/platform/orchestrator.py +901 -0
- gatewaysdk/platform/registry.py +122 -0
- gatewaysdk/platform/worker.py +864 -0
- gatewaysdk/replay/__init__.py +1032 -0
- gatewaysdk/replay/pytest.py +56 -0
- gatewaysdk/reward.py +7 -0
- gatewaysdk/run.py +1781 -0
- gatewaysdk/runner/__init__.py +11 -0
- gatewaysdk/runner/agent.py +878 -0
- gatewaysdk/runner/base.py +182 -0
- gatewaysdk/runner/legacy.py +309 -0
- gatewaysdk/security.py +700 -0
- gatewaysdk/semconv.py +170 -0
- gatewaysdk/server.py +399 -0
- gatewaysdk/sessions.py +282 -0
- gatewaysdk/store/__init__.py +45 -0
- gatewaysdk/store/base.py +908 -0
- gatewaysdk/store/client_server.py +2093 -0
- gatewaysdk/store/collection/__init__.py +30 -0
- gatewaysdk/store/collection/base.py +587 -0
- gatewaysdk/store/collection/memory.py +970 -0
- gatewaysdk/store/collection/mongo.py +1412 -0
- gatewaysdk/store/collection_based.py +1823 -0
- gatewaysdk/store/gateway.py +983 -0
- gatewaysdk/store/gateway_listener.py +465 -0
- gatewaysdk/store/listener.py +58 -0
- gatewaysdk/store/memory.py +396 -0
- gatewaysdk/store/mongo.py +165 -0
- gatewaysdk/store/redis_stream.py +517 -0
- gatewaysdk/store/sqlite.py +3 -0
- gatewaysdk/store/threading.py +370 -0
- gatewaysdk/store/utils.py +142 -0
- gatewaysdk/tracer/__init__.py +14 -0
- gatewaysdk/tracer/base.py +286 -0
- gatewaysdk/tracer/dummy.py +106 -0
- gatewaysdk/tracer/otel.py +559 -0
- gatewaysdk/tracing/__init__.py +110 -0
- gatewaysdk/tracing/api.py +808 -0
- gatewaysdk/tracing/attributes.py +9 -0
- gatewaysdk/tracing/context.py +272 -0
- gatewaysdk/tracing/exporters/__init__.py +10 -0
- gatewaysdk/tracing/exporters/gateway.py +228 -0
- gatewaysdk/tracing/identity.py +288 -0
- gatewaysdk/tracing/init.py +620 -0
- gatewaysdk/tracing/instrumentors/__init__.py +15 -0
- gatewaysdk/tracing/instrumentors/claude_agent_sdk.py +766 -0
- gatewaysdk/tracing/instrumentors/instrumentation_principles.md +294 -0
- gatewaysdk/tracing/instrumentors/registry.py +352 -0
- gatewaysdk/tracing/mapping.py +729 -0
- gatewaysdk/tracing/processors.py +393 -0
- gatewaysdk/tracing/push.py +617 -0
- gatewaysdk/tracing/push_models.py +247 -0
- gatewaysdk/tracing/semconv.py +294 -0
- gatewaysdk/tracing/span_builder.py +356 -0
- gatewaysdk/trainer/__init__.py +6 -0
- gatewaysdk/trainer/init_utils.py +263 -0
- gatewaysdk/trainer/legacy.py +359 -0
- gatewaysdk/trainer/registry.py +12 -0
- gatewaysdk/trainer/trainer.py +638 -0
- gatewaysdk/types/__init__.py +63 -0
- gatewaysdk/types/core.py +556 -0
- gatewaysdk/types/resources.py +204 -0
- gatewaysdk/types/tracer.py +515 -0
- gatewaysdk/types/tracing.py +162 -0
- gatewaysdk/users.py +251 -0
- gatewaysdk/utils/__init__.py +1 -0
- gatewaysdk/utils/id.py +18 -0
- gatewaysdk/utils/metrics.py +1025 -0
- gatewaysdk/utils/otel.py +550 -0
- gatewaysdk/utils/otlp.py +556 -0
- gatewaysdk/utils/redact.py +22 -0
- gatewaysdk/utils/server_launcher.py +1045 -0
- gatewaysdk/utils/system_snapshot.py +90 -0
- gatewaysdk/verl/__init__.py +8 -0
- gatewaysdk/verl/__main__.py +6 -0
- gatewaysdk/verl/async_server.py +46 -0
- gatewaysdk/verl/config.yaml +27 -0
- gatewaysdk/verl/daemon.py +1154 -0
- gatewaysdk/verl/dataset.py +44 -0
- gatewaysdk/verl/entrypoint.py +248 -0
- gatewaysdk/verl/trainer.py +549 -0
- gatewaysdk/world_browser.py +748 -0
- gatewaysdk/world_data.py +453 -0
- gatewaysdk/world_sessions.py +978 -0
- gatewaysdk/world_tasks.py +285 -0
- gatewaysdk/world_tools.py +115 -0
- gatewaysdk/worlds.py +639 -0
- gatewaysdk-0.3.2.dist-info/METADATA +236 -0
- gatewaysdk-0.3.2.dist-info/RECORD +376 -0
- gatewaysdk-0.3.2.dist-info/WHEEL +4 -0
- gatewaysdk-0.3.2.dist-info/entry_points.txt +5 -0
- gatewaysdk-0.3.2.dist-info/licenses/LICENSE +19 -0
gatewaysdk/__init__.py
ADDED
|
@@ -0,0 +1,540 @@
|
|
|
1
|
+
# Copyright (c) Microsoft. All rights reserved.
|
|
2
|
+
|
|
3
|
+
"""GatewaySDK's public package surface.
|
|
4
|
+
|
|
5
|
+
The package root deliberately owns names, not feature initialization. Python
|
|
6
|
+
executes this file before every ``gatewaysdk.*`` submodule import, so eager
|
|
7
|
+
re-exports here make a narrow Memory or tracing consumer initialize the runner,
|
|
8
|
+
training, proxy, server, and GPU-monitoring graphs. PEP 562 module attribute
|
|
9
|
+
hooks keep the historical root-level imports while loading only the module that
|
|
10
|
+
owns the requested name.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
from __future__ import annotations
|
|
14
|
+
|
|
15
|
+
from importlib import import_module as _import_module
|
|
16
|
+
from typing import TYPE_CHECKING as _TYPE_CHECKING
|
|
17
|
+
|
|
18
|
+
if _TYPE_CHECKING:
|
|
19
|
+
# Static analyzers need concrete symbols; this branch is never evaluated by
|
|
20
|
+
# Python and therefore does not compromise the runtime import boundary.
|
|
21
|
+
from .adapter import * # noqa: F401,F403
|
|
22
|
+
from .algorithm import * # noqa: F401,F403
|
|
23
|
+
from .automations import AutomationClient, AutomationClientError # noqa: F401
|
|
24
|
+
from .sessions import ( # noqa: F401
|
|
25
|
+
SessionLoadError,
|
|
26
|
+
SessionObservation,
|
|
27
|
+
SessionRecording,
|
|
28
|
+
SessionTrace,
|
|
29
|
+
load_session,
|
|
30
|
+
)
|
|
31
|
+
from .replay import ( # noqa: F401
|
|
32
|
+
ReplayCase,
|
|
33
|
+
ReplayCheck,
|
|
34
|
+
ReplaySuite,
|
|
35
|
+
ToolStubRegistry,
|
|
36
|
+
run_suite,
|
|
37
|
+
)
|
|
38
|
+
from .client import DevTaskLoader, GatewayClient # noqa: F401
|
|
39
|
+
from .config import * # noqa: F401,F403
|
|
40
|
+
from .context import ( # noqa: F401
|
|
41
|
+
GatewayContext,
|
|
42
|
+
GatewayContextConfig,
|
|
43
|
+
GatewayContextConflictError,
|
|
44
|
+
GatewayContextError,
|
|
45
|
+
render_agent_system,
|
|
46
|
+
)
|
|
47
|
+
from .emitter import * # noqa: F401,F403
|
|
48
|
+
from .env_var import * # noqa: F401,F403
|
|
49
|
+
from .execution import * # noqa: F401,F403
|
|
50
|
+
from .instrumentation import ( # noqa: F401
|
|
51
|
+
Instrumentor,
|
|
52
|
+
InstrumentorRegistry,
|
|
53
|
+
MetricSchema,
|
|
54
|
+
instrument,
|
|
55
|
+
instrument_all,
|
|
56
|
+
uninstrument,
|
|
57
|
+
uninstrument_all,
|
|
58
|
+
)
|
|
59
|
+
from .integrations import ( # noqa: F401
|
|
60
|
+
GatewayToolAccess,
|
|
61
|
+
GatewayToolAccessConfig,
|
|
62
|
+
GatewayToolAccessError,
|
|
63
|
+
GatewayToolSubjectType,
|
|
64
|
+
)
|
|
65
|
+
from .integrations.gateway import GatewayIngestionClient, GatewayIngestionConfig # noqa: F401
|
|
66
|
+
from .litagent import * # noqa: F401,F403
|
|
67
|
+
from .llm_proxy import LLMProxy # noqa: F401
|
|
68
|
+
from .logging import configure_logger # noqa: F401
|
|
69
|
+
from .logging import setup as setup_logging # noqa: F401
|
|
70
|
+
from .logging import setup_module as setup_module_logging # noqa: F401
|
|
71
|
+
from .memory import ( # noqa: F401
|
|
72
|
+
GatewayMemory,
|
|
73
|
+
GatewayMemoryConfig,
|
|
74
|
+
GatewayMemoryConflictError,
|
|
75
|
+
GatewayMemoryError,
|
|
76
|
+
)
|
|
77
|
+
from .personas import Persona, PersonaError, PersonaReply, PersonasClient # noqa: F401
|
|
78
|
+
from .run import ( # noqa: F401
|
|
79
|
+
GatewayRunError,
|
|
80
|
+
Metric,
|
|
81
|
+
Run,
|
|
82
|
+
episode,
|
|
83
|
+
experiment,
|
|
84
|
+
finish,
|
|
85
|
+
get_current_rollout,
|
|
86
|
+
get_current_run,
|
|
87
|
+
init_run,
|
|
88
|
+
log,
|
|
89
|
+
run,
|
|
90
|
+
score,
|
|
91
|
+
success,
|
|
92
|
+
)
|
|
93
|
+
from .runner import * # noqa: F401,F403
|
|
94
|
+
from .security import ( # noqa: F401
|
|
95
|
+
GatewayAgentDescriptor,
|
|
96
|
+
GatewaySecurity,
|
|
97
|
+
GatewaySecurityConfig,
|
|
98
|
+
GatewaySecurityError,
|
|
99
|
+
GatewayToolApprovalRequiredError,
|
|
100
|
+
GatewayToolBlockedError,
|
|
101
|
+
GuardedMcpSession,
|
|
102
|
+
)
|
|
103
|
+
from .server import GatewayServer # noqa: F401
|
|
104
|
+
from .store import * # noqa: F401,F403
|
|
105
|
+
from .tracer import * # noqa: F401,F403
|
|
106
|
+
from .tracing.identity import identify # noqa: F401
|
|
107
|
+
from .trainer import * # noqa: F401,F403
|
|
108
|
+
from .types import * # noqa: F401,F403
|
|
109
|
+
from .users import UserEvent, UserProfile, UserProfileError, UsersClient # noqa: F401
|
|
110
|
+
from .build import define_tool, register_artifact, register_prompt, register_skill # noqa: F401
|
|
111
|
+
|
|
112
|
+
__version__ = "0.3.2"
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
# module: public names. Keep this explicit: wildcard ownership made additions
|
|
116
|
+
# to an internal module silently become package-root API.
|
|
117
|
+
_LAZY_EXPORT_GROUPS: dict[str, tuple[str, ...]] = {
|
|
118
|
+
".adapter": (
|
|
119
|
+
"Adapter",
|
|
120
|
+
"LlmProxyTraceToTriplet",
|
|
121
|
+
"OtelTraceAdapter",
|
|
122
|
+
"TraceAdapter",
|
|
123
|
+
"TraceToMessages",
|
|
124
|
+
"TraceToTripletBase",
|
|
125
|
+
"TracerTraceToTriplet",
|
|
126
|
+
),
|
|
127
|
+
".algorithm": ("APO", "Algorithm", "Baseline", "FastAlgorithm", "GEPA", "GEPAAdapter", "VERL", "algo"),
|
|
128
|
+
".automations": ("AutomationClient", "AutomationClientError"),
|
|
129
|
+
".sessions": (
|
|
130
|
+
"SessionLoadError",
|
|
131
|
+
"SessionObservation",
|
|
132
|
+
"SessionRecording",
|
|
133
|
+
"SessionTrace",
|
|
134
|
+
"load_session",
|
|
135
|
+
),
|
|
136
|
+
".replay": (
|
|
137
|
+
"ReplayCase",
|
|
138
|
+
"ReplayCheck",
|
|
139
|
+
"ReplaySuite",
|
|
140
|
+
"ToolStubRegistry",
|
|
141
|
+
"run_suite",
|
|
142
|
+
),
|
|
143
|
+
".client": ("DevTaskLoader", "GatewayClient"),
|
|
144
|
+
".config": ("lightning_cli",),
|
|
145
|
+
".context": (
|
|
146
|
+
"GatewayContext",
|
|
147
|
+
"GatewayContextConfig",
|
|
148
|
+
"GatewayContextConflictError",
|
|
149
|
+
"GatewayContextError",
|
|
150
|
+
"render_agent_system",
|
|
151
|
+
),
|
|
152
|
+
".emitter": (
|
|
153
|
+
"emit_annotation",
|
|
154
|
+
"emit_exception",
|
|
155
|
+
"emit_message",
|
|
156
|
+
"emit_object",
|
|
157
|
+
"emit_reward",
|
|
158
|
+
"find_final_reward",
|
|
159
|
+
"find_reward_spans",
|
|
160
|
+
"get_message_value",
|
|
161
|
+
"get_object_value",
|
|
162
|
+
"get_reward_value",
|
|
163
|
+
"get_rewards_from_span",
|
|
164
|
+
"is_reward_span",
|
|
165
|
+
"operation",
|
|
166
|
+
"reward",
|
|
167
|
+
),
|
|
168
|
+
".env_var": ("LightningEnvVar", "resolve_bool_env_var", "resolve_int_env_var", "resolve_str_env_var"),
|
|
169
|
+
".execution": (
|
|
170
|
+
"ClientServerExecutionStrategy",
|
|
171
|
+
"ExecutionEvent",
|
|
172
|
+
"ExecutionStrategy",
|
|
173
|
+
"MultiprocessingEvent",
|
|
174
|
+
"SharedMemoryExecutionStrategy",
|
|
175
|
+
"ThreadingEvent",
|
|
176
|
+
),
|
|
177
|
+
".instrumentation": (
|
|
178
|
+
"Instrumentor",
|
|
179
|
+
"InstrumentorRegistry",
|
|
180
|
+
"MetricSchema",
|
|
181
|
+
"instrument",
|
|
182
|
+
"instrument_all",
|
|
183
|
+
"uninstrument",
|
|
184
|
+
"uninstrument_all",
|
|
185
|
+
),
|
|
186
|
+
".integrations": (
|
|
187
|
+
"GatewayToolAccess",
|
|
188
|
+
"GatewayToolAccessConfig",
|
|
189
|
+
"GatewayToolAccessError",
|
|
190
|
+
"GatewayToolSubjectType",
|
|
191
|
+
),
|
|
192
|
+
".integrations.gateway": ("GatewayIngestionClient", "GatewayIngestionConfig"),
|
|
193
|
+
".litagent": ("LitAgent", "llm_rollout", "prompt_rollout", "rollout"),
|
|
194
|
+
".llm_proxy": ("LLMProxy",),
|
|
195
|
+
".logging": ("configure_logger",),
|
|
196
|
+
".memory": ("GatewayMemory", "GatewayMemoryConfig", "GatewayMemoryConflictError", "GatewayMemoryError"),
|
|
197
|
+
".personas": ("Persona", "PersonaError", "PersonaReply", "PersonasClient"),
|
|
198
|
+
# Rollout intentionally remains owned by .types, matching the historical
|
|
199
|
+
# identity produced by the former final wildcard import.
|
|
200
|
+
".run": (
|
|
201
|
+
"GatewayRunError",
|
|
202
|
+
"Metric",
|
|
203
|
+
"Run",
|
|
204
|
+
"episode",
|
|
205
|
+
"experiment",
|
|
206
|
+
"finish",
|
|
207
|
+
"get_current_rollout",
|
|
208
|
+
"get_current_run",
|
|
209
|
+
"init_run",
|
|
210
|
+
"log",
|
|
211
|
+
"run",
|
|
212
|
+
"score",
|
|
213
|
+
"success",
|
|
214
|
+
),
|
|
215
|
+
".runner": ("LegacyAgentRunner", "LitAgentRunner", "Runner"),
|
|
216
|
+
".security": (
|
|
217
|
+
"GatewayAgentDescriptor",
|
|
218
|
+
"GatewaySecurity",
|
|
219
|
+
"GatewaySecurityConfig",
|
|
220
|
+
"GatewaySecurityError",
|
|
221
|
+
"GatewayToolApprovalRequiredError",
|
|
222
|
+
"GatewayToolBlockedError",
|
|
223
|
+
"GuardedMcpSession",
|
|
224
|
+
),
|
|
225
|
+
".server": ("GatewayServer",),
|
|
226
|
+
".store": (
|
|
227
|
+
"CollectionBasedLightningStore",
|
|
228
|
+
"GatewayLightningStore",
|
|
229
|
+
"GatewayRunListener",
|
|
230
|
+
"GatewayTracker",
|
|
231
|
+
"InMemoryLightningStore",
|
|
232
|
+
"LightningStore",
|
|
233
|
+
"LightningStoreCapabilities",
|
|
234
|
+
"LightningStoreClient",
|
|
235
|
+
"LightningStoreServer",
|
|
236
|
+
"LightningStoreStatistics",
|
|
237
|
+
"LightningStoreThreaded",
|
|
238
|
+
"StorageListener",
|
|
239
|
+
"create_platform_store_client_from_env",
|
|
240
|
+
"create_platform_store_from_env",
|
|
241
|
+
),
|
|
242
|
+
".tracer": (
|
|
243
|
+
"DummyTracer",
|
|
244
|
+
"OtelTracer",
|
|
245
|
+
"Tracer",
|
|
246
|
+
"clear_active_tracer",
|
|
247
|
+
"get_active_tracer",
|
|
248
|
+
"set_active_tracer",
|
|
249
|
+
),
|
|
250
|
+
".tracing.identity": ("identify",),
|
|
251
|
+
".trainer": ("Trainer", "build_component"),
|
|
252
|
+
".types": (
|
|
253
|
+
"Attempt",
|
|
254
|
+
"AttemptStatus",
|
|
255
|
+
"AttemptedRollout",
|
|
256
|
+
"AttributeValue",
|
|
257
|
+
"Attributes",
|
|
258
|
+
"Dataset",
|
|
259
|
+
"EnqueueRolloutRequest",
|
|
260
|
+
"Event",
|
|
261
|
+
"FilterField",
|
|
262
|
+
"FilterOptions",
|
|
263
|
+
"GenericResponse",
|
|
264
|
+
"Hook",
|
|
265
|
+
"LLM",
|
|
266
|
+
"Link",
|
|
267
|
+
"NamedResources",
|
|
268
|
+
"OtelResource",
|
|
269
|
+
"PaginatedResult",
|
|
270
|
+
"ParallelWorkerBase",
|
|
271
|
+
"PromptTemplate",
|
|
272
|
+
"ProxyLLM",
|
|
273
|
+
"Resource",
|
|
274
|
+
"ResourceUnion",
|
|
275
|
+
"ResourcesUpdate",
|
|
276
|
+
"Rollout",
|
|
277
|
+
"RolloutConfig",
|
|
278
|
+
"RolloutLegacy",
|
|
279
|
+
"RolloutMode",
|
|
280
|
+
"RolloutRawResult",
|
|
281
|
+
"RolloutRawResultLegacy",
|
|
282
|
+
"RolloutStatus",
|
|
283
|
+
"SortOptions",
|
|
284
|
+
"Span",
|
|
285
|
+
"SpanAttributeNames",
|
|
286
|
+
"SpanContext",
|
|
287
|
+
"SpanCoreFields",
|
|
288
|
+
"SpanLike",
|
|
289
|
+
"SpanNames",
|
|
290
|
+
"SpanRecordingContext",
|
|
291
|
+
"StatusCode",
|
|
292
|
+
"Task",
|
|
293
|
+
"TaskIfAny",
|
|
294
|
+
"TaskInput",
|
|
295
|
+
"TraceState",
|
|
296
|
+
"TraceStatus",
|
|
297
|
+
"TracingConfig",
|
|
298
|
+
"Triplet",
|
|
299
|
+
"Worker",
|
|
300
|
+
"WorkerStatus",
|
|
301
|
+
),
|
|
302
|
+
".users": ("UserEvent", "UserProfile", "UserProfileError", "UsersClient"),
|
|
303
|
+
".build": ("define_tool", "register_artifact", "register_prompt", "register_skill"),
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
_LAZY_EXPORTS = {
|
|
307
|
+
export_name: (module_name, export_name)
|
|
308
|
+
for module_name, export_names in _LAZY_EXPORT_GROUPS.items()
|
|
309
|
+
for export_name in export_names
|
|
310
|
+
}
|
|
311
|
+
_LAZY_EXPORTS.update(
|
|
312
|
+
{
|
|
313
|
+
"setup_logging": (".logging", "setup"),
|
|
314
|
+
"setup_module_logging": (".logging", "setup_module"),
|
|
315
|
+
}
|
|
316
|
+
)
|
|
317
|
+
|
|
318
|
+
|
|
319
|
+
_LAZY_MODULES: dict[str, str] = {
|
|
320
|
+
name: f".{name}"
|
|
321
|
+
for name in (
|
|
322
|
+
"adapter",
|
|
323
|
+
"algorithm",
|
|
324
|
+
"automations",
|
|
325
|
+
"sessions",
|
|
326
|
+
"replay",
|
|
327
|
+
"client",
|
|
328
|
+
"config",
|
|
329
|
+
"context",
|
|
330
|
+
"emitter",
|
|
331
|
+
"env_var",
|
|
332
|
+
"execution",
|
|
333
|
+
"instrumentation",
|
|
334
|
+
"integrations",
|
|
335
|
+
"litagent",
|
|
336
|
+
"logging",
|
|
337
|
+
"memory",
|
|
338
|
+
"personas",
|
|
339
|
+
"runner",
|
|
340
|
+
"security",
|
|
341
|
+
"semconv",
|
|
342
|
+
"server",
|
|
343
|
+
"store",
|
|
344
|
+
"tracer",
|
|
345
|
+
"tracing",
|
|
346
|
+
"types",
|
|
347
|
+
"users",
|
|
348
|
+
"utils",
|
|
349
|
+
)
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
_OPTIONAL_EXPORTS = {"LLMProxy", "Trainer", "build_component"}
|
|
353
|
+
_OPTIONAL_EXPORT_EXTRAS = {
|
|
354
|
+
"LLMProxy": "proxy",
|
|
355
|
+
"Trainer": "trainer",
|
|
356
|
+
"build_component": "trainer",
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
# Preserve wildcard imports for the always-available surface. Historically
|
|
360
|
+
# optional proxy/trainer names appeared only when their extras happened to be
|
|
361
|
+
# installed; explicit imports remain supported through ``__getattr__``.
|
|
362
|
+
__all__ = sorted((set(_LAZY_EXPORTS) - _OPTIONAL_EXPORTS) | {"experiments", "init_experiments"})
|
|
363
|
+
|
|
364
|
+
|
|
365
|
+
def _load_export(name: str) -> object:
|
|
366
|
+
module_name, attribute_name = _LAZY_EXPORTS[name]
|
|
367
|
+
try:
|
|
368
|
+
module = _import_module(module_name, __name__)
|
|
369
|
+
except ImportError as error:
|
|
370
|
+
if name in _OPTIONAL_EXPORTS:
|
|
371
|
+
# AttributeError keeps feature probes such as
|
|
372
|
+
# ``hasattr(gatewaysdk, "Trainer")`` compatible with the former
|
|
373
|
+
# optional import. Direct attribute access still carries the
|
|
374
|
+
# installation instruction; ``from ... import`` converts it to
|
|
375
|
+
# the standard ImportError for a missing public name.
|
|
376
|
+
extra = _OPTIONAL_EXPORT_EXTRAS[name]
|
|
377
|
+
raise AttributeError(
|
|
378
|
+
f"{name} requires GatewaySDK's proxy/training dependencies. "
|
|
379
|
+
f"Install them with: pip install 'gatewaysdk[{extra}]'"
|
|
380
|
+
) from error
|
|
381
|
+
raise
|
|
382
|
+
|
|
383
|
+
# Cache every export owned by this module. Besides avoiding repeated
|
|
384
|
+
# __getattr__ calls, this restores the public ``run`` function after Python
|
|
385
|
+
# temporarily assigns the imported ``gatewaysdk.run`` module to that name.
|
|
386
|
+
for export_name, (owner_module, owner_attribute) in _LAZY_EXPORTS.items():
|
|
387
|
+
if owner_module == module_name and hasattr(module, owner_attribute):
|
|
388
|
+
globals()[export_name] = getattr(module, owner_attribute)
|
|
389
|
+
return globals()[name]
|
|
390
|
+
|
|
391
|
+
|
|
392
|
+
def __getattr__(name: str) -> object:
|
|
393
|
+
if name in _LAZY_EXPORTS:
|
|
394
|
+
return _load_export(name)
|
|
395
|
+
if name in _LAZY_MODULES:
|
|
396
|
+
module = _import_module(_LAZY_MODULES[name], __name__)
|
|
397
|
+
globals()[name] = module
|
|
398
|
+
return module
|
|
399
|
+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
|
|
400
|
+
|
|
401
|
+
|
|
402
|
+
def __dir__() -> list[str]:
|
|
403
|
+
return sorted(set(globals()) | set(_LAZY_EXPORTS) | set(_LAZY_MODULES))
|
|
404
|
+
|
|
405
|
+
|
|
406
|
+
# =============================================================================
|
|
407
|
+
# A/B Experiments — module-level proxy
|
|
408
|
+
# =============================================================================
|
|
409
|
+
|
|
410
|
+
|
|
411
|
+
class _ExperimentsNamespace:
|
|
412
|
+
"""Proxy that delegates to the global ExperimentClient.
|
|
413
|
+
|
|
414
|
+
Allows `msk.experiments.register(...)` and `msk.experiments.get_variant(...)`
|
|
415
|
+
without requiring users to manage an ExperimentClient instance directly.
|
|
416
|
+
|
|
417
|
+
If no client has been initialized yet (via `init_experiments()`), calling
|
|
418
|
+
`register()` or `get_variant()` will lazily create a local-only client
|
|
419
|
+
(no exposure logging).
|
|
420
|
+
"""
|
|
421
|
+
|
|
422
|
+
def _client(self):
|
|
423
|
+
from .experiments.client import ExperimentClient, _set_experiments_client, get_experiments_client
|
|
424
|
+
|
|
425
|
+
client = get_experiments_client()
|
|
426
|
+
if client is None:
|
|
427
|
+
client = ExperimentClient()
|
|
428
|
+
_set_experiments_client(client)
|
|
429
|
+
return client
|
|
430
|
+
|
|
431
|
+
def register(self, key, variants, traffic_percent=100, sync_to_backend=True):
|
|
432
|
+
"""Register an A/B experiment. See ExperimentClient.register()."""
|
|
433
|
+
return self._client().register(key, variants, traffic_percent, sync_to_backend)
|
|
434
|
+
|
|
435
|
+
def get_variant(self, experiment_key, user_id):
|
|
436
|
+
"""Get variant for a user. See ExperimentClient.get_variant()."""
|
|
437
|
+
return self._client().get_variant(experiment_key, user_id)
|
|
438
|
+
|
|
439
|
+
def is_registered(self, experiment_key):
|
|
440
|
+
"""Check if an experiment is registered."""
|
|
441
|
+
return self._client().is_registered(experiment_key)
|
|
442
|
+
|
|
443
|
+
def list_experiments(self):
|
|
444
|
+
"""List all registered experiment keys."""
|
|
445
|
+
return self._client().list_experiments()
|
|
446
|
+
|
|
447
|
+
def fetch(self, experiment_key, auto_register=True):
|
|
448
|
+
"""Fetch an experiment from the backend. See ExperimentClient.fetch()."""
|
|
449
|
+
return self._client().fetch(experiment_key, auto_register)
|
|
450
|
+
|
|
451
|
+
def fetch_all(self, auto_register=True):
|
|
452
|
+
"""Fetch all experiments from the backend. See ExperimentClient.fetch_all()."""
|
|
453
|
+
return self._client().fetch_all(auto_register)
|
|
454
|
+
|
|
455
|
+
def configure_backend(self, api_base_url, public_key, secret_key):
|
|
456
|
+
"""Configure backend connectivity. See ExperimentClient.configure_backend()."""
|
|
457
|
+
return self._client().configure_backend(api_base_url, public_key, secret_key)
|
|
458
|
+
|
|
459
|
+
|
|
460
|
+
# Store proxy under a private name so Python's import system can't clobber it
|
|
461
|
+
# when 'gatewaysdk.experiments' (the subpackage) is later imported internally.
|
|
462
|
+
_EXPERIMENTS_PROXY = _ExperimentsNamespace()
|
|
463
|
+
experiments = _EXPERIMENTS_PROXY
|
|
464
|
+
|
|
465
|
+
|
|
466
|
+
def init_experiments(
|
|
467
|
+
api_endpoint=None, public_key=None, secret_key=None, batch_size=100, flush_interval=1.0, api_base_url=None
|
|
468
|
+
):
|
|
469
|
+
"""Initialize the experiments system with backend connectivity.
|
|
470
|
+
|
|
471
|
+
Sets up the ExposureLogger (background thread that batches and sends
|
|
472
|
+
exposure events to the backend) and creates the global ExperimentClient.
|
|
473
|
+
|
|
474
|
+
Args:
|
|
475
|
+
api_endpoint: Full URL for the exposures batch API
|
|
476
|
+
(e.g., "https://gateway.example.com/api/public/experiments/exposures/batch")
|
|
477
|
+
If not provided, uses api_base_url to construct it.
|
|
478
|
+
public_key: Gateway public key (pk-lf-...)
|
|
479
|
+
secret_key: Gateway secret key (sk-lf-...)
|
|
480
|
+
batch_size: Max exposures per batch (default 100)
|
|
481
|
+
flush_interval: Seconds between flushes (default 1.0)
|
|
482
|
+
api_base_url: Base URL for the experiments API (e.g., "https://gateway.example.com").
|
|
483
|
+
Used for fetching/syncing experiments. If not provided, derived from api_endpoint.
|
|
484
|
+
|
|
485
|
+
Returns:
|
|
486
|
+
The ExperimentClient instance.
|
|
487
|
+
"""
|
|
488
|
+
# The imports above cause Python to register 'gatewaysdk.experiments' as the
|
|
489
|
+
# subpackage module in sys.modules, which overwrites 'gatewaysdk.experiments'
|
|
490
|
+
# attribute on this module. Restore the proxy immediately.
|
|
491
|
+
import sys
|
|
492
|
+
|
|
493
|
+
from .experiments.client import ExperimentClient, _set_experiments_client
|
|
494
|
+
from .experiments.exposure import ExposureLogger
|
|
495
|
+
|
|
496
|
+
_self = sys.modules.get(__name__)
|
|
497
|
+
if _self is not None:
|
|
498
|
+
_self.experiments = _EXPERIMENTS_PROXY
|
|
499
|
+
|
|
500
|
+
# Derive api_base_url from api_endpoint if not provided
|
|
501
|
+
if api_base_url is None and api_endpoint:
|
|
502
|
+
# Extract base URL from the full endpoint
|
|
503
|
+
# e.g., "https://gateway.example.com/api/public/experiments/exposures/batch"
|
|
504
|
+
# -> "https://gateway.example.com"
|
|
505
|
+
from urllib.parse import urlparse
|
|
506
|
+
|
|
507
|
+
parsed = urlparse(api_endpoint)
|
|
508
|
+
api_base_url = f"{parsed.scheme}://{parsed.netloc}"
|
|
509
|
+
|
|
510
|
+
# Derive api_endpoint from api_base_url if not provided
|
|
511
|
+
if api_endpoint is None and api_base_url:
|
|
512
|
+
api_endpoint = f"{api_base_url}/api/public/experiments/exposures/batch"
|
|
513
|
+
|
|
514
|
+
exposure_logger = None
|
|
515
|
+
if api_endpoint and public_key and secret_key:
|
|
516
|
+
exposure_logger = ExposureLogger(
|
|
517
|
+
api_endpoint=api_endpoint,
|
|
518
|
+
public_key=public_key,
|
|
519
|
+
secret_key=secret_key,
|
|
520
|
+
batch_size=batch_size,
|
|
521
|
+
flush_interval=flush_interval,
|
|
522
|
+
)
|
|
523
|
+
exposure_logger.start()
|
|
524
|
+
|
|
525
|
+
client = ExperimentClient(
|
|
526
|
+
exposure_logger=exposure_logger,
|
|
527
|
+
api_base_url=api_base_url,
|
|
528
|
+
public_key=public_key,
|
|
529
|
+
secret_key=secret_key,
|
|
530
|
+
)
|
|
531
|
+
_set_experiments_client(client)
|
|
532
|
+
|
|
533
|
+
# Transfer any experiments registered before init (use _EXPERIMENTS_PROXY
|
|
534
|
+
# directly — 'experiments' module-level name may be the subpackage at this point)
|
|
535
|
+
existing = _EXPERIMENTS_PROXY._client()
|
|
536
|
+
if existing is not client and hasattr(existing, "_experiments"):
|
|
537
|
+
for key, config in existing._experiments.items():
|
|
538
|
+
client._experiments[key] = config
|
|
539
|
+
|
|
540
|
+
return client
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Copyright (c) Microsoft. All rights reserved.
|
|
2
|
+
|
|
3
|
+
from .base import Adapter, OtelTraceAdapter, TraceAdapter
|
|
4
|
+
from .messages import TraceToMessages
|
|
5
|
+
from .triplet import LlmProxyTraceToTriplet, TracerTraceToTriplet, TraceToTripletBase
|
|
6
|
+
|
|
7
|
+
__all__ = [
|
|
8
|
+
"TraceAdapter",
|
|
9
|
+
"OtelTraceAdapter",
|
|
10
|
+
"Adapter",
|
|
11
|
+
"TraceToTripletBase",
|
|
12
|
+
"TracerTraceToTriplet",
|
|
13
|
+
"LlmProxyTraceToTriplet",
|
|
14
|
+
"TraceToMessages",
|
|
15
|
+
]
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
# Copyright (c) Microsoft. All rights reserved.
|
|
2
|
+
|
|
3
|
+
from typing import Generic, Sequence, TypeVar
|
|
4
|
+
|
|
5
|
+
from opentelemetry.sdk.trace import ReadableSpan
|
|
6
|
+
|
|
7
|
+
from gatewaysdk.types import Span
|
|
8
|
+
|
|
9
|
+
T_from = TypeVar("T_from")
|
|
10
|
+
T_to = TypeVar("T_to")
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class Adapter(Generic[T_from, T_to]):
|
|
14
|
+
"""Base class for synchronous adapters that convert data from one format to another.
|
|
15
|
+
|
|
16
|
+
The class defines a minimal protocol so that adapters can be treated like callables while
|
|
17
|
+
still allowing subclasses to supply the concrete transformation logic.
|
|
18
|
+
|
|
19
|
+
!!! note
|
|
20
|
+
Subclasses must override [`adapt()`][gatewaysdk.Adapter.adapt] to provide
|
|
21
|
+
the actual conversion.
|
|
22
|
+
|
|
23
|
+
Type Variables:
|
|
24
|
+
|
|
25
|
+
T_from: Source data type supplied to the adapter.
|
|
26
|
+
|
|
27
|
+
T_to: Target data type produced by the adapter.
|
|
28
|
+
|
|
29
|
+
Examples:
|
|
30
|
+
>>> class IntToStrAdapter(Adapter[int, str]):
|
|
31
|
+
... def adapt(self, source: int) -> str:
|
|
32
|
+
... return str(source)
|
|
33
|
+
...
|
|
34
|
+
>>> adapter = IntToStrAdapter()
|
|
35
|
+
>>> adapter(42)
|
|
36
|
+
'42'
|
|
37
|
+
"""
|
|
38
|
+
|
|
39
|
+
def __call__(self, source: T_from, /) -> T_to:
|
|
40
|
+
"""Convert the data to the target format.
|
|
41
|
+
|
|
42
|
+
This method delegates to [`adapt()`][gatewaysdk.Adapter.adapt] so that an
|
|
43
|
+
instance of [`Adapter`][gatewaysdk.Adapter] can be used like a standard
|
|
44
|
+
function.
|
|
45
|
+
|
|
46
|
+
Args:
|
|
47
|
+
source: Input data in the source format.
|
|
48
|
+
|
|
49
|
+
Returns:
|
|
50
|
+
Data converted to the target format.
|
|
51
|
+
"""
|
|
52
|
+
return self.adapt(source)
|
|
53
|
+
|
|
54
|
+
def adapt(self, source: T_from, /) -> T_to:
|
|
55
|
+
"""Convert the data to the target format.
|
|
56
|
+
|
|
57
|
+
Subclasses must override this method with the concrete transformation logic. The base
|
|
58
|
+
implementation raises `NotImplementedError` to make the requirement explicit.
|
|
59
|
+
|
|
60
|
+
Args:
|
|
61
|
+
source: Input data in the source format.
|
|
62
|
+
|
|
63
|
+
Returns:
|
|
64
|
+
Data converted to the target format.
|
|
65
|
+
"""
|
|
66
|
+
raise NotImplementedError("Adapter.adapt() is not implemented")
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
class OtelTraceAdapter(Adapter[Sequence[ReadableSpan], T_to], Generic[T_to]):
|
|
70
|
+
"""Base class for adapters that convert OpenTelemetry trace spans into other formats.
|
|
71
|
+
|
|
72
|
+
This specialization of [`Adapter`][gatewaysdk.Adapter] expects a list of
|
|
73
|
+
`opentelemetry.sdk.trace.ReadableSpan` instances and produces any target format, such as
|
|
74
|
+
reinforcement learning trajectories, structured logs, or analytics-ready payloads.
|
|
75
|
+
|
|
76
|
+
Examples:
|
|
77
|
+
>>> class TraceToDictAdapter(OtelTraceAdapter[dict]):
|
|
78
|
+
... def adapt(self, spans: List[ReadableSpan]) -> dict:
|
|
79
|
+
... return {"count": len(spans)}
|
|
80
|
+
...
|
|
81
|
+
>>> adapter = TraceToDictAdapter()
|
|
82
|
+
>>> adapter([span1, span2])
|
|
83
|
+
{'count': 2}
|
|
84
|
+
"""
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
class TraceAdapter(Adapter[Sequence[Span], T_to], Generic[T_to]):
|
|
88
|
+
"""Base class for adapters that convert trace spans into other formats.
|
|
89
|
+
|
|
90
|
+
This class specializes [`Adapter`][gatewaysdk.Adapter] for working with
|
|
91
|
+
[`Span`][gatewaysdk.Span] instances emitted by GatewaySDK instrumentation.
|
|
92
|
+
Subclasses receive entire trace slices and return a format suited for the downstream consumer,
|
|
93
|
+
for example reinforcement learning training data or observability metrics.
|
|
94
|
+
"""
|