Tutorial: Your First Natural Language Query
In this tutorial, you will use the MATIH Agentic Workbench to ask questions about your data in plain English. The platform's multi-agent AI system will interpret your question, generate SQL, execute it against your data source, and return the results -- all through a conversational interface.
What You Will Learn
- How to open the Agentic Workbench and start a conversation session
- How to ask natural language questions and receive structured answers
- How the multi-agent orchestrator routes your question to the right agent
- How to refine queries through follow-up questions
- How to inspect the generated SQL for transparency
- How to export results for further analysis
Prerequisites
| Requirement | How to Verify |
|---|---|
| MATIH platform running | ./scripts/tools/platform-status.sh returns healthy |
| AI service operational | curl http://localhost:8000/health returns healthy |
| Data source configured | At least one data source connected (see First-Time Configuration) |
| Sample data loaded | The orders, customers, and products tables exist in your data source |
Step 1: Open the Agentic Workbench
Navigate to the Agentic Workbench:
- Local development:
http://localhost:3003 - Cloud deployment:
https://agentic.{your-tenant}.matih.ai
Log in with your tenant credentials. You will see the conversation interface with a text input at the bottom and a sidebar showing your conversation history.
Step 2: Start a New Session
Click New Conversation in the sidebar (or use the keyboard shortcut). A new session is created with a unique identifier. The session maintains conversation context, so follow-up questions reference previous results.
Behind the scenes, this creates a ConversationSession with:
| Field | Value |
|---|---|
session_id | Unique UUID |
tenant_id | Your current tenant |
user_id | Your user ID |
state | Empty AgentState |
Step 3: Ask Your First Question
Type a natural language question in the input box and press Enter (or click Send).
Example question:
What were our total sales last month?What Happens Behind the Scenes
The multi-agent orchestrator processes your question through several specialized agents:
Your Question: "What were our total sales last month?"
|
v
[Router Agent] -- Classifies intent as DATA_QUERY
|
v
[SQL Agent] -- Generates SQL from your question
| Uses: schema context from vector store, LLM for generation
|
v
[Query Engine] -- Executes the generated SQL
|
v
[Analysis Agent] -- Interprets results, generates narrative
|
v
[Visualization Agent] -- Suggests chart type for the data
|
v
Response displayed in the conversationThe Router Agent classifies your question into one of several intents:
| Intent | Description | Handled By |
|---|---|---|
DATA_QUERY | Questions about data that require SQL | SQL Agent |
ANALYSIS | Requests for statistical analysis or insights | Analysis Agent |
VISUALIZATION | Requests to create charts or dashboards | Visualization Agent |
DOCUMENTATION | Questions about the platform or data dictionary | Documentation Agent |
The Response
The workbench displays the answer in a structured format:
Narrative answer:
Total sales last month were $1,247,832.50, representing a 12.3% increase compared to the previous month.
Data table:
| Month | Total Sales | Order Count | Avg Order Value |
|---|---|---|---|
| January 2026 | $1,247,832.50 | 4,230 | $295.00 |
Suggested visualization: Bar chart showing monthly sales trend.
Step 4: Inspect the Generated SQL
Click the Show SQL button (or the code icon) beneath the response to see the SQL that was generated:
SELECT
DATE_TRUNC('month', order_date) AS month,
SUM(total_amount) AS total_sales,
COUNT(*) AS order_count,
AVG(total_amount) AS avg_order_value
FROM orders
WHERE order_date >= DATE_TRUNC('month', CURRENT_DATE - INTERVAL '1' MONTH)
AND order_date < DATE_TRUNC('month', CURRENT_DATE)
GROUP BY DATE_TRUNC('month', order_date)The SQL generation pipeline:
- Question parsing -- The
QuestionParserextracts entities, time references, and aggregations from your question. - Schema retrieval -- The
QdrantSchemaStoreretrieves relevant table and column metadata using vector similarity search. - SQL generation -- The
LLMClientgenerates SQL using the parsed question and schema context. - Validation -- The
SQLValidatorchecks the generated SQL for syntax errors and safety issues. - Auto-correction -- If validation fails, the system automatically attempts to fix the SQL and regenerate.
Step 5: Ask a Follow-Up Question
Because the conversation maintains context, you can ask follow-up questions that reference previous results:
How does that compare to the same month last year?The AI understands "that" refers to the total sales figure from your previous question. It generates a comparison query:
SELECT
DATE_TRUNC('month', order_date) AS month,
SUM(total_amount) AS total_sales
FROM orders
WHERE DATE_TRUNC('month', order_date) IN (
DATE_TRUNC('month', CURRENT_DATE - INTERVAL '1' MONTH),
DATE_TRUNC('month', CURRENT_DATE - INTERVAL '13' MONTH)
)
GROUP BY DATE_TRUNC('month', order_date)
ORDER BY monthResponse:
| Month | Total Sales | Year-over-Year Change |
|---|---|---|
| January 2025 | $1,082,450.00 | -- |
| January 2026 | $1,247,832.50 | +15.3% |
Step 6: Try More Complex Questions
The AI can handle progressively complex analytical questions:
Aggregation with Filtering
What are the top 5 product categories by revenue this quarter?Multi-Table Joins
Which customers have the highest return rates?Time-Series Analysis
Show me the daily order trend for the past 30 daysConditional Logic
What percentage of orders over $500 were returned?Statistical Questions
What is the average time between a customer's first and second purchase?Step 7: Request a Visualization
You can ask the AI to visualize results directly:
Show me a bar chart of monthly revenue for the past 12 monthsThe Visualization Agent interprets this request and generates a chart configuration. The result is rendered directly in the conversation as an interactive chart.
Supported chart types:
| Chart Type | Best For |
|---|---|
| Bar chart | Category comparisons, rankings |
| Line chart | Time series, trends |
| Pie chart | Proportional breakdown |
| Scatter plot | Correlation analysis |
| Heatmap | Two-dimensional distribution |
| Table | Detailed data with many columns |
Step 8: Export Results
You can export query results in several formats:
| Action | How |
|---|---|
| Copy SQL | Click the copy icon next to the SQL display |
| Download CSV | Click the download button and select CSV |
| Download JSON | Click the download button and select JSON |
| Send to BI Workbench | Click "Create Dashboard" to open the results in the BI Workbench |
| Share link | Click "Share" to generate a shareable link to this conversation |
Step 9: Manage Sessions
Viewing Session History
The sidebar shows all your conversation sessions. Click any session to resume it:
| Session Info | Description |
|---|---|
| Session title | Auto-generated from the first question |
| Message count | Number of messages in the session |
| Last active | Timestamp of the most recent interaction |
| Status | Active, Idle, or Closed |
Clearing a Session
To start fresh with no context, click New Conversation to create a new session. Previous sessions remain available in the history.
Understanding the Agent Architecture
The conversation is powered by a multi-agent system built on the LangGraph pattern:
| Agent | Role | Key Capability |
|---|---|---|
| Router Agent | Intent classification | Routes questions to the appropriate specialist agent |
| SQL Agent | Query generation | Converts natural language to SQL using schema context |
| Analysis Agent | Result interpretation | Generates narrative explanations and statistical insights |
| Visualization Agent | Chart generation | Recommends and configures appropriate visualizations |
| Documentation Agent | Platform knowledge | Answers questions about data definitions and platform usage |
The agents communicate through a shared AgentState that maintains:
- Conversation history (all messages)
- Current intent classification
- Generated SQL queries
- Query execution results
- Visualization configurations
- Error context for retry logic
Tips for Better Results
| Tip | Example |
|---|---|
| Be specific about time periods | "last quarter" instead of "recently" |
| Name the metrics you want | "total revenue" instead of "how much" |
| Specify grouping dimensions | "by category and region" |
| Reference table/column names if known | "from the orders table" |
| Use follow-ups for refinement | "Now filter that to only premium customers" |
Troubleshooting
| Issue | Possible Cause | Resolution |
|---|---|---|
| "Unable to generate SQL" | Question too ambiguous | Rephrase with specific table/column references |
| "Query execution failed" | Generated SQL has errors | Check the SQL, report the issue for model improvement |
| "No data found" | Filters too restrictive or wrong time period | Broaden the time range or remove filters |
| Slow response | Complex query or large dataset | Simplify the question or add filters |
| "Service unavailable" | AI service not running | Check ./scripts/tools/platform-status.sh |
Next Steps
Now that you can query data conversationally, proceed to Building a Dashboard to learn how to create persistent visualizations from your query results.