Use this skill when the user asks questions about travel policies, reimbursement, booking guides, city information, or any travel-related questions. Triggers when user asks "XX标准是多少", "如何XX", "XX怎么办", or any question format. This skill uses RAGKnowledgeAgent to retrieve answers from the knowledge base.
回答用户关于差旅政策、报销、预订、城市指南等的问题,使用 RAGKnowledgeAgent 从本地知识库检索并生成答案。
agents/rag_knowledge_agent.py)OpenAIChatModelreply() 为 async,需 awaitimport asyncio
from agentscope.message import Msg
from agentscope.model import OpenAIChatModel
from config_agentscope import init_agentscope
from config import LLM_CONFIG
from agents.rag_knowledge_agent import RAGKnowledgeAgent
import json
async def ask_question(user_query: str):
init_agentscope()
model = OpenAIChatModel(
model_name=LLM_CONFIG["model_name"],
api_key=LLM_CONFIG["api_key"],
client_kwargs={"base_url": LLM_CONFIG["base_url"], "timeout": 60},
temperature=LLM_CONFIG.get("temperature", 0.7),
max_tokens=LLM_CONFIG.get("max_tokens", 2000),
)
# 嵌入模型路径从 config.RAG_CONFIG 读取,默认 data/models/bge-small-zh-v1.5
rag_agent = RAGKnowledgeAgent(
name="RAGKnowledgeAgent",
model=model,
knowledge_base_path="./data/rag_knowledge",
collection_name="business_travel_knowledge",
top_k=3,
)
if not getattr(rag_agent, "initialized", True):
return {"error": "RAG 未初始化,请先运行 python scripts/init_knowledge_base.py"}
user_msg = Msg(name="user", content=user_query, role="user")
result = await rag_agent.reply(user_msg)
return json.loads(result.content) if isinstance(result.content, str) else result.content
# 使用
data = asyncio.run(ask_question("北京的住宿标准是多少?"))
# data: {"status": "success"|"no_knowledge", "answer": "...", "retrieved_documents": [...], "query": "..."}
status: "success" 或 "no_knowledge"answer: 自然语言答案retrieved_documents: 列表,每项含 content, metadataquery: 用户问题data/rag_knowledge/(Milvus Lite)data/documents/,共 8 类(差旅标准、报销、预订、FAQ、紧急处理、平台指南、城市指南、环保)python scripts/init_knowledge_base.py【回答要求】
请直接给出答案。