Parse a single tool call entry from either dict or object format. Args: tc: A tool call entry (dict or object with function attribute). Returns: Dict with 'name' and 'args', or None if parsing fails.
(tc: Any)
| 1012 | |
| 1013 | |
| 1014 | def _parse_tool_call_entry(tc: Any) -> dict[str, Any] | None: |
| 1015 | """Parse a single tool call entry from either dict or object format. |
| 1016 | |
| 1017 | Args: |
| 1018 | tc: A tool call entry (dict or object with function attribute). |
| 1019 | |
| 1020 | Returns: |
| 1021 | Dict with 'name' and 'args', or None if parsing fails. |
| 1022 | """ |
| 1023 | if isinstance(tc, dict): |
| 1024 | func = tc.get("function", {}) |
| 1025 | name = func.get("name", "") |
| 1026 | args_str = func.get("arguments", "{}") |
| 1027 | elif hasattr(tc, "function"): |
| 1028 | func = tc.function |
| 1029 | name = getattr(func, "name", "") |
| 1030 | args_str = getattr(func, "arguments", "{}") |
| 1031 | else: |
| 1032 | return None |
| 1033 | |
| 1034 | try: |
| 1035 | args = json.loads(args_str) if isinstance(args_str, str) else args_str |
| 1036 | except (json.JSONDecodeError, TypeError): |
| 1037 | args = {} |
| 1038 | |
| 1039 | return {"name": name, "args": args} if name else None |
| 1040 | |
| 1041 | |
| 1042 | def _summarize_variables(var_context: dict[str, Any]) -> str: |