Skip to content

Commit 793e25d

Browse files
authored
Disable parallel tool calls for search agent & fix azure api (#873)
2 parents 7d83fcd + 51b2aae commit 793e25d

1 file changed

Lines changed: 42 additions & 7 deletions

File tree

backend/app/utils/agent.py

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -614,18 +614,52 @@ def agent_model(
614614

615615
# Build model config, defaulting to streaming for planner
616616
extra_params = options.extra_params or {}
617+
init_param_keys = {
618+
"api_version",
619+
"azure_ad_token",
620+
"azure_ad_token_provider",
621+
"max_retries",
622+
"timeout",
623+
"client",
624+
"async_client",
625+
"azure_deployment_name",
626+
}
627+
628+
init_params = {}
617629
model_config: dict[str, Any] = {}
630+
618631
if options.is_cloud():
619632
model_config["user"] = str(options.project_id)
620-
model_config.update(
621-
{
622-
k: v
623-
for k, v in extra_params.items()
624-
if k not in ["model_platform", "model_type", "api_key", "url"]
625-
}
626-
)
633+
634+
excluded_keys = {"model_platform", "model_type", "api_key", "url"}
635+
636+
# Distribute extra_params between init_params and model_config
637+
for k, v in extra_params.items():
638+
if k in excluded_keys:
639+
continue
640+
# Skip empty values
641+
if v is None or (isinstance(v, str) and not v.strip()):
642+
continue
643+
644+
if k in init_param_keys:
645+
init_params[k] = v
646+
else:
647+
model_config[k] = v
648+
627649
if agent_name == Agents.task_agent:
628650
model_config["stream"] = True
651+
if agent_name == Agents.search_agent:
652+
try:
653+
model_platform_enum = ModelPlatformType(options.model_platform.lower())
654+
if model_platform_enum in {
655+
ModelPlatformType.OPENAI,
656+
ModelPlatformType.AZURE,
657+
ModelPlatformType.AIHUBMIX,
658+
}:
659+
model_config["parallel_tool_calls"] = False
660+
except (ValueError, AttributeError):
661+
traceroot_logger.error(f"Invalid model platform for search agent: {options.model_platform}", exc_info=True)
662+
model_platform_enum = None
629663

630664
return ListenChatAgent(
631665
options.project_id,
@@ -637,6 +671,7 @@ def agent_model(
637671
api_key=options.api_key,
638672
url=options.api_url,
639673
model_config_dict=model_config or None,
674+
**init_params,
640675
),
641676
# output_language=options.language,
642677
tools=tools,

0 commit comments

Comments
 (0)