fix: map agent workflow inputs
This commit is contained in:
@@ -9,7 +9,7 @@ from sqlalchemy import select
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from ai_platform.models import (
|
||||
Agent, AgentConversation, AgentMessage, LLMModel,
|
||||
Agent, AgentConversation, AgentMessage, AIWorkflow, LLMModel,
|
||||
)
|
||||
from .llm_service import LLMService
|
||||
|
||||
@@ -433,16 +433,16 @@ class AgentService:
|
||||
if accumulated:
|
||||
final_content = accumulated
|
||||
elif event_type == 'node_complete':
|
||||
node_type = event.get('node_type')
|
||||
if node_type == 'llm':
|
||||
outputs = event.get('outputs', {})
|
||||
output = outputs.get('output', '')
|
||||
if output:
|
||||
final_content = output
|
||||
output = (event.get('outputs') or {}).get('output', '')
|
||||
if output:
|
||||
final_content = output
|
||||
elif event_type == 'waiting_input':
|
||||
is_waiting = True
|
||||
elif event_type == 'complete':
|
||||
total_tokens = event.get('total_tokens', 0)
|
||||
output = (event.get('outputs') or {}).get('output', '')
|
||||
if output:
|
||||
final_content = output
|
||||
|
||||
yield event
|
||||
else:
|
||||
@@ -465,7 +465,7 @@ class AgentService:
|
||||
if attachment_texts:
|
||||
enhanced_user_input = user_message + '\n' + '\n'.join(attachment_texts)
|
||||
|
||||
workflow_inputs = {'user_input': enhanced_user_input}
|
||||
workflow_inputs = await self._build_workflow_inputs(agent, enhanced_user_input)
|
||||
if application_id:
|
||||
workflow_inputs['application_id'] = application_id
|
||||
if form_code:
|
||||
@@ -495,12 +495,9 @@ class AgentService:
|
||||
if accumulated:
|
||||
final_content = accumulated
|
||||
elif event_type == 'node_complete':
|
||||
node_type = event.get('node_type')
|
||||
if node_type == 'llm':
|
||||
outputs = event.get('outputs', {})
|
||||
output = outputs.get('output', '')
|
||||
if output:
|
||||
final_content = output
|
||||
output = (event.get('outputs') or {}).get('output', '')
|
||||
if output:
|
||||
final_content = output
|
||||
elif event_type == 'waiting_input':
|
||||
is_waiting = True
|
||||
# 保存工作流运行 ID 到对话元数据
|
||||
@@ -509,6 +506,9 @@ class AgentService:
|
||||
conversation.extra_data['workflow_run_id'] = current_run_id
|
||||
elif event_type == 'complete':
|
||||
total_tokens = event.get('total_tokens', 0)
|
||||
output = (event.get('outputs') or {}).get('output', '')
|
||||
if output:
|
||||
final_content = output
|
||||
|
||||
yield event
|
||||
|
||||
@@ -552,6 +552,35 @@ class AgentService:
|
||||
'type': 'error',
|
||||
'content': str(e),
|
||||
}
|
||||
|
||||
async def _build_workflow_inputs(self, agent: Agent, user_input: str) -> Dict[str, Any]:
|
||||
workflow_inputs: Dict[str, Any] = {'user_input': user_input}
|
||||
if not self._db or not agent.workflow_id:
|
||||
return workflow_inputs
|
||||
|
||||
result = await self._db.execute(
|
||||
select(AIWorkflow).where(
|
||||
AIWorkflow.id == agent.workflow_id,
|
||||
AIWorkflow.is_deleted == False,
|
||||
)
|
||||
)
|
||||
workflow = result.scalar_one_or_none()
|
||||
if not workflow:
|
||||
return workflow_inputs
|
||||
|
||||
input_variables = workflow.input_variables or []
|
||||
if any((item or {}).get('name') == 'request' for item in input_variables):
|
||||
workflow_inputs.setdefault('request', user_input)
|
||||
if any((item or {}).get('name') == 'issue_id' for item in input_variables):
|
||||
workflow_inputs.setdefault('issue_id', self._extract_issue_id(user_input))
|
||||
return workflow_inputs
|
||||
|
||||
@staticmethod
|
||||
def _extract_issue_id(text: str) -> str:
|
||||
import re
|
||||
|
||||
match = re.search(r'\b[A-Z][A-Z0-9]+-\d+\b', text or '', re.IGNORECASE)
|
||||
return match.group(0).upper() if match else 'MANUAL-1'
|
||||
|
||||
def _build_system_prompt_simple(self, agent: Agent) -> str:
|
||||
"""构建简化的系统提示词"""
|
||||
|
||||
Reference in New Issue
Block a user