Class ToolSurfaceHasher

java.lang.Object
com.tnsai.llm.observability.ToolSurfaceHasher

public final class ToolSurfaceHasher extends Object
Single canonical entry point for building a ToolSurface from the raw List<Map<String,Object>> tool shape every framework caller passes around (issue #79).

Why centralise: ToolSurface.surfaceHash is meaningful only if every call site hashes the same way. Rolling-our-own JSON serialisation per provider would silently drift — different key order, different number formatting — and the hash would split, defeating prompt-cache correlation. This util uses one Jackson ObjectMapper configured for sorted-key output so (provider, model, surfaceHash) is a stable cache key.

Tool shape recognised:

  • OpenAI / Anthropic flavor — top-level "function" object with "name" (most providers).
  • Top-level "name" key — bare schema dict.
Anything else falls back to a synthetic name tool[i] so the hash still differentiates by schema content.
Since:
0.9.0 (issue #79)