r/synapcores • • 13h ago

Recipe of the week #5: route an agent's request to the right tool with one SQL query. On 12 support messages, keyword rules routed 7; matching by meaning routed 9, picked 0 wrong tools and asked on the other 3 (real output)

1 Upvotes

Every Monday: one site recipe, run on the current release, real output inline.

(This sub is run by the SynapCores team. Run this morning on 2.5.1.)

The problem

A support agent has six tools: reset_password, cancel_subscription, check_order_status, update_billing, create_support_ticket, check_usage. People don't type tool names. They type "Where's my package?" Keyword rules only catch the words you thought of, and letting the LLM choose means a model call before every tool call.

1. Describe each tool, embed the descriptions

One row per tool: name, a plain-English description, a VECTOR(384) column (CREATE and INSERTs in the first comment). The embedding model runs inside the database:

UPDATE recipe_agent_tools SET embedding = EMBED(description);

2. Nearest tool, called only above a threshold

SELECT tool_name, match_score,
       CASE WHEN match_score >= 0.35 THEN 'CALL' ELSE 'ASK_CLARIFY' END AS decision
FROM (
  SELECT tool_name,
         COSINE_SIMILARITY(embedding, EMBED('I want to stop being charged every month')) AS match_score
  FROM recipe_agent_tools
  ORDER BY match_score DESC
  LIMIT 1
);

cancel_subscription  0.5978519320487976  CALL

The message never says "cancel" or "subscription". Same query with "hey, quick question about my thing":

reset_password  0.10003530979156494  ASK_CLARIFY

Nothing clears 0.35, so the agent asks instead of guessing.

3. Fourteen messages, one query

12 support messages written the way people type, plus two that no tool should take (table in the first comment). Every message against every tool, best match each:

SELECT req_id, message, tool_name, ROUND(match_score, 3) AS score,
       CASE WHEN match_score >= 0.35 THEN 'CALL' ELSE 'ASK_CLARIFY' END AS decision
FROM (
  SELECT r.req_id, r.message, t.tool_name,
         COSINE_SIMILARITY(t.embedding, r.embedding) AS match_score,
         ROW_NUMBER() OVER (PARTITION BY r.req_id
                            ORDER BY COSINE_SIMILARITY(t.embedding, r.embedding) DESC) AS rn
  FROM recipe_agent_requests r CROSS JOIN recipe_agent_tools t
) ranked
WHERE rn = 1
ORDER BY req_id;

1  I keep getting locked out and can't sign in  reset_password  0.625  CALL
2  I want to stop being charged every month  cancel_subscription  0.598  CALL
3  hey, quick question about my thing  reset_password  0.1  ASK_CLARIFY
4  Forgot my password, help  reset_password  0.647  CALL
5  Please close my account, we're moving to another vendor  cancel_subscription  0.365  CALL
6  Where's my package? It was supposed to arrive Tuesday  check_order_status  0.424  CALL
7  Has order 88123 shipped yet?  check_order_status  0.448  CALL
8  My card expired, how do I put the new one in?  update_billing  0.509  CALL
9  We moved offices and the address on our invoices is wrong  update_billing  0.414  CALL
10  How many API calls do we have left this month?  check_usage  0.528  CALL
11  Are we about to hit our rate limit?  create_support_ticket  0.157  ASK_CLARIFY
12  The CSV export crashes every time I click it  update_billing  0.169  ASK_CLARIFY
13  Can a real person look at this? Nothing works  create_support_ticket  0.289  ASK_CLARIFY
14  What's the weather in Boston tomorrow?  check_order_status  0.093  ASK_CLARIFY

Scoreboard (the 12 requests)

  • Keyword rules using words from the same six descriptions (password, cancel, order, card, api...; query in the first comment): 7 routed, 0 wrong tools, 5 "no rule".
  • By meaning: 9 routed, 0 wrong tools, 3 sent to ASK_CLARIFY. Both no-tool messages went to ASK_CLARIFY too.

A new message (embed, compare with six tools, gate) took 6 to 16 ms on a Mac mini (Apple M4). No LLM call, no tokens.

The three ASK_CLARIFY rows are a to-do list: each is a phrasing your descriptions don't cover yet (two rewrites and the re-run are in the comments).

Recipe (~12 min): https://synapcores.com/recipes/agents/semantic-tool-routing?utm_source=reddit&utm_medium=owned&utm_campaign=synapcores-recipe-5

Free Community Edition: https://synapcores.com/download?utm_source=reddit&utm_medium=owned&utm_campaign=synapcores-recipe-5

Join the sub and Recipe of the week #6 lands in your feed next Monday.

How does your agent pick a tool today: keyword rules, the LLM's own function calling, or something else?