Source code for aidputils.agents.toolkit.tool_common
from typing import Any
[docs]
def error(message: str, code: int, data: dict | None = None) -> dict:
"""Standardized error envelope for tool responses."""
return {"error": {"code": code, "message": message, "data": data or {}}}
[docs]
def as_str(v: Any) -> str:
"""Coerce arbitrary values to string, treating None as empty."""
if v is None:
return ""
if isinstance(v, str):
return v
return str(v)
[docs]
def sanitize_params(params: dict) -> dict:
"""Remove internal-only runtime keys from params before including in payload."""
return {
k: v
for k, v in params.items()
if not (isinstance(k, str) and k.startswith("_"))
}