When implementing caching/idempotency for tools that generate external media, make cache keys stable and semantically accurate.
Rules
input_schema defaults; treat an explicit None as “unset”, so omitted and defaulted inputs produce the same key.idempotency_key_fields should include only fields that are actually consumed by the request/output builders. Do not include fields the provider ignores, or you’ll get false cache misses.Example pattern
class MyTool(BaseTool):
input_schema = {
"type": "object",
"required": ["prompt"],
"properties": {
"prompt": {"type": "string"},
"prompt_influence": {"type": "number", "default": 0.3},
"loop": {"type": "boolean", "default": False},
},
}
# Include only fields that affect the request/output
idempotency_key_fields = ["prompt", "prompt_influence", "loop"]
This ensures cache/idempotency behaves predictably: no accidental misses from default handling, and no accidental hits from hashing irrelevant fields.