repositories
loading repo index
repositories
loading repo index
repository
loading code, commits, and activity
Mirrored from https://github.com/yingqi-z20/Agent-libOS
stars
latest
clone command
git clone gitlawb://did:key:z6MkqRzA...RfoM/yingqi-z20-Agen...git clone gitlawb://did:key:z6MkqRzA.../yingqi-z20-Agen...d98dd2c9IPC1d ago| #1 | from __future__ import annotations |
| #2 | |
| #3 | import json |
| #4 | from typing import Any |
| #5 | |
| #6 | |
| #7 | def tool_call_to_action(tool_call: dict[str, Any]) -> dict[str, Any]: |
| #8 | name = str(tool_call.get("name") or "").strip() |
| #9 | raw_args = tool_call.get("arguments") |
| #10 | # Empty arguments are common for no-arg tool calls, but other false-y |
| #11 | # values such as [] or 0 are malformed protocol frames and should surface |
| #12 | # as repairable LLM output errors. |
| #13 | if raw_args is None or raw_args == "": |
| #14 | raw_args = "{}" |
| #15 | if isinstance(raw_args, str): |
| #16 | args = json.loads(raw_args or "{}") |
| #17 | elif isinstance(raw_args, dict): |
| #18 | args = raw_args |
| #19 | else: |
| #20 | raise ValueError(f"invalid tool arguments for {name}: {type(raw_args).__name__}") |
| #21 | if not isinstance(args, dict): |
| #22 | raise ValueError(f"tool arguments for {name} must decode to an object") |
| #23 | if not name: |
| #24 | fallback_name = str(args.get("action") or "").strip() |
| #25 | if not fallback_name: |
| #26 | raise ValueError("tool call is missing a function name") |
| #27 | name = fallback_name |
| #28 | args = {key: value for key, value in args.items() if key != "action"} |
| #29 | return {**args, "action": name} |
| #30 |