b4f7574f
tangwang
feat(agent): add ...
|
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
|
"""JSON Schema definitions for registering the recommendation tools."""
import copy
ALGORITHM_NAMES = [
'swing_cpp',
'swing',
'session_w2v',
'deepwalk',
'content_name',
'content_pic',
'item_behavior',
]
DIMENSION_NAMES = [
'platform',
'client_platform',
'country_code',
'customer_type',
'supplier',
'category_level1',
'category_level2',
'category_level3',
'category_level4',
]
LIST_TYPE_NAMES = ['hot', 'cart', 'new', 'global']
SEED_ITEMS_SCHEMA = {
'type': 'array',
'minItems': 1,
'maxItems': 20,
'items': {
'type': 'object',
'additionalProperties': False,
'properties': {
'item_id': {
'description': '商品 SKU ID,建议以字符串传递。',
'oneOf': [{'type': 'string'}, {'type': 'integer'}],
},
'weight': {
'type': 'number',
'exclusiveMinimum': 0,
'maximum': 10,
'description': '偏好强度;省略时按 behavior 推导。',
},
'behavior': {
'type': 'string',
'enum': [
'click', 'view', 'addToPool', 'addToCart',
'contactFactory', 'purchase',
],
},
'reason': {
'type': 'string',
'maxLength': 200,
'description': '画像中选择该种子商品的简短依据。',
},
},
'required': ['item_id'],
},
}
CONTEXT_SCHEMA = {
'type': 'object',
'additionalProperties': False,
'properties': {
'platform': {'type': 'string'},
'client_platform': {'type': 'string'},
'country_code': {
'oneOf': [{'type': 'string'}, {'type': 'integer'}],
},
'customer_type': {'type': 'string'},
},
'description': '当前请求上下文;组合维度会由工具自动规划。',
}
INTERESTS_SCHEMA = {
'type': 'array',
'maxItems': 30,
'items': {
'type': 'object',
'additionalProperties': False,
'properties': {
'dimension': {'type': 'string', 'enum': DIMENSION_NAMES},
'value': {
'description': '内部维度值;名称应先通过维度解析工具转换。',
'oneOf': [{'type': 'string'}, {'type': 'integer'}],
},
'weight': {
'type': 'number',
'exclusiveMinimum': 0,
'maximum': 10,
'default': 1,
},
'reason': {'type': 'string', 'maxLength': 200},
},
'required': ['dimension', 'value'],
},
}
def _common_recall_properties():
return {
'top_k': {
'type': 'integer', 'minimum': 1, 'maximum': 100, 'default': 50,
},
'exclude_item_ids': {
'type': 'array',
'maxItems': 500,
'items': {'oneOf': [{'type': 'string'}, {'type': 'integer'}]},
'description': '已曝光、已购买、不可售等需排除的商品 ID。',
},
}
def _similar_properties():
properties = _common_recall_properties()
properties.update({
'seed_items': copy.deepcopy(SEED_ITEMS_SCHEMA),
'algorithms': {
'type': 'array',
'uniqueItems': True,
'items': {'type': 'string', 'enum': ALGORITHM_NAMES},
},
'per_seed_k': {
'type': 'integer', 'minimum': 1, 'maximum': 200, 'default': 50,
},
})
return properties
def _dimension_properties():
properties = _common_recall_properties()
properties.update({
'context': copy.deepcopy(CONTEXT_SCHEMA),
'interests': copy.deepcopy(INTERESTS_SCHEMA),
'list_types': {
'type': 'array',
'minItems': 1,
'uniqueItems': True,
'items': {'type': 'string', 'enum': LIST_TYPE_NAMES},
},
'per_source_k': {
'type': 'integer', 'minimum': 1, 'maximum': 500, 'default': 100,
},
})
return properties
def get_tool_definitions():
"""Return framework-neutral function tool definitions."""
hybrid_properties = _similar_properties()
hybrid_properties.update(_dimension_properties())
hybrid_properties.update({
'collaborative_weight': {
'type': 'number', 'minimum': 0, 'maximum': 1, 'default': 0.65,
},
'dimension_weight': {
'type': 'number', 'minimum': 0, 'maximum': 1, 'default': 0.35,
},
})
hybrid_properties['seed_items']['minItems'] = 0
return [
{
'type': 'function',
'function': {
'name': 'recommendation_capabilities',
'description': (
'查看可用协同算法、画像维度、索引语义和推荐工具调用顺序。'
'首次接入或不确定参数时调用。'
),
'parameters': {
'type': 'object', 'properties': {},
'additionalProperties': False,
},
},
},
{
'type': 'function',
'function': {
'name': 'resolve_recommendation_dimension',
'description': (
'把分类、供应商、平台等自然语言名称解析为离线索引使用的内部维度值。'
'只返回候选映射,不做商品召回。'
),
'parameters': {
'type': 'object',
'additionalProperties': False,
'properties': {
'dimension': {'type': 'string', 'enum': DIMENSION_NAMES},
'query': {'type': 'string', 'minLength': 1, 'maxLength': 200},
'limit': {
'type': 'integer', 'minimum': 1, 'maximum': 20,
'default': 10,
},
},
'required': ['dimension', 'query'],
},
},
},
{
'type': 'function',
'function': {
'name': 'recall_similar_products',
'description': (
'基于用户明确感兴趣的种子商品,从 Swing、序列、图和内容索引中'
'召回相似商品,并返回可追溯的多算法融合证据。'
),
'parameters': {
'type': 'object',
'additionalProperties': False,
'properties': _similar_properties(),
'required': ['seed_items'],
},
},
},
{
'type': 'function',
'function': {
'name': 'recall_products_by_dimensions',
'description': (
'根据平台、国家、客户类型、分类、供应商等画像维度召回热门、'
'高加购、新品和全局商品;自动使用组合维度并回退到单维度。'
),
'parameters': {
'type': 'object',
'additionalProperties': False,
'properties': _dimension_properties(),
'anyOf': [{'required': ['context']}, {'required': ['interests']}],
},
},
},
{
'type': 'function',
'function': {
'name': 'build_recommendation_candidates',
'description': (
'为智能导购生成高召回候选池:融合种子商品协同召回与画像维度召回,'
'去重、排除已知商品,并保留供 LLM 挑选的来源证据。'
),
'parameters': {
'type': 'object',
'additionalProperties': False,
'properties': hybrid_properties,
'anyOf': [
{'required': ['seed_items']},
{'required': ['context']},
{'required': ['interests']},
],
},
},
},
]
|