(
messages: list[Any],
*,
before_index: int,
tool_call_id: str,
)
| 1455 | |
| 1456 | |
| 1457 | def _command_for_tool_result( |
| 1458 | messages: list[Any], |
| 1459 | *, |
| 1460 | before_index: int, |
| 1461 | tool_call_id: str, |
| 1462 | ) -> str: |
| 1463 | if not tool_call_id: |
| 1464 | return "" |
| 1465 | for prior in reversed(messages[:before_index]): |
| 1466 | if not isinstance(prior, dict): |
| 1467 | continue |
| 1468 | extra = prior.get("extra") or {} |
| 1469 | if isinstance(extra, dict): |
| 1470 | for action in extra.get("actions") or (): |
| 1471 | if ( |
| 1472 | isinstance(action, dict) |
| 1473 | and action.get("tool_call_id") == tool_call_id |
| 1474 | and isinstance(action.get("command"), str) |
| 1475 | ): |
| 1476 | return str(action["command"]) |
| 1477 | for tc in prior.get("tool_calls") or (): |
| 1478 | if isinstance(tc, dict) and tc.get("id") == tool_call_id: |
| 1479 | command = _tool_call_command(tc) |
| 1480 | if command: |
| 1481 | return command |
| 1482 | return "" |
| 1483 | |
| 1484 | |
| 1485 | def _latest_tool_result_context(messages: list[Any]) -> tuple[str, bool, str]: |
no test coverage detected