5a581c78a2
Build / build (push) Has been cancelled
Docker / build (push) Has been cancelled
Lint / ruff (push) Has been cancelled
Test / pytest (ubuntu-latest, 3.11) (push) Has been cancelled
Test / pytest (ubuntu-latest, 3.12) (push) Has been cancelled
Test / pytest (windows-latest, 3.11) (push) Has been cancelled
Test / pytest (windows-latest, 3.12) (push) Has been cancelled
Introduce provider, model, and invocation contracts with encrypted configuration persistence. Add web runtime fencing, route fallback, recovery middleware, workspace scoping, and comprehensive tests.
162 lines
6.4 KiB
Python
162 lines
6.4 KiB
Python
from __future__ import annotations
|
|
|
|
from typing import Any
|
|
|
|
from EvoScientist.llm.crypto import HmacKeyRing, KeyMaterial
|
|
from EvoScientist.llm.model_config import (
|
|
EvoModelConfig,
|
|
adapter_revision,
|
|
endpoint_fingerprint,
|
|
route_semantics_hash,
|
|
)
|
|
|
|
RUNTIME_SECRET = "runtime-secret-for-tests-000000000000000000000000"
|
|
IDENTITY_SECRET = "identity-secret-for-tests-00000000000000000000000"
|
|
RUNTIME_KEY_ID = "runtime-test"
|
|
IDENTITY_KEY_ID = "identity-test"
|
|
|
|
|
|
def identity_ring() -> HmacKeyRing:
|
|
return HmacKeyRing(KeyMaterial.create(IDENTITY_KEY_ID, IDENTITY_SECRET))
|
|
|
|
|
|
def v3_payload(*, revision: int = 1) -> dict[str, Any]:
|
|
payload: dict[str, Any] = {
|
|
"schema_version": 2,
|
|
"config_revision": revision,
|
|
"config_identity_key_id": IDENTITY_KEY_ID,
|
|
"runtime_defaults": {"max_retries": 0},
|
|
"purpose_defaults": {
|
|
"main_agent": {"reasoning_effort": "medium"},
|
|
"tool_selector": {"reasoning_effort": "disabled"},
|
|
"deepagents_summarizer": {"reasoning_effort": "disabled"},
|
|
"title": {"reasoning_effort": "disabled"},
|
|
},
|
|
"providers": {
|
|
"custom-openai": {
|
|
"protocol": "custom-openai",
|
|
"params": {},
|
|
"endpoints": [
|
|
{
|
|
"name": "primary",
|
|
"base_url": "https://provider.example/v1",
|
|
"auth": {"ref": "env://WEB_RUNTIME_TEST_KEY", "revision": 1},
|
|
"headers": {"User-Agent": "Ai4Sci-Test"},
|
|
"header_refs": {},
|
|
"params": {"extra_body": {}},
|
|
}
|
|
],
|
|
"models": [
|
|
{
|
|
"id": "model-id",
|
|
"params": {"output_token_limit": 512},
|
|
"supports_vision": True,
|
|
"supports_reasoning": True,
|
|
"allowed_reasoning_efforts": ["low", "medium", "high"],
|
|
"context_window": 8192,
|
|
"max_output_tokens": 2048,
|
|
"access": {"allowed_plans": [], "allowed_roles": []},
|
|
"billing": {
|
|
"sku": "visible-model",
|
|
"pricing_revision": "test-1",
|
|
"currency": "CNY",
|
|
"unit_scale": 1_000_000,
|
|
"input_microunits_per_million": 1_000_000,
|
|
"output_microunits_per_million": 2_000_000,
|
|
"cached_microunits_per_million": 500_000,
|
|
},
|
|
}
|
|
],
|
|
}
|
|
},
|
|
"endpoint_pools": {
|
|
"default": {
|
|
"provider": "custom-openai",
|
|
"strategy": "smooth_weighted_round_robin",
|
|
"endpoints": [{"name": "primary", "weight": 1}],
|
|
}
|
|
},
|
|
"route_health": {
|
|
"failure_threshold": 3,
|
|
"cooldown_seconds": 30,
|
|
"half_open_max_inflight": 1,
|
|
"counted_error_codes": ["PROVIDER_5XX", "PROVIDER_TIMEOUT"],
|
|
"open_immediately_error_codes": ["PROVIDER_AUTH_INVALID"],
|
|
},
|
|
"route_selectors": {
|
|
"visible-main": {
|
|
"provider": "custom-openai",
|
|
"endpoint_pool": "default",
|
|
"model": "model-id",
|
|
"api_mode": "chat_completions",
|
|
"tool_call_transport": "non_streaming",
|
|
}
|
|
},
|
|
"purpose_routes": {
|
|
"main_agent": {
|
|
"default_alias": "visible-model",
|
|
"selectable": {"visible-model": "visible-main"},
|
|
},
|
|
"title": {"default": "visible-main"},
|
|
},
|
|
"purpose_call_limits": {
|
|
"main_agent": {"max_attempts_per_run": 4},
|
|
"tool_selector": {"max_attempts_per_run": 2},
|
|
"deepagents_summarizer": {"max_attempts_per_run": 1},
|
|
"title": {"max_attempts_per_run": 1},
|
|
},
|
|
"web_runtime": {
|
|
"title_start_timeout_seconds": 30,
|
|
"prepare_ttl_seconds": 30,
|
|
"turn_lease_grace_seconds": 10,
|
|
"active_run_timeout_seconds": 60,
|
|
"max_run_journal_events": 1000,
|
|
"max_run_journal_bytes": 1_048_576,
|
|
"max_prepared_runs_per_subject": 2,
|
|
"max_prepared_runs_total": 100,
|
|
},
|
|
"capability_evidence": [],
|
|
"tool_protocol_fallbacks": [{"primary": "visible-main", "fallbacks": []}],
|
|
}
|
|
candidate = EvoModelConfig.parse(payload, require_evidence=False)
|
|
ring = identity_ring()
|
|
semantics_key = ring.derive_current("ai4sci/route-semantics-hash/v3")[1]
|
|
endpoint_key = ring.derive_current("ai4sci/endpoint-fingerprint/v3")[1]
|
|
evidence = []
|
|
seen = set()
|
|
for selector_id in candidate.route_selectors:
|
|
for route in candidate.concrete_routes(selector_id):
|
|
if route.key() in seen:
|
|
continue
|
|
seen.add(route.key())
|
|
evidence.append(
|
|
{
|
|
"route": {
|
|
"provider": route.provider,
|
|
"endpoint": route.endpoint,
|
|
"model": route.model,
|
|
"api_mode": route.api_mode,
|
|
"tool_call_transport": route.tool_call_transport,
|
|
},
|
|
"connectivity": "supported",
|
|
"tool_capability": "supported",
|
|
"probe": {
|
|
"route_semantics_hash": route_semantics_hash(
|
|
candidate, route, semantics_key
|
|
),
|
|
"endpoint_fingerprint": endpoint_fingerprint(
|
|
candidate, route, endpoint_key
|
|
),
|
|
"config_identity_key_id": IDENTITY_KEY_ID,
|
|
"adapter_revision": adapter_revision(
|
|
candidate.providers[route.provider].protocol,
|
|
route.api_mode,
|
|
),
|
|
"fixture_digest": "sha256:test-fixture-v3",
|
|
"verified_at": "2026-07-20T00:00:00+00:00",
|
|
},
|
|
}
|
|
)
|
|
payload["capability_evidence"] = evidence
|
|
return payload
|