Execute a single step in the execution plan. Handles step execution by: 1. Generating specialized system prompt for the step 2. Gathering context from dependent steps 3. Substituting variables in arguments 4. Executing the step with appropriate error handling Args:
(
state: RuntimeState,
step_id: StepID,
llm: Optional[ChatOpenAI] = None,
save_steps: bool = False,
output_dir: str = './steps'
)
| 829 | from langchain_core.output_parsers import StrOutputParser |
| 830 | |
| 831 | async def execute_step( |
| 832 | state: RuntimeState, |
| 833 | step_id: StepID, |
| 834 | llm: Optional[ChatOpenAI] = None, |
| 835 | save_steps: bool = False, |
| 836 | output_dir: str = './steps' |
| 837 | ) -> Dict[str, Any]: |
| 838 | """Execute a single step in the execution plan. |
| 839 | |
| 840 | Handles step execution by: |
| 841 | 1. Generating specialized system prompt for the step |
| 842 | 2. Gathering context from dependent steps |
| 843 | 3. Substituting variables in arguments |
| 844 | 4. Executing the step with appropriate error handling |
| 845 | |
| 846 | Args: |
| 847 | state: Current runtime state |
| 848 | step_id: ID of step to execute |
| 849 | llm: Optional LLM instance to use |
| 850 | save_steps: Whether to save step results to files |
| 851 | output_dir: Directory to save step files |
| 852 | |
| 853 | Returns: |
| 854 | Dict[str, Any]: Updates to state including step results |
| 855 | """ |
| 856 | try: |
| 857 | step_key = str(step_id) |
| 858 | step_info = state["step_data"][step_key] |
| 859 | logger.info(f"Executing step #{step_key}: {step_info.description}") |
| 860 | |
| 861 | # Create or use provided LLM instance |
| 862 | step_llm = llm or create_llm() |
| 863 | |
| 864 | # Generate specialized system prompt |
| 865 | system_prompt = await generate_specialist_prompt(step_info.description) |
| 866 | logger.debug(f"Generated system prompt for step {step_id}") |
| 867 | |
| 868 | # Build context from dependencies |
| 869 | context = [] |
| 870 | agent_results = state.get("agent_results", {}) |
| 871 | |
| 872 | for dep in step_info.depends_on: |
| 873 | if str(dep) in agent_results: |
| 874 | result = agent_results[str(dep)].get("result") |
| 875 | context.append(f"Previous step {dep}: {result}") |
| 876 | else: |
| 877 | logger.warning(f"Missing result for dependency {dep}") |
| 878 | context.append(f"Previous step {dep}: Not found") |
| 879 | |
| 880 | # Substitute variables in arguments |
| 881 | step_args = substitute_variables( |
| 882 | step_info.args, |
| 883 | step_info.depends_on, |
| 884 | agent_results |
| 885 | ) |
| 886 | |
| 887 | # Create and execute prompt |
| 888 | prompt = ChatPromptTemplate.from_messages([ |
nothing calls this directly
no test coverage detected