[fix] app api multi agent call
This commit is contained in:
@@ -21,7 +21,7 @@ from app.schemas.api_key_schema import ApiKeyAuth
|
||||
from app.services import workspace_service
|
||||
from app.services.app_chat_service import AppChatService, get_app_chat_service
|
||||
from app.services.conversation_service import ConversationService, get_conversation_service
|
||||
from app.utils.app_config_utils import dict_to_multi_agent_config, dict_to_workflow_config, agent_config_4_app_release
|
||||
from app.utils.app_config_utils import dict_to_multi_agent_config, dict_to_workflow_config, agent_config_4_app_release, multi_agent_config_4_app_release
|
||||
from app.services.app_service import get_app_service, AppService
|
||||
|
||||
router = APIRouter(prefix="/app", tags=["V1 - App API"])
|
||||
@@ -182,7 +182,7 @@ async def chat(
|
||||
return success(data=conversation_schema.ChatResponse(**result).model_dump(mode="json"))
|
||||
elif app_type == AppType.MULTI_AGENT:
|
||||
# 多 Agent 流式返回
|
||||
config = dict_to_multi_agent_config(app.current_release.config,app.id)
|
||||
config = multi_agent_config_4_app_release(app.current_release)
|
||||
if payload.stream:
|
||||
async def event_generator():
|
||||
async for event in app_chat_service.multi_agent_chat_stream(
|
||||
|
||||
@@ -1203,11 +1203,11 @@ class AppService:
|
||||
self._check_multi_agent_config(app_id)
|
||||
|
||||
# 3. 获取主 Agent 的模型配置 ID
|
||||
master_agent = self.db.get(AgentConfig, multi_agent_cfg.master_agent_id)
|
||||
default_model_config_id = master_agent.default_model_config_id if master_agent else None
|
||||
default_model_config_id = multi_agent_cfg.default_model_config_id
|
||||
|
||||
# 4. 构建配置快照
|
||||
config = {
|
||||
"model_parameters":multi_agent_cfg.model_parameters,
|
||||
"master_agent_id": str(multi_agent_cfg.master_agent_id),
|
||||
"orchestration_mode": multi_agent_cfg.orchestration_mode,
|
||||
"sub_agents": multi_agent_cfg.sub_agents,
|
||||
@@ -1220,7 +1220,7 @@ class AppService:
|
||||
"多智能体应用发布配置准备完成",
|
||||
extra={
|
||||
"app_id": str(app_id),
|
||||
"master_agent_id": str(multi_agent_cfg.master_agent_id),
|
||||
"default_model_config_id": str(default_model_config_id),
|
||||
"sub_agent_count": len(multi_agent_cfg.sub_agents) if multi_agent_cfg.sub_agents else 0,
|
||||
"orchestration_mode": multi_agent_cfg.orchestration_mode
|
||||
}
|
||||
|
||||
@@ -9,7 +9,8 @@ from typing import Dict, Any, Optional
|
||||
from datetime import datetime
|
||||
|
||||
from app.models import AppRelease
|
||||
|
||||
from app.models.agent_app_config_model import AgentConfig
|
||||
from app.models.multi_agent_model import MultiAgentConfig
|
||||
|
||||
class AgentConfigProxy:
|
||||
"""Proxy class for AgentConfig (legacy compatibility)"""
|
||||
@@ -24,20 +25,10 @@ class AgentConfigProxy:
|
||||
self.default_model_config_id = release.default_model_config_id
|
||||
|
||||
|
||||
def agent_config_4_app_release(release: AppRelease ):
|
||||
from app.models.agent_app_config_model import AgentConfig
|
||||
# Create AgentConfig instance
|
||||
# config = {
|
||||
# "system_prompt": agent_cfg.system_prompt,
|
||||
# "model_parameters": agent_cfg.model_parameters,
|
||||
# "knowledge_retrieval": agent_cfg.knowledge_retrieval,
|
||||
# "memory": agent_cfg.memory,
|
||||
# "variables": agent_cfg.variables or [],
|
||||
# "tools": agent_cfg.tools or {},
|
||||
# }
|
||||
#
|
||||
config_dict = release.config
|
||||
def agent_config_4_app_release(release: AppRelease ) -> AgentConfig:
|
||||
|
||||
config_dict = release.config
|
||||
|
||||
agent_config = AgentConfig(
|
||||
app_id=release.app_id,
|
||||
system_prompt=config_dict.get("system_prompt"),
|
||||
@@ -51,6 +42,26 @@ def agent_config_4_app_release(release: AppRelease ):
|
||||
|
||||
return agent_config
|
||||
|
||||
def multi_agent_config_4_app_release(release: AppRelease ) -> MultiAgentConfig:
|
||||
|
||||
config_dict = release.config
|
||||
|
||||
|
||||
agent_config = MultiAgentConfig(
|
||||
app_id=release.app_id,
|
||||
default_model_config_id=release.default_model_config_id,
|
||||
model_parameters=config_dict.get("model_parameters"),
|
||||
master_agent_id=config_dict.get("master_agent_id"),
|
||||
master_agent_name=config_dict.get("master_agent_name"),
|
||||
orchestration_mode=config_dict.get("orchestration_mode", "conditional"),
|
||||
sub_agents=config_dict.get("sub_agents", []),
|
||||
routing_rules=config_dict.get("routing_rules"),
|
||||
execution_config=config_dict.get("execution_config", {}),
|
||||
aggregation_strategy=config_dict.get("aggregation_strategy", "merge"),
|
||||
|
||||
)
|
||||
|
||||
return agent_config
|
||||
|
||||
def dict_to_multi_agent_config(config_dict: Dict[str, Any], app_id: Optional[uuid.UUID] = None):
|
||||
"""Convert dict to MultiAgentConfig model object
|
||||
|
||||
Reference in New Issue
Block a user