fix: start_agent query by org_id, auto-execute tasks, link creation+execution
This commit is contained in:
parent
28820a0b29
commit
73935ae652
@ -358,7 +358,7 @@ if action == 'send_message':
|
||||
title = intent.get('title', '') or message_text[:100]
|
||||
task_params = {'description': intent.get('description', ''), 'input_text': message_text}
|
||||
try:
|
||||
# Direct task creation (bypass pipeline_submit to avoid executor issues)
|
||||
# Direct task creation
|
||||
task_id = getID()
|
||||
await sor.C('pipeline_tasks', {
|
||||
'id': task_id, 'tenant_id': org_id, 'pipeline_id': 'sdlc_general',
|
||||
@ -366,7 +366,25 @@ if action == 'send_message':
|
||||
'params': json.dumps(task_params, ensure_ascii=False)
|
||||
})
|
||||
await _save_context(sor, uid, pid, iid)
|
||||
agent_reply = f"✅ 任务「{title}」已提交({task_id})。"
|
||||
|
||||
# Auto-execute: call LLM to work on the task
|
||||
task_msgs = [{"role": "system", "content": settings['system_prompt']}]
|
||||
task_msgs.append({"role": "user", "content": f"请完成以下开发任务:\n{title}\n\n{json.dumps(task_params, ensure_ascii=False)}"})
|
||||
try:
|
||||
result = await _call_llm(model_info, task_msgs, settings['temperature'])
|
||||
# Save deliverable
|
||||
did = getID()
|
||||
await sor.C('pipeline_deliverables', {
|
||||
'id': did, 'project_id': pid, 'task_id': task_id,
|
||||
'deliverable_type': 'code', 'title': title, 'content': result,
|
||||
'quality_score': 80, 'review_status': 'pending', 'created_by': 'agent'
|
||||
})
|
||||
await sor.sqlExe("UPDATE pipeline_tasks SET state='completed' WHERE id=${tid}$", {"tid": task_id})
|
||||
agent_reply = f"✅ 任务「{title}」已完成。\n\n{result[:1500]}"
|
||||
if len(result) > 1500:
|
||||
agent_reply += f"\n\n...(共{len(result)}字,完整内容已保存到交付件 {did})"
|
||||
except Exception as e2:
|
||||
agent_reply = f"✅ 任务「{title}」已创建({task_id}),但执行失败:{str(e2)[:200]}"
|
||||
except Exception as e:
|
||||
agent_reply = f"任务提交失败:{str(e)[:200]}"
|
||||
elif intent_type == 'add_bug':
|
||||
@ -397,17 +415,30 @@ if action == 'send_message':
|
||||
if not pid:
|
||||
agent_reply = "请先指定项目。「创建XXX项目」或「切换到XXX项目」"
|
||||
else:
|
||||
# Direct query — avoid run_agent_loop's separate DB context
|
||||
tasks = await sor.sqlExe(
|
||||
"SELECT id, title, state FROM pipeline_tasks WHERE tenant_id=${pid}$ AND state='submitted' LIMIT 5",
|
||||
{"pid": pid})
|
||||
"SELECT id, title, state FROM pipeline_tasks WHERE tenant_id=${oid}$ AND state='submitted' LIMIT 5",
|
||||
{"oid": org_id})
|
||||
if not tasks:
|
||||
agent_reply = f"项目「{ctx['project_name']}」暂无待执行任务。\n\n请先提交开发任务,例如:设计用户表结构"
|
||||
else:
|
||||
lines = [f"📋 项目「{ctx['project_name']}」待执行任务:"]
|
||||
# Execute each pending task
|
||||
results = []
|
||||
for t in tasks:
|
||||
lines.append(f" · {t.title} [{t.state}]")
|
||||
agent_reply = '\n'.join(lines) + '\n\n输入具体任务名开始执行。'
|
||||
try:
|
||||
task_msgs = [{"role": "system", "content": settings['system_prompt']}]
|
||||
task_msgs.append({"role": "user", "content": f"请完成:{t.title}"})
|
||||
result = await _call_llm(model_info, task_msgs, settings['temperature'])
|
||||
did = getID()
|
||||
await sor.C('pipeline_deliverables', {
|
||||
'id': did, 'project_id': pid, 'task_id': t.id,
|
||||
'deliverable_type': 'code', 'title': t.title, 'content': result,
|
||||
'quality_score': 80, 'review_status': 'pending', 'created_by': 'agent'
|
||||
})
|
||||
await sor.sqlExe("UPDATE pipeline_tasks SET state='completed' WHERE id=${tid}$", {"tid": t.id})
|
||||
results.append(f"✅ {t.title} → 交付件 {did}")
|
||||
except Exception as e2:
|
||||
results.append(f"❌ {t.title}:{str(e2)[:80]}")
|
||||
agent_reply = '\n'.join(results) if results else "无需执行的任务"
|
||||
elif intent_type == 'agent_status':
|
||||
pid = ctx['project_id']
|
||||
if not pid:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user