Skip to content

Tool System

ContextRouter exposes tools for LLM function calling. Tools allow agents to interact with Brain (search), Commerce (products), databases, and external services.

Built-in Tools

ToolModuleDescription
Brain Searchmodules/tools/Query Brain knowledge store
Commerce Productsmodules/tools/Search/update product catalog
Web Connectormodules/connectors/web.pyWeb search via Google CSE
RSS Connectormodules/connectors/rss.pyRSS feed ingestion
File Connectormodules/connectors/file.pyLocal file reading
API Connectormodules/connectors/api.pyGeneric HTTP API calls

ToolExecutorStream

The ToolExecutorStream RPC enables bi-directional tool execution. External projects connect to Router via persistent gRPC bidi-streams, allowing agents to invoke tools on the client side without exposing credentials.

router-tools

Client-Side Implementation

from contextcore import ContextUnit, create_channel_sync, context_unit_pb2
from contextcore import router_pb2_grpc
async def tool_executor():
channel = create_channel_sync("router:50052")
stub = router_pb2_grpc.RouterServiceStub(channel)
async for message_pb in stub.ToolExecutorStream(request_stream()):
message = ContextUnit.from_protobuf(message_pb)
# Execute tool locally
tool_name = message.payload.get("tool_name")
if tool_name == "sql_query":
result = await run_sql(message.payload["arguments"]["query"])
response = ContextUnit(
payload={"result": result, "tool_call_id": message.payload["tool_call_id"]},
)
yield response.to_protobuf(context_unit_pb2)

Tool Registration

Tools are registered via the ToolFactory:

from contextrouter.service.tool_factory import ToolFactory
factory = ToolFactory(config)
tools = factory.build_tools(agent_config)

The factory reads agent configuration to determine which tools are available for each agent, enforcing the principle of least privilege.