mirror of
https://gitee.com/wanwujie/deer-flow
synced 2026-04-03 06:12:14 +08:00
fix: passing the locale to create_react_agent (#745)
This commit is contained in:
@@ -22,6 +22,7 @@ def create_agent(
|
||||
prompt_template: str,
|
||||
pre_model_hook: callable = None,
|
||||
interrupt_before_tools: Optional[List[str]] = None,
|
||||
locale: str = "en-US",
|
||||
):
|
||||
"""Factory function to create agents with consistent configuration.
|
||||
|
||||
@@ -32,6 +33,7 @@ def create_agent(
|
||||
prompt_template: Name of the prompt template to use
|
||||
pre_model_hook: Optional hook to preprocess state before model invocation
|
||||
interrupt_before_tools: Optional list of tool names to interrupt before execution
|
||||
locale: Language locale for prompt template selection (e.g., en-US, zh-CN)
|
||||
|
||||
Returns:
|
||||
A configured agent graph
|
||||
@@ -62,13 +64,16 @@ def create_agent(
|
||||
llm_type = AGENT_LLM_MAP.get(agent_type, "basic")
|
||||
logger.debug(f"Agent '{agent_name}' using LLM type: {llm_type}")
|
||||
|
||||
logger.debug(f"Creating ReAct agent '{agent_name}'")
|
||||
logger.debug(f"Creating ReAct agent '{agent_name}' with locale: {locale}")
|
||||
# Use closure to capture locale from the workflow state instead of relying on
|
||||
# agent state.get("locale"), which doesn't have the locale field
|
||||
# See: https://github.com/bytedance/deer-flow/issues/743
|
||||
agent = create_react_agent(
|
||||
name=agent_name,
|
||||
model=get_llm_by_type(llm_type),
|
||||
tools=processed_tools,
|
||||
prompt=lambda state: apply_prompt_template(
|
||||
prompt_template, state, locale=state.get("locale", "en-US")
|
||||
prompt=lambda state, captured_locale=locale: apply_prompt_template(
|
||||
prompt_template, state, locale=captured_locale
|
||||
),
|
||||
pre_model_hook=pre_model_hook,
|
||||
)
|
||||
|
||||
@@ -1115,6 +1115,10 @@ async def _setup_and_execute_agent_step(
|
||||
configurable = Configuration.from_runnable_config(config)
|
||||
mcp_servers = {}
|
||||
enabled_tools = {}
|
||||
|
||||
# Get locale from workflow state to pass to agent creation
|
||||
# This fixes issue #743 where locale was not correctly retrieved in agent prompt
|
||||
locale = state.get("locale", "en-US")
|
||||
|
||||
# Extract MCP server configuration for this agent type
|
||||
if configurable.mcp_settings:
|
||||
@@ -1152,6 +1156,7 @@ async def _setup_and_execute_agent_step(
|
||||
agent_type,
|
||||
pre_model_hook,
|
||||
interrupt_before_tools=configurable.interrupt_before_tools,
|
||||
locale=locale,
|
||||
)
|
||||
return await _execute_agent_step(state, agent, agent_type, config)
|
||||
else:
|
||||
@@ -1165,6 +1170,7 @@ async def _setup_and_execute_agent_step(
|
||||
agent_type,
|
||||
pre_model_hook,
|
||||
interrupt_before_tools=configurable.interrupt_before_tools,
|
||||
locale=locale,
|
||||
)
|
||||
return await _execute_agent_step(state, agent, agent_type, config)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user