Legal tool call

1.0 when the output is a single tool call to an allowed tool with every required argument.

tool_call.pyverify_environment
def verify_environment(completion: str, metadata: dict | None = None) -> float:
    """Expects {"name": str, "arguments": {...}}. metadata["tools"] maps name -> list of required args."""
    import json

    try:
        call = json.loads(completion.strip())
    except (ValueError, TypeError):
        return 0.0
    if not isinstance(call, dict) or not isinstance(call.get("arguments"), dict):
        return 0.0
    tools = (metadata or {}).get("tools") or {}
    name = call.get("name")
    if name not in tools:
        return 0.0
    required = set(tools[name])
    given = set(call["arguments"])
    if not required.issubset(given):
        return 0.0
    return 1.0 if given == required else 0.5
Legal tool call reward function (Python) — Reinforcement.tech