Files
ai-agent-book/tests/test_ch4_semantic_router_empty_servers.py
T
liqiang b119135836
Build latest book artifacts / build (push) Canceled after 0s
dependency resolution / resolve (3.11) (push) Canceled after 0s
dependency resolution / resolve (3.13) (push) Canceled after 0s
deploy-pages / build (push) Canceled after 0s
deploy-pages / deploy (push) Canceled after 0s
i18n consistency check / check (push) Canceled after 0s
provider adoption tests / test (chapter2/context-compression) (push) Canceled after 0s
provider adoption tests / test (chapter2/prompt-injection) (push) Canceled after 0s
provider adoption tests / test (chapter2/system-hint) (push) Canceled after 0s
provider adoption tests / test (chapter3/log-sanitization) (push) Canceled after 0s
web-search-agent tests / test (push) Canceled after 0s
web-search-agent tests / agentbook (push) Canceled after 0s
ai-agent-book 精选快照(<2MB 代码与文档,来自 github.com/bojieli/ai-agent-book)
2026-08-20 13:12:50 +00:00

38 lines
1.3 KiB
Python

import pytest
pytest.importorskip("numpy")
"""Regression test for SemanticRouter initialization with empty servers list."""
import sys
from pathlib import Path
# Add active-tool-selection to sys.path
sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "chapter4" / "active-tool-selection"))
from semantic_router import SemanticRouter
def test_semantic_router_empty_servers():
router = SemanticRouter([])
assert router.servers == []
assert router.server_embeddings is None
assert router.route_request("find a tool") == []
assert router.retrieve("find a tool", top_k=5) == []
assert router._route_to_servers("find a tool", top_k=5) == []
details = router.get_routing_details("find a tool")
assert details["final_tools"] == []
assert details["stage1_servers"] == []
assert details["stage2_tools"] == {}
def test_semantic_router_servers_with_only_stop_words():
class MockServer:
name = "the"
description = "a an in on at"
tools = []
router = SemanticRouter([MockServer()])
assert router.server_embeddings is None
assert router.route_request("query") == []
assert router.retrieve("query", top_k=3) == []
assert router._route_to_servers("query", top_k=3) == [(router.servers[0], 0.0)]