Route object, the only difference between them is that static routes return a Route.name when chosen, whereas dynamic routes use an LLM call to produce parameter input values.
For example, a static route will tell us if a query is talking about mathematics by returning the route name (which could be "math" for example). A dynamic route does the same thing, but it also extracts key information from the input utterance to be used in a function associated with that route.
For example we could provide a dynamic route with associated utterances:
base=2 and exponent=3. These values are returned in such a way that they can be used in the above power function. That is, the dynamic router automates the process of calling relevant functions from natural language inputs.
As with static routes, we must create a dynamic route before adding it to our router. To make a route dynamic, we need to provide the function_schemas as a list. Each function schema provides instructions on what a function is, so that an LLM can decide how to use it correctly.
get_schemas_openai function.
Full Example
Installing the Library
Initializing Routes and SemanticRouter
Dynamic routes are treated in the same way as static routes, let’s begin by initializing aSemanticRouter consisting of static routes.
⚠️ Note: We have a fully local version of dynamic routes available at docs/05-local-execution.ipynb. The local version tends to outperform the OpenAI version we demo in this document, so we’d recommend trying 05-local-execution.ipynb!
SemanticRouter with our encoder and routes. We can use popular encoder APIs like CohereEncoder and OpenAIEncoder, or local alternatives like FastEmbedEncoder.
Creating a Dynamic Route
As with static routes, we must create a dynamic route before adding it to our router. To make a route dynamic, we need to provide thefunction_schemas as a list. Each function schema provides instructions on what a function is, so that an LLM can decide how to use it correctly.
get_schemas_openai function.

