@@ -26,6 +26,8 @@ async def expand_node(
2626
2727 # Prepare inputs files for the agent based on reference_code and parent_node
2828 self ._prepare_inputs (session_dir , parent_node , reference_code )
29+ # Prepare initial state
30+ initial_state = self ._prepare_initial_state (parent_node )
2931
3032 # Run the agent and process results
3133 try :
@@ -34,6 +36,7 @@ async def expand_node(
3436 session_dir = session_dir ,
3537 strategy = strategy ,
3638 agent_config = agent_config ,
39+ initial_state = initial_state ,
3740 )
3841 return self ._process_results (
3942 node_id = node_id ,
@@ -76,12 +79,29 @@ def _prepare_inputs(
7679 with open (kernel_plan_path , "w" ) as f :
7780 f .write (parent_node .plan )
7881
82+ def _prepare_initial_state (self , parent_node : Node ) -> Dict [str , Any ]:
83+ initial_state = {}
84+ if parent_node .evaluation :
85+ initial_state = {
86+ "kernel_compilation_status" : {
87+ "success" : parent_node .evaluation .compiled ,
88+ "message" : parent_node .evaluation .compilation_error ,
89+ },
90+ "test_results" : {
91+ "success" : parent_node .evaluation .correct ,
92+ "output" : parent_node .evaluation .test_error ,
93+ },
94+ "profiling_summary" : parent_node .evaluation .profiling_summary ,
95+ }
96+ return initial_state
97+
7998 async def _run_agent (
8099 self ,
81100 node_id : str ,
82101 session_dir : str ,
83102 strategy : Optional [str ],
84103 agent_config : Optional [Dict [str , Any ]] = None ,
104+ initial_state : Optional [Dict [str , Any ]] = None ,
85105 ) -> Dict [str , Any ]:
86106 """Sets up a custom AutonomousPipelineAgent and runs the client."""
87107 agent_config = agent_config or {}
@@ -111,7 +131,8 @@ async def _run_agent(
111131 query = query ,
112132 agent = custom_agent ,
113133 )
114- await client .create_session ()
134+
135+ await client .create_session (initial_state )
115136 await client .run_async ()
116137 try :
117138 session_json_path = os .path .join (session_dir , "session.json" )
@@ -144,7 +165,13 @@ def _process_results(
144165
145166 comp_status = best_run .get ("compilation_status" , {})
146167 compiled = comp_status .get ("success" , False )
147- compilation_error = comp_status .get ("message" ) if not compiled else None
168+ compilation_error = None
169+ if not compiled :
170+ compilation_error = comp_status .get ("message" , "" )
171+ if comp_status .get ("final_errors" ):
172+ compilation_error += "\n \n Final Errors:\n " + comp_status .get (
173+ "final_errors"
174+ )
148175
149176 test_status = best_run .get ("test_status" , {})
150177 correct = test_status .get ("success" , False )
0 commit comments