精准HS归类AgentVibe Building
帮我创建一个可以根据美国、欧盟、中国的海关归类要求,通过理解产品信息、查阅海关判例,进行精准HS归类的Agent
正在思考...
1. 识别核心功能:HS归类、多国规则(CN/US/EU)、判例检索
2. 规划Agent架构:Input Parser -> RAG Engine -> Reasoning -> Output
3. 确定技术栈:Python, LangChain, VectorDB
6 个工具调用
SearchCustomsRules(region='US')
QueryVectorDB(query='HS classification cases')
GenerateAgentCode(model='gpt-4')

我已经为你设计了HS归类Agent的架构,并开始生成核心代码。这个Agent将包含三个主要模块:

  • 知识库模块:集成各国海关规则和历史判例
  • 推理引擎:基于RAG技术进行多维度分析
  • 输出格式化:生成符合报关要求的标准报告
沙箱已连接
Explorer
agent
classifier.py
customs_rag.py
utils.py
config
settings.yaml
prompts.yaml
requirements.txt
README.md
classifier.py
"text-purple-600">import openai
"text-purple-600">from typing "text-purple-600">import List, Dict, Optional
"text-purple-600">from customs_rag "text-purple-600">import CustomsKnowledgeBase

"text-purple-600">class HSClassifierAgent:
    "text-purple-600">def __init__("text-orange-600">self, region: str = "CN"):
        """
        初始化海关归类Agent
        :param region: 归类区域 (CN/US/EU)
        """
        "text-orange-600">self.region = region
        "text-orange-600">self.kb = CustomsKnowledgeBase(region)
        "text-orange-600">self.model = "gpt-4-turbo"

    "text-purple-600">async "text-purple-600">def "text-purple-600">classify_product("text-orange-600">self, product_info: Dict) -> Dict:
        """
        根据产品信息进行HS归类
        """
        # 1. 理解产品信息
        product_desc = "text-orange-600">self._format_product_desc(product_info)
        
        # 2. 检索海关判例和归类规则
        rag_context = "text-purple-600">await "text-orange-600">self.kb.search(product_desc)
        
        # 3. 生成归类建议
        prompt = "text-orange-600">self._build_prompt(product_desc, rag_context)
        response = "text-purple-600">await "text-orange-600">self._call_llm(prompt)
        
        "text-purple-600">return "text-orange-600">self._parse_response(response)

    "text-purple-600">def _build_prompt("text-orange-600">self, product_desc: str, context: List[str]) -> str:
        "text-purple-600">return f"""
        作为海关归类专家,请基于以下信息对产品进行{"text-orange-600">self.region}海关归类:
        
        [产品信息]
        {product_desc}
        
        [参考判例与规则]
        {context}
        
        请提供:
        1. 推荐的HS编码(6位或8位)
        2. 归类依据(GRI规则引用)
        3. 潜在风险提示
        """
TERMINAL
➜ spark-studio git:(main) python agent/classifier.py
[INFO] Initializing CustomsKnowledgeBase with region='CN'...
[INFO] Loading vector embeddings from ./data/embeddings...
[DEBUG] Connection established to vector database
✓ System ready. Waiting for input...
_