Dedicated NL2SQL queries: SQLite → CSV
Ask DataAgent to total sales by region, generate and execute SQL, and save CSV. This case follows normal Server/TUI usage. For reading query results, analyzing them, and writing a report, continue with parent/subagent analysis.
Execution path
TUI question → Server's compiled NL2SQL entry
→ Schema context, SQL generation, validation/repair, execution, selection
→ Query-result JSON, CSV, and metadata filedataagent.entry: nl2sql runs the enabled compiled workflow directly, without a planning root Agent or task delegation. Plugin routing selects stages; every invocation need not visit all nodes. This case supplies a local schema and needs no SemanticLayer.
Prepare the environment
Work from the source repository root. Use quick start or manual source deployment to prepare Python, uv, and the built TUI. For the initial Python environment:
uv sync --python 3.12Provide model settings in repository-root .env:
LLM_MODEL=your-model-name
LLM_BASE_URL=https://your-openai-compatible-host/v1
LLM_API_KEY=replace-with-your-key--env-file .env below selects this file; nonempty process values take precedence. Omit it if all three model values are already in the environment. See basic configuration for fields.
Prepare shared data first
Run shared data preparation. It creates the five orders and schema using only Python's standard library, without a model call. Retain DATAAGENT_HOME, DATAAGENT_TUTORIAL_SQLITE, and DATAAGENT_TUTORIAL_SCHEMA in the same terminal for configuration and startup below.
The query groups amount_cents by region, returns region then total_cents, and sorts total descending and region ascending. Reference SQL:
SELECT region, SUM(amount_cents) AS total_cents
FROM orders
GROUP BY region
ORDER BY total_cents DESC, region ASC;Amounts are integer cents. Equivalent SQL is acceptable; verify the actual CSV rather than comparing SQL strings.
How the key settings work together
The full runnable file is config.example.yaml. It does not need every product field; the key settings are:
| Setting | Value and purpose in this example |
|---|---|
schema_version |
4, the product YAML version |
dataagent.model |
primary, the host's default model alias; it does not select the execution approach |
dataagent.entry |
nl2sql, which directly runs the compiled entry |
models.primary |
OpenAI-compatible model name, address, and key resolved from the effective environment |
plugins.enabled |
[nl2sql], enabling the bundled NL2SQL plugin |
plugins.config.nl2sql.model |
primary, the model alias used inside the plugin's nodes |
plugins.config.nl2sql.database |
db_id: orders identifies the business database, dialect: sqlite selects SQL syntax, engine: sqlite selects the connection implementation, and path references the database created during shared preparation |
plugins.config.nl2sql.nodes |
Explicitly selects perceptor, generator, validator, reflector, executor, selector; failures follow the workflow's routing |
perceptor.user_schema |
All node fields below are under plugins.config.nl2sql. This field references the schema file from shared preparation and avoids semantic-service schema lookup in this example |
generator |
strategies: [prompt], num_workers: 1, and num_samples: 1 keep one strategy and one sample for a small first run |
validator |
semantic_check: false skips model-based semantic scoring; db_explain: true checks the query with SQLite; read_only: true enables read-only SQL checks |
selector.shortcut |
1, allowing selection when a valid execution result receives one vote; the example has one candidate and needs no extra model-based selection |
result_files |
Omitted, retaining the plugin's default true so successful queries write CSV and metadata files |
Shared preparation exports DATAAGENT_TUTORIAL_SQLITE and DATAAGENT_TUTORIAL_SCHEMA; retain both in the terminal that starts Server.
The --config argument below selects this product YAML, which replaces, rather than merges with, Home config.yaml. Enabled plugins can supply defaults, which explicit plugins.config.<id> values override. The current nl2sql manifest declares no defaults_file; omitted values such as result_files come from the plugin implementation. The old parent/child YAML nonempty-field fallback does not apply. See configuration merging and precedence.
Start Server, attach TUI, and ask
From the repository root, in the terminal retaining the data variables:
uv run --no-sync dataagent serve \
--config examples/sqlite-tutorial/config.example.yaml --env-file .envThis YAML omits server, defaulting to 127.0.0.1:8790. If occupied, copy the YAML to the independent Home, configure server.port, and update both --config and the TUI URL accordingly. Do not resume a thread from a different graph; switching entries requires restart and a new session.
Attach from another terminal after preparing the client through the TUI guide:
npm run start:tui -- --runtime-url http://127.0.0.1:8790Do not also pass --config or --env-file to TUI here. Ask in a new session:
Query orders and sum amount_cents by region.
Return region and total_cents, ordered by total_cents descending and region ascending.
Use cents, and provide the SQL and actual CSV path.
Check this session's CSV and JSON result
The final reply contains query-result JSON. First establish an empty error, then inspect sql, columns, rows_preview, row_count, total_known, and truncated. result_file is the actual CSV path and query_id identifies the query. A result_file_error is a persistence failure even if SQL succeeded.
Use TUI /outputs and the returned path to locate current-session outputs. Default layout:
<home>/outputs/default/<thread>/nl2sql/
<query_id>.csv
<query_id>.meta.json<thread> is this service session's ID, not the optional SDK script's sqlite-tutorial. The actual CSV should contain:
region,total_cents
north,4500
south,2300
east,800The neighboring .meta.json stores the question, SQL, database identity, execution time, columns, row count, and truncation indicators. The plugin does not create a separate .sql file by default. For larger outputs the preview may be partial; inspect the actual CSV and truncation flags.
Inspect logs and traces
The official Server writes <home>/runtime/logs/backend.log. In the Server's terminal, replace this example with the current session ID:
thread_id='replace-with-current-thread-id'
tail -n 100 "$DATAAGENT_HOME/runtime/logs/backend.log"
find "$DATAAGENT_HOME/runtime/users/default/sessions/$thread_id/traces" \
-maxdepth 1 -type f -name '*.json' -printTrace filenames use native root run IDs rather than thread names or CSV query_id. This case's root is nl2sql; follow nl2sql.workflow through generation, validation, execution, and model calls, without a main-Agent task delegation. Connect steps by traceId, spanId, and parentSpanId, not array positions. See logs and traces.
Server creates a session index and persistent checkpoints; see session records and SQLite for their locations.
Common problems
- Missing database/schema: execute shared preparation and launch Server from the terminal retaining its environment variables.
- Model failures: check the endpoint, name, key, and nonempty process overrides of
.env. - Missing semantic service: confirm this configuration's nonempty, readable
perceptor.user_schema. - Incorrect CSV: inspect aggregation fields, aliases, ordering, errors, and truncation.
- Missing logs/traces: locate this Server Home and actual thread; failures before graph execution can have no trace.
Keep required outputs and diagnostics before cleaning temporary directories. See troubleshooting for other failures.
Optional: automatic SDK verification
The original command remains available to verify a fixed question automatically:
uv run --no-sync python examples/sqlite-tutorial/run.py --env-file .envIt prepares separate temporary data and Home and actually calls the model. It needs no running Server and is not a data-preparation prerequisite for Server/TUI. It checks every actual CSV row, prints Verified: 3 region totals, and prints the Home, configuration, output, and trace paths.
This SDK script uses fixed thread sqlite-tutorial, with default artifacts under its own printed Home at outputs/default/sqlite-tutorial/nl2sql/. The script uses the host’s Python logging configuration. To write to backend.log, see SDK logging. The script supplies no persistent checkpointer. Use the Home and thread printed by this run to locate its files.