Mahal Systems

Overview › Agent type

Data analysis

Querying structured data: text-to-SQL, semantic layers, BI, spreadsheets.

Specific to data analysis

  1. 5.b.i

    Give the model the schema it queries, in context: descriptions, keys, codes, sample values

    When the model writes SQL or structured filters, put the schema it is querying in its context: table and column descriptions, key relationships, what enum codes and nulls mean, sample values.

    Context › Filtering input

    Better qualityHigher cost

    Tier 3 · tuning · changes knowledge access, context · data analysis agents · 4 sources, 2 measured

  2. 7.a.i

    Route metric questions through a deterministic semantic layer; fall back to text-to-SQL

    Where a semantic layer exists, have the agent answer metric questions by choosing metrics and dimensions that the layer compiles to SQL, and write SQL only when the layer cannot answer.

    Orchestration › Routing

    Better quality

    Tier 3 · tuning · changes control flow, knowledge access · data analysis agents · 4 sources, 3 measured

  3. 8.a.ii

    Surface information the source holds but the agent cannot read

    Find information a connected source holds that the agent never reads, and expose it.

    Retrieval › Expanding sources

    Better quality

    Tier 3 · tuning · changes knowledge access · retrieval, data analysis, document extraction agents · 11 sources, 3 measured

  4. 8.b.ii

    Link large schemas by exploration: start broad, grow the linked set with probing queries, favor recall

    When a schema is too large to load whole, link the tables and columns a question needs by exploration rather than by one up-front retrieval or by loading everything: start from all table names plus the top retrieved columns, give the agent a column-level vector index, metadata probes and trial queries to grow the linked set, favor recall over minimizing noise, and cap the exploration turns low.

    Retrieval › Querying precisely

    Better qualityLower cost

    Tier 3 · tuning · changes knowledge access, control flow · data analysis agents · 11 sources, 9 measured

General optimizations with evidence from data analysis

  1. 1.b.i

    Match the model and its effort to each call site and query class

    Pick the model per role or call site rather than one model everywhere, and set its reasoning effort and sampling parameters per site; tune each role's prompt to its model (GEPA raised every model tested at lower cost).

    Models › Finding specialists

    Better qualityLower cost

    Tier 3 · tuning · changes model, prompt · any agent · 19 sources, 6 measured

  2. 3.a.i

    Add worked examples to the prompt (few-shot), or curated example queries for data agents

    Put a few solved examples of the task in the prompt (the input and the exact output wanted), or give a data agent commented example queries for its custom metrics and an index of past queries it retrieves per question.

    Prompts › Structuring

    Mixed qualityHigher costSlower

    Tier 3 · tuning · changes prompt · any agent · 7 sources, 6 measured

  3. 3.b.i

    Keep the prompt prefix cache-stable

    Put static content (identity, rules, tool definitions) before a boundary and per-turn content (date, state, memory) after it; keep the prefix bit-for-bit identical across turns; strip thinking text from persisted history; and track per-turn cache-miss cost.

    Prompts › Caching

    Lower costFaster

    Tier 1 · hygiene · changes context · any agent · 8 sources, 1 measured

  4. 6.b.iii

    Use multi-agent orchestration only for breadth-first, independent sub-tasks

    Spawn parallel sub-agents when the work splits into independent, breadth-first parts with little shared context; expect about 15x the tokens of a chat and up to 90% less wall-clock.

    Topologies › Parallelizing

    FasterMixed qualityHigher cost

    Tier 4 · restructuring · changes control flow, context · any agent · 22 sources, 7 measured

  5. 7.a.ii

    Prompt chaining with gate checks

    Split a task that decomposes cleanly into fixed steps into a chain of model calls, one goal per call, with a gate between steps: a schema check, an assertion, or a run against the real system, and an LLM check only for subjective criteria.

    Orchestration › Routing

    Better qualityMore secureBetter governanceBetter for brandHigher costSlower

    Tier 4 · restructuring · changes control flow · any agent · 11 sources, 8 measured

  6. 7.c.ii

    Self-critique evaluator loop

    Train or tune the system's own judge from its own outputs and synthetic judgments (contrastive pairs with one side deliberately degraded, the judge's own verdicts kept only where they match the construction label) instead of human labels, then use it to score, select or train in the loop.

    Orchestration › Scaling compute

    Mixed qualityHigher cost

    Tier 3 · tuning · changes control flow · any agent · 11 sources, 10 measured

  7. 7.d.ii

    Inversion of control

    Give the agent the goal, the tools and the acceptance checks and let it choose the sequence of steps, instead of coding a fixed workflow; the goal, permissions, budget and evaluation stay outside the agent.

    Orchestration › Shaping the loop

    Mixed qualityHigher costSlower

    Tier 4 · restructuring · changes control flow · any agent · 6 sources, 4 measured

  8. 7.d.iii

    ReAct loop

    Run the agent as a loop: the model reasons, calls a tool, reads the result and picks the next step, until it answers or hits a cap.

    Orchestration › Shaping the loop

    Better qualityHigher costSlower

    Tier 4 · restructuring · changes control flow · any agent · 11 sources, 9 measured

  9. 9.a.i

    Feed back a sound external verifier's verdict; never the model's own critique

    Run a check the model cannot fool on its output (compiler, tests, schema validation, execution, EXPLAIN on generated SQL, a solver) and feed the verdict back; a pass/fail verdict is enough, and resampling until the check accepts works about as well as detailed feedback.

    Verification › Checking externally

    Better qualityHigher costSlower

    Tier 2 · reliability · changes control flow · any agent · 31 sources, 17 measured

  10. 9.b.iii

    Verify completion against the environment before the agent stops

    Never take the agent's own report that it finished.

    Verification › Confirming completion

    Better qualityHigher costSlower

    Tier 2 · reliability · changes control flow · any agent · 22 sources, 9 measured

  11. 9.c.ii

    Spend extra samples before extra verification: parallel attempts with a vote or judge; verify only where it pays

    Running several independent attempts and picking by majority vote or a judge raised accuracy (Genie 73.8% to 81.4% with 8 runs, at up to 2.1x cost).

    Verification › Sizing verification

    Better qualityHigher costSlower

    Tier 3 · tuning · changes control flow · any agent · 36 sources, 33 measured

  12. 10.a.i

    Constrain what the agent can touch

    Run the agent in an OS-level sandbox with a workspace path guard that resolves symlinks, scrub credentials from the command environment, run agent-written SQL read-only with timeouts and row caps, and set resource limits on generated code.

    Safety › Sandboxing

    Higher costSlower

    Tier 2 · reliability · changes guardrails · any agent · 5 sources

Before you go...

Build better agents, weekly

Our latest research, performance benchmarks, optimization strategies, and updates around AOT development.

One email a week, nothing else. Unsubscribe anytime.