Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
chatbot_canifa_test_conservation_tools
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Vũ Hoàng Anh
chatbot_canifa_test_conservation_tools
Commits
f0081da3
Commit
f0081da3
authored
Jan 27, 2026
by
Vũ Hoàng Anh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(backend): Enforce strict age/gender filtering in prompt and tool schema
parent
c66892a7
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
200 additions
and
343 deletions
+200
-343
system_prompt.txt
backend/agent/system_prompt.txt
+160
-342
data_retrieval_tool.py
backend/agent/tools/data_retrieval_tool.py
+40
-1
No files found.
backend/agent/system_prompt.txt
View file @
f0081da3
This diff is collapsed.
Click to expand it.
backend/agent/tools/data_retrieval_tool.py
View file @
f0081da3
...
...
@@ -79,6 +79,18 @@ class SearchItem(BaseModel):
price_min
:
float
|
None
=
Field
(
...
,
description
=
"Giá thấp nhất (VD: 100000)"
)
price_max
:
float
|
None
=
Field
(
...
,
description
=
"Giá cao nhất (VD: 500000)"
)
action
:
str
=
Field
(
...
,
description
=
"Hành động: 'search' (tìm kiếm) hoặc 'visual_search' (phân tích ảnh)"
)
# Metadata Fields for Filtering
gender_by_product
:
str
|
None
=
None
age_by_product
:
str
|
None
=
None
product_name
:
str
|
None
=
None
style
:
str
|
None
=
None
master_color
:
str
|
None
=
None
season
:
str
|
None
=
None
material_group
:
str
|
None
=
None
fitting
:
str
|
None
=
None
form_neckline
:
str
|
None
=
None
form_sleeve
:
str
|
None
=
None
class
MultiSearchParams
(
BaseModel
):
...
...
@@ -87,6 +99,23 @@ class MultiSearchParams(BaseModel):
searches
:
list
[
SearchItem
]
=
Field
(
...
,
description
=
"Danh sách các truy vấn tìm kiếm chạy song song"
)
def
_parse_query_metadata
(
query_str
:
str
)
->
dict
:
"""Parse structured query string explicitly generated by the Agent."""
import
re
metadata
=
{}
if
not
query_str
:
return
metadata
# Matches "key: value" at the start of lines (handling indentation)
pattern
=
re
.
compile
(
r"^\s*([a-z_]+):\s*(.+?)\s*$"
,
re
.
MULTILINE
)
matches
=
pattern
.
findall
(
query_str
)
for
key
,
value
in
matches
:
if
value
and
value
.
lower
()
!=
'none'
:
metadata
[
key
]
=
value
.
strip
()
return
metadata
@
tool
(
args_schema
=
MultiSearchParams
)
# @traceable(run_type="tool", name="data_retrieval_tool")
...
...
@@ -101,16 +130,26 @@ async def data_retrieval_tool(searches: list[SearchItem]) -> str:
"""
logger
.
info
(
"data_retrieval_tool started, searches=
%
s"
,
len
(
searches
))
try
:
# Pre-process: Parse metadata from query string
for
item
in
searches
:
if
item
.
query
:
meta
=
_parse_query_metadata
(
item
.
query
)
for
k
,
v
in
meta
.
items
():
if
hasattr
(
item
,
k
):
setattr
(
item
,
k
,
v
)
# 0. Log input tổng quan (không log chi tiết dài)
for
idx
,
item
in
enumerate
(
searches
):
short_query
=
(
item
.
query
[:
60
]
+
"..."
)
if
item
.
query
and
len
(
item
.
query
)
>
60
else
item
.
query
logger
.
debug
(
"search[
%
s] query=
%
r, code=
%
r, price_min=
%
r, price_max=
%
r"
,
"search[
%
s] query=
%
r, code=
%
r, price_min=
%
r, price_max=
%
r
, gender=
%
r, age=
%
r
"
,
idx
,
short_query
,
item
.
magento_ref_code
,
item
.
price_min
,
item
.
price_max
,
item
.
gender_by_product
,
item
.
age_by_product
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment