From 3191e819397a56a4827692535fd6ac8cd7a7ffba Mon Sep 17 00:00:00 2001 From: Willem Jiang Date: Sat, 6 Dec 2025 11:15:11 +0800 Subject: [PATCH] fix: passing the locale to create_react_agent (#745) --- src/agents/agents.py | 11 ++++++++--- src/graph/nodes.py | 6 ++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/agents/agents.py b/src/agents/agents.py index df94bd3..7310cc1 100644 --- a/src/agents/agents.py +++ b/src/agents/agents.py @@ -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, ) diff --git a/src/graph/nodes.py b/src/graph/nodes.py index ed7584d..8f9497e 100644 --- a/src/graph/nodes.py +++ b/src/graph/nodes.py @@ -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)