tools.flavor_tool module

Flavor Engine Tool – Stargazer-callable tool for gustatory computation.

Wraps FlavorEngine for use as a Discord bot tool. Supports:
  • blend: compute composite flavor profile from a recipe

  • morph: interpolate between two flavors

  • lookup: get a single flavor profile

  • list: list all available flavors

NCM deltas from blend/morph are auto-injected into the limbic system via exhale() so narrative food consumption actually modifies Star’s neurochemistry in Redis DB12.

async tools.flavor_tool.run(action, recipe='[]', morph_from='', morph_to='', morph_t=0.5, flavor='', ctx=None)[source]

Dispatch one of the four flavor-engine actions and return JSON.

This is the generate_image-style single-tool entry point for the flavor_engine tool: it instantiates a fresh FlavorEngine and routes on action to list, lookup, blend, or morph, serialising the result with jsonutil (aliased json). Beyond pure computation it has two side effects that make narrative eating actually change Star’s state: for blend and morph it calls _inject_ncm_deltas to fold the result’s NCM deltas into the per-channel limbic shard in Redis DB12, and (when a ToolContext is present) it records each ingredient via flavor_memory.record_flavor using the Redis client from _get_redis. All other failures are caught and returned as an Error: string rather than raised.

Dispatched by tool_loader.py, which imports this module and pulls run out with getattr(module, "run") to register it under TOOL_NAME (“flavor_engine”); it is also exercised directly in the test suite.

Parameters:
  • action (str) – One of "blend", "morph", "lookup", or "list".

  • recipe (str) – JSON array of ingredient dicts, used only for blend.

  • morph_from (str) – Starting flavor name for morph.

  • morph_to (str) – Target flavor name for morph.

  • morph_t (float) – Interpolation point in [0, 1] for morph (default 0.5).

  • flavor (str) – Flavor name for lookup.

  • ctx (ToolContext | None) – The current ToolContext; supplies channel_id and the Redis client needed for NCM injection and flavor-memory recording. When None, those side effects are skipped.

Return type:

str

Returns:

A pretty-printed JSON string for a successful action, or an "Error: ..." message string when the action is unknown, a required parameter is missing, the recipe JSON is invalid, or an exception is raised.