产品介绍

NL2SQL query and main-Agent analysis

Have the main Agent delegate to nl2sql, read the actual CSV, continue the analysis, and write regional-sales.md. The plugin and five-order dataset match dedicated queries; the difference is root-Agent orchestration and follow-up processing.

Scenario and responsibilities

TUI business question → Main Agent plans
  → task delegates to nl2sql → Generate, validate, execute, and save CSV
  → Main Agent reads CSV, compares regions, and writes Markdown

Verify real delegation and file reads rather than having the main Agent query SQLite directly through the shell. Expected totals are north=4500, south=2300, east=800 cents, with a 7600-cent total.

Prepare dependencies and shared data first

Follow dedicated-query environment setup for dependencies and repository-root .env. The model must support tool calling. Run model-free shared preparation, retaining the Home, database, and schema variables in the same terminal. Neither SemanticLayer nor MCP is required.

If a dedicated-query Server is running, stop it and repeat preparation for another Home. Do not resume its direct-entry checkpoint.

Configuration structure

See the complete config.parent.yaml. The key difference from the direct entry is dataagent.entry:

schema_version: 4
dataagent:
  model: primary
  entry: null
models:
  primary:
    provider: openai
    name: $env{LLM_MODEL}
    base_url: $env{LLM_BASE_URL}
    api_key: $env{LLM_API_KEY}
plugins:
  enabled: [nl2sql]
  config:
    nl2sql:
      model: primary
      database:
        db_id: orders
        dialect: sqlite
        engine: sqlite
        path: $env{DATAAGENT_TUTORIAL_SQLITE}
      nodes: [perceptor, generator, validator, reflector, executor, selector]
      perceptor:
        user_schema: $env{DATAAGENT_TUTORIAL_SCHEMA}
      generator:
        strategies: [prompt]
        num_workers: 1
        num_samples: 1
      validator:
        semantic_check: false
        db_explain: true
        read_only: true
      selector:
        shortcut: 1
Setting Meaning in this example When omitted
dataagent.entry null: build the main Agent, which can choose a subagent. nl2sql instead runs the compiled entry directly Build the main Agent
dataagent.model primary: model alias for the main Agent primary
plugins.enabled [nl2sql]: load the plugin declaration and compiled subagent []; plugins.config alone does not enable a plugin
plugins.config.nl2sql.model primary: model alias for the SQL workflow Required; does not automatically inherit the main Agent alias
database Business database identity, dialect, engine, and connection; shared preparation supplies the path Required by this plugin
perceptor.user_schema Schema file created during shared preparation, avoiding an external metadata service in this example Supply the capabilities required by the plugin's metadata lookup path
nodes Ordered perception, generation, validation, reflection, execution, and final selection workflow Without any node sections, the full workflow; otherwise the configured sections must form a continuous prefix
generator.num_workers, num_samples Both 1, keeping candidate generation small Both 1
validator.semantic_check false: skip model-based semantic validation while retaining other configured checks true
validator.db_explain, read_only Both true: enable database plan checks and require read-only SQL false, true, respectively
selector.shortcut 1: allow one matching execution result to trigger shortcut selection, reducing selector model calls -1, disabling the shortcut
result_files Omitted here; executed results still produce CSV true
model_call_budget Omitted here; bounds model calls in each NL2SQL task 64

models declares connections, dataagent selects the main Agent's behavior, plugins.enabled controls loading, and plugins.config.nl2sql supplies SQL workflow parameters. The startup command selects this configuration with --config; Home config.yaml is not merged into it. See configuration selection and merging for environment references and plugin parameter rules.

Start Server, attach TUI, and ask

From the repository root in the terminal retaining the shared-data variables:

uv run --no-sync dataagent serve \
  --config examples/sqlite-tutorial/config.parent.yaml --env-file .env

This YAML omits server and defaults to 127.0.0.1:8790. If occupied, copy it to the independent Home, set an available server.port, and update --config and the client URL together. Changing Home alone does not change the port.

Attach from another terminal; prepare the client with the TUI guide:

npm run start:tui -- --runtime-url http://127.0.0.1:8790

Do not also pass --config or --env-file to TUI. Ask in a new session:

Use task to delegate to nl2sql: group orders by region and sum amount_cents.
Return region and total_cents, ordered by total_cents descending and region ascending.
Read the actual CSV returned by the subagent, compare regions, and save regional-sales.md.
Use cents throughout. Do not query SQLite through the shell or write a replacement CSV yourself.
Give the actual CSV and report paths.

Check the current session's CSV and report

Use TUI /outputs and the returned absolute paths to locate actual files. Default layout:

<home>/outputs/default/<thread>/
  nl2sql/<query_id>.csv
  nl2sql/<query_id>.meta.json
  regional-sales.md

<thread> is the current Server/TUI session's actual ID, not the SDK example's fixed sqlite-parent-tutorial. Verify this CSV:

region,total_cents
north,4500
south,2300
east,800

The neighboring .meta.json supplies the SQL and query metadata. The report should use this CSV, correctly identify north as the leader, and report 7600 cents in total. File existence or nonempty prose cannot substitute for checking content; wording may vary.

Inspect collaboration, logs, and traces

The official Server writes <home>/runtime/logs/backend.log. Current-session traces are under runtime/users/default/sessions/<thread>/traces/*.json. Use the actual thread and correlation IDs, not the SDK's fixed directories. See logs and traces for searches and fields.

A normally completed run has root dataagent. Verify:

  1. The main Agent's task call selects nl2sql and matches the aggregation request.
  2. nl2sql / nl2sql.workflow returns actual SQL, result details, and the CSV path without ignored error or result_file_error fields.
  3. Subsequent read_file and write_file calls read that CSV and write the report, with corresponding paths and contents.
  4. CSV values are correct; an OK root span describes execution state, not analytical correctness.

Connect steps through traceId, spanId, and parentSpanId, not array order. Internal non-Agent nodes may keep timing alone; inspect model/tool spans for inputs and outputs. Server uses persistent checkpoints; see session records and SQLite.

First checks on failure

Symptom Check first
Missing database/schema Shared preparation, variables retained in the Server terminal, and actual file existence
Answer without task --config selects config.parent.yaml, empty entry, and model tool-calling support
Unexpected CSV Subagent errors, SQL, column names, ordering, and units
Correct CSV but no report Main-Agent follow-up reads, write errors, or call limits
Missing logs/traces The actual Server Home/thread and whether failure preceded graph execution

See troubleshooting, and keep needed outputs and diagnostics before cleanup.

Optional: automatic SDK verification

For a fixed task with automatic execution and checks, the independent script remains:

uv run --no-sync python examples/sqlite-tutorial/run_parent.py --env-file .env

It creates separate temporary data and Home and actually runs the model, delegation, CSV reads, and report writing. It is not a data-preparation prerequisite for Server/TUI. It checks actual CSV headers, order, and totals and requires a nonempty report, printing Verified: 3 region totals and Verified: analysis report is nonempty. Human review of the report's meaning is still needed.

Its fixed SDK thread is sqlite-parent-tutorial; artifacts are under its printed Home at outputs/default/sqlite-parent-tutorial/. It prints SQL, CSV, metadata, report, and trace paths. The script uses the host’s Python logging configuration. To write to backend.log, see SDK logging. The script supplies no persistent checkpointer.