diff --git a/src/graph/nodes.py b/src/graph/nodes.py index b0b8cad..14616f9 100644 --- a/src/graph/nodes.py +++ b/src/graph/nodes.py @@ -308,17 +308,34 @@ async def _execute_agent_step( observations = state.get("observations", []) # Find the first unexecuted step + current_step = None + completed_steps = [] for step in current_plan.steps: if not step.execution_res: + current_step = step break + else: + completed_steps.append(step) - logger.info(f"Executing step: {step.title}") + if not current_step: + logger.warning("No unexecuted step found") + return Command(goto="research_team") - # Prepare the input for the agent + logger.info(f"Executing step: {current_step.title}") + + # Format completed steps information + completed_steps_info = "" + if completed_steps: + completed_steps_info = "# Existing Research Findings\n\n" + for i, step in enumerate(completed_steps): + completed_steps_info += f"## Existing Finding {i+1}: {step.title}\n\n" + completed_steps_info += f"\n{step.execution_res}\n\n\n" + + # Prepare the input for the agent with completed steps info agent_input = { "messages": [ HumanMessage( - content=f"#Task\n\n##title\n\n{step.title}\n\n##description\n\n{step.description}\n\n##locale\n\n{state.get('locale', 'en-US')}" + content=f"{completed_steps_info}# Current Task\n\n## title\n\n{current_step.title}\n\n## description\n\n{current_step.description}\n\n## locale\n\n{state.get('locale', 'en-US')}" ) ] } @@ -340,8 +357,8 @@ async def _execute_agent_step( logger.debug(f"{agent_name.capitalize()} full response: {response_content}") # Update the step with the execution result - step.execution_res = response_content - logger.info(f"Step '{step.title}' execution completed by {agent_name}") + current_step.execution_res = response_content + logger.info(f"Step '{current_step.title}' execution completed by {agent_name}") return Command( update={