/opt/miniconda3/envs/langchain/bin/python /Users/moonmovewhilecloudchange/Downloads/项目2_基于LangGraph实现智能分诊系统/L1-Project-2/ragAgent.py
mian() LLM_TYPE is:qwen
llm_type is: qwen
llm_type is :qwen
config is {'base_url': 'https://dashscope.aliyuncs.com/compatible-mode/v1', 'api_key': 'sk-699dffbfce8c430499468a3698095e73', 'chat_model': 'qwen-max', 'embedding_model': 'text-embedding-v2'}
dashscope_api_key is :sk-699dffbfce8c430499468a3698095e73
2025-08-30 23:51:03,015 - __main__ - INFO - Database connection test successful
2025-08-30 23:51:03,228 - utils.llms - INFO - 成功初始化 qwen LLM
2025-08-30 23:51:03,245 - chromadb.telemetry.product.posthog - INFO - Anonymized telemetry enabled. See https://docs.trychroma.com/telemetry for more information.
2025-08-30 23:51:03,325 - chromadb.telemetry.product.posthog - ERROR - Failed to send telemetry event ClientStartEvent: capture() takes 1 positional argument but 3 were given
2025-08-30 23:51:03,326 - chromadb.telemetry.product.posthog - ERROR - Failed to send telemetry event ClientCreateCollectionEvent: capture() takes 1 positional argument but 3 were given
2025-08-30 23:51:03,327 - __main__ - DEBUG - Tool 'retrieve' routed to 'grade_documents' (retrieval tool)
2025-08-30 23:51:03,327 - __main__ - DEBUG - Tool 'multiply' routed to 'generate' (non-retrieval tool)
2025-08-30 23:51:03,328 - __main__ - INFO - Initialized ToolConfig with tools: {'retrieve', 'multiply'}, routing: {'retrieve': 'grade_documents', 'multiply': 'generate'}
2025-08-30 23:51:03,328 - __main__ - INFO - Database connection pool initialized
2025-08-30 23:51:03,328 - __main__ - DEBUG - Database connection pool initialized
2025-08-30 23:51:03,328 - __main__ - INFO - Connection db_connection_pool status: 0/20 connections in use
2025-08-30 23:51:03,342 - __main__ - INFO - Connection db_connection_pool status: OK, test connection successful
聊天机器人准备就绪!输入 'quit'、'exit' 或 'q' 结束对话。
User: 2025-08-30 23:52:03,335 - __main__ - INFO - Connection db_connection_pool status: 0/20 connections in use
2025-08-30 23:53:03,348 - __main__ - INFO - Connection db_connection_pool status: 0/20 connections in use
2025-08-30 23:54:03,362 - __main__ - INFO - Connection db_connection_pool status: 0/20 connections in use
2025-08-30 23:55:03,372 - __main__ - INFO - Connection db_connection_pool status: 0/20 connections in use
2025-08-30 23:56:03,381 - __main__ - INFO - Connection db_connection_pool status: 0/20 connections in use
2025-08-30 23:57:03,391 - __main__ - INFO - Connection db_connection_pool status: 0/20 connections in use
您好,请介绍一下你自己
namespace:('memories', '1')
2025-08-30 23:57:51,445 - __main__ - INFO - Agent processing user query
2025-08-30 23:57:51,447 - __main__ - INFO - agent question:content='您好,请介绍一下你自己' additional_kwargs={} response_metadata={} id='c39ff69e-7caa-437c-ae27-f3ad7517157f'
2025-08-30 23:57:51,448 - __main__ - DEBUG - Search memory for query:您好,请介绍一下你自己
2025-08-30 23:57:51,805 - httpx - INFO - HTTP Request: POST https://dashscope.aliyuncs.com/compatible-mode/v1/embeddings "HTTP/1.1 400 Bad Request"
memories : []
user_info is:
2025-08-30 23:57:51,815 - __main__ - WARNING - Memory search failed,continuing without memory:Error code: 400 - {'error': {'code': 'InvalidParameter', 'param': None, 'message': '<400> InternalError.Algo.InvalidParameter: Value error, contents is neither str nor list of str.: input.contents', 'type': 'InvalidParameter'}, 'id': '8e888abd-a5a0-955b-a2d1-bafc713f979d', 'request_id': '8e888abd-a5a0-955b-a2d1-bafc713f979d'}
2025-08-30 23:57:51,830 - __main__ - INFO - Loading and caching prompt template from prompts/prompt_template_agent.txt
2025-08-30 23:57:51,832 - __main__ - INFO - agent_chain is : first=ChatPromptTemplate(input_variables=['messages', 'question'], input_types={}, partial_variables={}, messages=[HumanMessagePromptTemplate(prompt=PromptTemplate(input_variables=['messages', 'question'], input_types={}, partial_variables={}, template='你是一个智能分诊助手,任务是根据用户的问题,分析其意图并匹配最合适的工具来解决问题。\n如果问题超出工具范围,结合已知的上下文信息,直接用简洁、自然的语言回复。不要输出自己的思考过程。\n\n已知的用户问题:\n{question}\n\n已知的上下文信息:\n{messages}\n\n你拥有以下两个工具:\n(1)健康档案查询工具。这个工具是搜索并返回有关健康档案的信息。\n(2)计算两个数的乘积工具。这个工具返回最终的计算结果。\n\n对你的要求:\n(1)分析用户输入\n仔细阅读用户的问题,识别意图。\n判断问题属于以下哪类(或多类):健康档案查询,还是直接回答问题。\n\n(2)匹配工具\n如果问题涉及询问健康档案相关的内容,使用健康档案查询工具。\n\n(3)遵守规则\n避免直接假设用户需求,除非意图非常明确。\n如果问题涉及敏感话题(如“谁该死”),回复:“我无法做出这种判断。”\n'), additional_kwargs={})]) middle=[] last=RunnableBinding(bound=ChatOpenAI(client=<openai.resources.chat.completions.completions.Completions object at 0x10b808610>, async_client=<openai.resources.chat.completions.completions.AsyncCompletions object at 0x10b808700>, root_client=<openai.OpenAI object at 0x10b808460>, root_async_client=<openai.AsyncOpenAI object at 0x10b808790>, model_name='qwen-max', temperature=0.5, model_kwargs={}, openai_api_key=SecretStr('**********'), openai_api_base='https://dashscope.aliyuncs.com/compatible-mode/v1', request_timeout=30.0, max_retries=2), kwargs={'tools': [{'type': 'function', 'function': {'name': 'retrieve', 'description': '这是健康档案查询工具,搜索并返回有关用户的健康档案信息。', 'parameters': {'properties': {'query': {'description': 'query to look up in retriever', 'type': 'string'}}, 'required': ['query'], 'type': 'object'}}}, {'type': 'function', 'function': {'name': 'multiply', 'description': '这是计算两个数的乘积的工具,返回最终的计算结果', 'parameters': {'properties': {'a': {'type': 'number'}, 'b': {'type': 'number'}}, 'required': ['a', 'b'], 'type': 'object'}}}]}, config={}, config_factories=[])
2025-08-30 23:57:55,935 - httpx - INFO - HTTP Request: POST https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions "HTTP/1.1 200 OK"
2025-08-30 23:57:55,953 - __main__ - INFO - Agent response: content='您好,我是一个智能分诊助手,我的主要任务是帮助您根据您的问题匹配最合适的服务。如果您有关于健康档案的查询需求或者需要计算两个数的乘积,都可以告诉我,我会尽力帮到您。对于其他类型的问题,我也会尽我所能提供帮助。请问您具体想了解什么呢?' additional_kwargs={'refusal': None} response_metadata={'token_usage': {'completion_tokens': 68, 'prompt_tokens': 762, 'total_tokens': 830, 'completion_tokens_details': None, 'prompt_tokens_details': {'audio_tokens': None, 'cached_tokens': 0}}, 'model_name': 'qwen-max', 'system_fingerprint': None, 'finish_reason': 'stop', 'logprobs': None} id='run--bb1e106f-ff9d-4554-af3d-10a1081b1c73-0' usage_metadata={'input_tokens': 762, 'output_tokens': 68, 'total_tokens': 830, 'input_token_details': {'cache_read': 0}, 'output_token_details': {}}
Assistant: 处理响应时发生未知错误: Object of type HumanMessage is not JSON serializable
User: 2025-08-30 23:57:55,964 - __main__ - ERROR - Error processing response: Object of type HumanMessage is not JSON serializable