agents.components.semantic_router
#
Module Contents#
Classes#
A component that routes semantic information from input topics to output topics based on pre-defined routes. The Semantic Router takes in a list of input topics, a list of routes, an optional default route, and a configuration object. It uses the database client to store and retrieve routing information. |
API#
- class agents.components.semantic_router.SemanticRouter(*, inputs: List[agents.ros.Topic], routes: List[agents.ros.Route], config: agents.config.SemanticRouterConfig, db_client: agents.clients.db_base.DBClient, default_route: Optional[agents.ros.Route] = None, callback_group=None, component_name: str = 'router_component', **kwargs)#
Bases:
agents.components.component_base.Component
A component that routes semantic information from input topics to output topics based on pre-defined routes. The Semantic Router takes in a list of input topics, a list of routes, an optional default route, and a configuration object. It uses the database client to store and retrieve routing information.
- Parameters:
inputs (list[Topic]) โ A list of input text topics that this component will subscribe to.
routes (list[Route]) โ A list of pre-defined routes that publish incoming input to the routed output topics.
default_route (Optional[Route]) โ An optional route that specifies the default behavior when no specific route matches up to a threshold. If not provided, the component will use the first route in the list.
config (SemanticRouterConfig) โ The configuration object for this Semantic Router component.
db_client (DBClient) โ A database client that is used to store and retrieve routing information.
callback_group โ An optional callback group for this component.
component_name (str) โ The name of this Semantic Router component (default: โrouter_componentโ).
kwargs โ Additional keyword arguments.
Example usage:
input_text = Topic(name="text0", msg_type="String") goto_route = Route( routes_to=goto, # where goto is an input topic to another component samples=[ "Go to the door", "Go to the kitchen", "Get me a glass", "Fetch a ball", "Go to hallway", "Go over there", ], ) mllm_route = Route( routes_to=mllm_input, # where mllm_input is an input topic to another component samples=[ "Are we indoors or outdoors", "What do you see?", "Whats in front of you?", "Where are we", "Do you see any people?", "How many things are infront of you?", "Is this room occupied?", ], ) config = SemanticRouterConfig(router_name="my_router") db_client = DBClient(db=ChromaDB("database_name")) semantic_router = SemanticRouter( inputs=[input_text], routes=[route1, route2], default_route=None, config=config, db_client=db_client )