@@ -55,12 +55,36 @@ def run_routing(goal: str) -> dict[str, Any]:
5555 "history" : history ,
5656 }
5757
58+ previous_step = history [- 1 ] if history else None
59+ previous_observation = (
60+ previous_step .get ("observation" )
61+ if isinstance (previous_step , dict )
62+ else None
63+ )
64+ previous_route = previous_step .get ("route" ) if isinstance (previous_step , dict ) else None
65+ previous_status = (
66+ previous_observation .get ("status" )
67+ if isinstance (previous_observation , dict )
68+ else None
69+ )
70+ previous_target = (
71+ previous_route .get ("target" )
72+ if isinstance (previous_route , dict )
73+ else None
74+ )
75+ forbidden_targets = (
76+ [previous_target ]
77+ if previous_status == "needs_reroute" and isinstance (previous_target , str )
78+ else []
79+ )
80+
5881 try :
5982 raw_route = decide_route (
6083 goal = goal ,
6184 history = history ,
6285 max_route_attempts = BUDGET .max_route_attempts ,
6386 remaining_attempts = (BUDGET .max_route_attempts - attempt + 1 ),
87+ forbidden_targets = forbidden_targets ,
6488 )
6589 except LLMTimeout :
6690 return {
@@ -75,6 +99,8 @@ def run_routing(goal: str) -> dict[str, Any]:
7599 route_action = validate_route_action (
76100 raw_route ,
77101 allowed_routes = ALLOWED_ROUTE_TARGETS_POLICY ,
102+ previous_target = previous_target ,
103+ previous_status = previous_status ,
78104 )
79105 except StopRun as exc :
80106 return {
@@ -88,33 +114,6 @@ def run_routing(goal: str) -> dict[str, Any]:
88114
89115 target = route_action ["target" ]
90116 route_args = route_action ["args" ]
91- previous_step = history [- 1 ] if history else None
92- previous_observation = (
93- previous_step .get ("observation" )
94- if isinstance (previous_step , dict )
95- else None
96- )
97- previous_route = previous_step .get ("route" ) if isinstance (previous_step , dict ) else None
98- previous_status = (
99- previous_observation .get ("status" )
100- if isinstance (previous_observation , dict )
101- else None
102- )
103- previous_target = (
104- previous_route .get ("target" )
105- if isinstance (previous_route , dict )
106- else None
107- )
108-
109- if previous_status == "needs_reroute" and target == previous_target :
110- return {
111- "status" : "stopped" ,
112- "stop_reason" : "invalid_route:repeat_target_after_reroute" ,
113- "phase" : "route" ,
114- "route" : route_action ,
115- "trace" : trace ,
116- "history" : history ,
117- }
118117
119118 try :
120119 observation = gateway .call (target , route_args )
@@ -166,6 +165,8 @@ def run_routing(goal: str) -> dict[str, Any]:
166165 "stop_reason" : "route_bad_observation" ,
167166 "phase" : "delegate" ,
168167 "route" : route_action ,
168+ "expected_statuses" : ["needs_reroute" , "done" ],
169+ "received_status" : observation_status ,
169170 "bad_observation" : observation ,
170171 "trace" : trace ,
171172 "history" : history ,
0 commit comments