Once you’ve defined your semantic layer with views, entities, dimensions, and measures, you need to build it before use:
oxy build
This command validates and compiles your semantic layer definitions, making them available to agents, workflows, and routing agents. Always run oxy build after creating or modifying semantic layer files to ensure your changes are picked up.
Add the semantic_query tool to your agent to enable it to query the semantic layer directly. The agent can then answer business questions using your defined metrics and dimensions.
model: "openai-4o-mini"description: "Data analyst agent that can answer business questions"system_instructions: | You are a data analyst expert. Your task is to help users answer questions based on data using the semantic layer. Use the semantic_query tool to query data. The tool gives you access to pre-defined business metrics and dimensions.tools: - name: semantic_query type: semantic_query topic: ecommerce_analytics # The topic to query
The semantic_query tool has the following properties:
Property
Type
Required
Description
name
string
Yes
Unique identifier for the tool
type
string
Yes
Must be semantic_query
topic
string
Yes
Name of the semantic topic to query
When querying a topic with default_filters, those filters are
automatically applied to all queries. User-provided filters are combined with
default filters using AND logic. For example, if a topic has a default filter
for tenant_id = 'abc123', every query will be scoped to that tenant
regardless of additional filters specified by the user.
Use the semantic_query task type in workflows to execute structured queries against your semantic layer. This is ideal for automated reporting, data pipelines, and scheduled analytics.
Reference dimensions and measures using the format view_name.field_name:
dimensions: - orders.order_date # From orders view - customers.customer_name # From customers view - products.product_category # From products viewmeasures: - orders.total_revenue # Sum measure from orders - orders.avg_order_value # Average measure from orders - customers.total_customers # Count measure from customers
If the topic ecommerce_analytics has default filters (e.g., tenant_id = 'xyz'), they are automatically applied along with the filters specified
above. All default filters and user filters must be satisfied.
model: "openai-4o-mini"type: routingdescription: "Main routing agent for data analysis"routes: # Include specific topics - "semantics/topics/ecommerce_analytics.topic.yml" - "semantics/topics/sales.topic.yml" # Or use glob patterns to include all topics - "semantics/topics/*.topic.yml" # Mix with other route types - "agents/specialized_analyst.agent.yml" - "workflows/*.workflow.yml"route_fallback: agents/default.agent.yml