2025-04-17 11:34:42 +08:00
|
|
|
# Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
|
|
|
# SPDX-License-Identifier: MIT
|
|
|
|
|
|
2025-04-07 16:25:55 +08:00
|
|
|
from langgraph.prebuilt import create_react_agent
|
|
|
|
|
|
|
|
|
|
from src.config.agents import AGENT_LLM_MAP
|
2025-08-17 22:57:23 +08:00
|
|
|
from src.llms.llm import get_llm_by_type
|
|
|
|
|
from src.prompts import apply_prompt_template
|
2025-04-07 16:25:55 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
# Create agents using configured LLM types
|
2025-09-27 06:42:22 -07:00
|
|
|
def create_agent(
|
|
|
|
|
agent_name: str,
|
|
|
|
|
agent_type: str,
|
|
|
|
|
tools: list,
|
|
|
|
|
prompt_template: str,
|
|
|
|
|
pre_model_hook: callable = None,
|
|
|
|
|
):
|
2025-04-07 16:25:55 +08:00
|
|
|
"""Factory function to create agents with consistent configuration."""
|
|
|
|
|
return create_react_agent(
|
|
|
|
|
name=agent_name,
|
|
|
|
|
model=get_llm_by_type(AGENT_LLM_MAP[agent_type]),
|
|
|
|
|
tools=tools,
|
2025-10-24 16:31:19 +08:00
|
|
|
prompt=lambda state: apply_prompt_template(
|
|
|
|
|
prompt_template, state, locale=state.get("locale", "en-US")
|
|
|
|
|
),
|
2025-09-27 06:42:22 -07:00
|
|
|
pre_model_hook=pre_model_hook,
|
2025-04-07 16:25:55 +08:00
|
|
|
)
|