[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 import workspace_service
|
||||||
from app.services.app_chat_service import AppChatService, get_app_chat_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.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
|
from app.services.app_service import get_app_service, AppService
|
||||||
|
|
||||||
router = APIRouter(prefix="/app", tags=["V1 - App API"])
|
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"))
|
return success(data=conversation_schema.ChatResponse(**result).model_dump(mode="json"))
|
||||||
elif app_type == AppType.MULTI_AGENT:
|
elif app_type == AppType.MULTI_AGENT:
|
||||||
# 多 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:
|
if payload.stream:
|
||||||
async def event_generator():
|
async def event_generator():
|
||||||
async for event in app_chat_service.multi_agent_chat_stream(
|
async for event in app_chat_service.multi_agent_chat_stream(
|
||||||
|
|||||||
@@ -1203,11 +1203,11 @@ class AppService:
|
|||||||
self._check_multi_agent_config(app_id)
|
self._check_multi_agent_config(app_id)
|
||||||
|
|
||||||
# 3. 获取主 Agent 的模型配置 ID
|
# 3. 获取主 Agent 的模型配置 ID
|
||||||
master_agent = self.db.get(AgentConfig, multi_agent_cfg.master_agent_id)
|
default_model_config_id = multi_agent_cfg.default_model_config_id
|
||||||
default_model_config_id = master_agent.default_model_config_id if master_agent else None
|
|
||||||
|
|
||||||
# 4. 构建配置快照
|
# 4. 构建配置快照
|
||||||
config = {
|
config = {
|
||||||
|
"model_parameters":multi_agent_cfg.model_parameters,
|
||||||
"master_agent_id": str(multi_agent_cfg.master_agent_id),
|
"master_agent_id": str(multi_agent_cfg.master_agent_id),
|
||||||
"orchestration_mode": multi_agent_cfg.orchestration_mode,
|
"orchestration_mode": multi_agent_cfg.orchestration_mode,
|
||||||
"sub_agents": multi_agent_cfg.sub_agents,
|
"sub_agents": multi_agent_cfg.sub_agents,
|
||||||
@@ -1220,7 +1220,7 @@ class AppService:
|
|||||||
"多智能体应用发布配置准备完成",
|
"多智能体应用发布配置准备完成",
|
||||||
extra={
|
extra={
|
||||||
"app_id": str(app_id),
|
"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,
|
"sub_agent_count": len(multi_agent_cfg.sub_agents) if multi_agent_cfg.sub_agents else 0,
|
||||||
"orchestration_mode": multi_agent_cfg.orchestration_mode
|
"orchestration_mode": multi_agent_cfg.orchestration_mode
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,8 @@ from typing import Dict, Any, Optional
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
from app.models import AppRelease
|
from app.models import AppRelease
|
||||||
|
from app.models.agent_app_config_model import AgentConfig
|
||||||
|
from app.models.multi_agent_model import MultiAgentConfig
|
||||||
|
|
||||||
class AgentConfigProxy:
|
class AgentConfigProxy:
|
||||||
"""Proxy class for AgentConfig (legacy compatibility)"""
|
"""Proxy class for AgentConfig (legacy compatibility)"""
|
||||||
@@ -24,18 +25,8 @@ class AgentConfigProxy:
|
|||||||
self.default_model_config_id = release.default_model_config_id
|
self.default_model_config_id = release.default_model_config_id
|
||||||
|
|
||||||
|
|
||||||
def agent_config_4_app_release(release: AppRelease ):
|
def agent_config_4_app_release(release: AppRelease ) -> AgentConfig:
|
||||||
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
|
config_dict = release.config
|
||||||
|
|
||||||
agent_config = AgentConfig(
|
agent_config = AgentConfig(
|
||||||
@@ -51,6 +42,26 @@ def agent_config_4_app_release(release: AppRelease ):
|
|||||||
|
|
||||||
return agent_config
|
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):
|
def dict_to_multi_agent_config(config_dict: Dict[str, Any], app_id: Optional[uuid.UUID] = None):
|
||||||
"""Convert dict to MultiAgentConfig model object
|
"""Convert dict to MultiAgentConfig model object
|
||||||
|
|||||||
Reference in New Issue
Block a user