MCPcopy Create free account
hub / github.com/MARIO-Math-Reasoning/Super_MARIO / code_execution

Function code_execution

mcts_math/agents/tree.py:132–160  ·  view source on GitHub ↗
(
    node: Type[BaseNode], 
    parser_result: Dict[str, str],
)

Source from the content-addressed store, hash-verified

130
131
132def code_execution(
133 node: Type[BaseNode],
134 parser_result: Dict[str, str],
135) -> str:
136
137 @timeout(TIMEOUT_SECONDS, exception_message=TIMEOUT_MESSAGE)
138 def _code_execution(node: Type[BaseNode], parser_result: Dict[str, str]) -> str:
139 # Define tool
140 action = parser_result["action"]
141 tool_func = tools[action]
142
143 # Preventing variable update between different children
144 # For each child, we re-run the historical code snippets with the same action (tool).
145 history_action_inputs = collect_action_inputs(node, action)
146 for history_ai in history_action_inputs:
147 _ = tool_func(history_ai)
148
149 # then, we execute current code snippets
150 action_input = parser_result["action_input"]
151 observation = str(tool_func(action_input)).strip()
152 del tool_func
153 return observation
154
155 try:
156 observation = _code_execution(node, parser_result)
157 except Exception as e:
158 observation = "{}: {}".format(type(e).__name__, str(e))
159
160 return observation
161
162
163def collect_action_inputs(

Callers 2

_update_current_nodeMethod · 0.85
create_childMethod · 0.85

Calls 1

_code_executionFunction · 0.85

Tested by

no test coverage detected