test_main.py
2.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
"""Tests for skill registration during AgentHub initialization."""
import pytest
from unittest.mock import patch, MagicMock
from app.config.settings import AgentConfig
def _make_test_agents():
"""Create test agent configs for AgentHub init."""
return {
"steward_key": AgentConfig(
name="管家 Agent", code="11",
prompt="你是智能助手",
description="协调调度各子Agent",
is_steward=True,
),
}
class TestSkillRegistration:
def test_agent_hub_registers_skills_on_init(self):
"""AgentHub.__init__ should register skills to Toolkit via register_agent_skill."""
from app.agent_core.agent_hub import AgentHub
mock_loader = MagicMock()
mock_model_config = MagicMock()
mock_model_config.model_name = "test-model"
mock_model_config.api_key = "test-key"
mock_model_config.api_base = "http://test"
mock_loader.load_models.return_value = {"main": mock_model_config}
mock_loader.load_skills_from_toolkit.return_value = {}
mock_session_service = MagicMock()
mock_im = MagicMock()
with patch('agentscope.tool.Toolkit.register_agent_skill') as mock_register:
with patch('agentscope.model.OpenAIChatModel.__init__', return_value=None):
hub = AgentHub(
mock_loader, mock_session_service, mock_im,
preloaded_agents=_make_test_agents(),
)
assert mock_register.called
def test_agent_hub_skills_loaded_from_toolkit(self):
"""Skills dict should come from load_skills_from_toolkit, not load_skills."""
from app.agent_core.agent_hub import AgentHub
expected_skills = {
"buddy-sings": {
"code": "buddy-sings",
"name": "buddy-sings",
"description": "Test desc",
"instruction": "Test desc",
"location": "skills/buddy-sings",
}
}
mock_loader = MagicMock()
mock_model_config = MagicMock()
mock_model_config.model_name = "test-model"
mock_model_config.api_key = "test-key"
mock_model_config.api_base = "http://test"
mock_loader.load_models.return_value = {"main": mock_model_config}
mock_loader.load_skills_from_toolkit.return_value = expected_skills
mock_session_service = MagicMock()
mock_im = MagicMock()
with patch('agentscope.tool.Toolkit.register_agent_skill'):
with patch('agentscope.model.OpenAIChatModel.__init__', return_value=None):
hub = AgentHub(
mock_loader, mock_session_service, mock_im,
preloaded_agents=_make_test_agents(),
)
assert hub.skills == expected_skills
assert "buddy-sings" in hub.skills