优化 岗位编辑agent 性能

This commit is contained in:
zk
2026-04-14 12:12:46 +08:00
parent 9bc8bb492c
commit ebffbc8615
4 changed files with 326 additions and 120 deletions
+42 -13
View File
@@ -14,7 +14,7 @@ from langchain_core.prompts import ChatPromptTemplate
from app.ai.models import LLM
from app.ai.skill_gap_analyzer.prompts import (
SKILL_GAP_PROMPT, SUMMARY_OPTIMIZE_PROMPT, EXPERIENCE_OPTIMIZE_PROMPT,
AGENT_PLAN_PROMPT, AGENT_MODULE_EDIT_PROMPT, MODULE_SCHEMAS,
AGENT_PLAN_PROMPT, AGENT_MODULE_EDIT_PROMPT, AGENT_MODULE_ADD_PROMPT, MODULE_SCHEMAS,
)
from app.core.logger import log
@@ -100,11 +100,13 @@ _plan_chain = (
)
async def plan_edit(job_title: str, resume_json: str, chat_history: str, instruction: str) -> dict | None:
"""Agent 规划:分析用户指令,返回修改计划或对话回复"""
async def plan_edit(job_title: str, job_description: str, resume_json: str,
chat_history: str, instruction: str) -> dict | None:
"""Agent 规划:分析用户指令,返回原子操作列表或对话回复"""
try:
raw = await _plan_chain.ainvoke({
"job_title": job_title, "resume_json": resume_json,
"job_title": job_title, "job_description": job_description,
"resume_json": resume_json,
"chat_history": chat_history, "instruction": instruction,
})
result = _parse_json(raw)
@@ -114,24 +116,51 @@ async def plan_edit(job_title: str, resume_json: str, chat_history: str, instruc
return None
# ===== Agent - 模块修改 =====
# ===== Agent - 单条记录修改 =====
_module_edit_chain = (
_record_edit_chain = (
ChatPromptTemplate.from_messages([("system", AGENT_MODULE_EDIT_PROMPT), ("human", "请执行修改。")])
| LLM.GPT_4O.create(temperature=0.3)
| StrOutputParser()
)
async def execute_module_edit(job_title: str, module_instruction: str,
module_schema: str, module_data: str) -> dict | list | None:
"""Agent 模块修改:根据指令修改指定模块数据"""
async def execute_record_edit(job_title: str, job_description: str, instruction: str,
chat_history: str, module_schema: str,
record_data: str) -> dict | list | None:
"""修改单条记录:根据指令修改指定记录数据"""
try:
raw = await _module_edit_chain.ainvoke({
"job_title": job_title, "module_instruction": module_instruction,
"module_schema": module_schema, "module_data": module_data,
raw = await _record_edit_chain.ainvoke({
"job_title": job_title, "job_description": job_description,
"instruction": instruction, "chat_history": chat_history,
"module_schema": module_schema, "record_data": record_data,
})
return _parse_json(raw)
except Exception as e:
log.warning(f"AI模块修改失败: {e}")
log.warning(f"AI单条记录修改失败: {e}")
return None
# ===== Agent - 新增记录 =====
_record_add_chain = (
ChatPromptTemplate.from_messages([("system", AGENT_MODULE_ADD_PROMPT), ("human", "请生成新记录。")])
| LLM.GPT_4O.create(temperature=0.3)
| StrOutputParser()
)
async def execute_record_add(job_title: str, job_description: str, instruction: str,
chat_history: str, module_schema: str) -> dict | None:
"""新增一条记录:根据指令生成新记录"""
try:
raw = await _record_add_chain.ainvoke({
"job_title": job_title, "job_description": job_description,
"instruction": instruction, "chat_history": chat_history,
"module_schema": module_schema,
})
result = _parse_json(raw)
return result if isinstance(result, dict) else None
except Exception as e:
log.warning(f"AI新增记录失败: {e}")
return None