Building Production-Ready AI Analytics Agents Through Advanced Prompt Engineering

explai · Tech · 2025 · source Agentic: yes · promotional bias: med · source-backed · extracted with prompt 0.5.5 (schema v2)

Generated from extraction.json — do not edit by hand. Every claim cites verbatim source evidence; stated means the quote directly asserts the claim, implied means it supports it indirectly.

Problem

Domain: Enterprise analytics agents and data-companion systems

Explai needed production analytics agents that could help business users through multi-step, high-context data-science work without drowning the model in schemas, business documents, sampled tables, intermediate results, and accumulated snapshots.

Constraints:

Architecture

Explai reframed its product as an AI data companion: a multi-agent analytics system with specialized agents for SQL, plotting, forecasting, and causal inference. Instead of stuffing every useful fact into the prompt, the harness preloads tiny trigger messages, lets agents pull structured version-controlled documents through tools, writes intermediate tables as backend artifacts with metadata and lineage, and grants full-code autonomy only in sandboxed low-risk domains such as plotting while keeping SQL behind guarded workflows.

Diagram confidence: reconstructed (reconstructed from prose).

flowchart LR
  business-user[Business user] --> data-companion[Data companion]
  data-companion --> agent-coordinator[Agent coordinator]
  agent-coordinator --> sql-writer-agent[SQL writer agent]
  agent-coordinator --> plotter-agent[Plotter agent]
  agent-coordinator --> forecasting-agent[Forecasting agent]
  agent-coordinator --> causal-inference-agent[Causal inference agent]
  agent-coordinator --> context-manager[Context manager]
  context-manager --> trigger-messages[Trigger messages]
  trigger-messages --> document-retrieval-tools[Document retrieval tools]
  document-retrieval-tools --> structured-document-store[Structured document store]
  context-manager --> summarization-handover[Summarization handover]
  context-manager --> artifact-metadata-interface[Artifact metadata interface]
  sql-writer-agent --> sql-guardrail-workflow[SQL guardrail workflow]
  sql-writer-agent --> artifact-store[Artifact store]
  plotter-agent --> sandboxed-python-runtime[Sandboxed Python runtime]
  plotter-agent --> artifact-store
  forecasting-agent --> artifact-store
  causal-inference-agent --> artifact-store
  artifact-store --> artifact-metadata-interface
  artifact-metadata-interface --> frontend-artifact-viewer[Frontend artifact viewer]
  frontend-artifact-viewer --> data-companion
  sql-guardrail-workflow --> result-verification[Result verification]
  sandboxed-python-runtime --> result-verification
  result-verification --> agent-coordinator
Drag to pan · scroll or use +/− to zoom · reconstructed from the source's described component topology

Components

Component Role Interacts with
Business user Domain expert who brings workplace context, asks follow-up questions, and participates in the multi-step analytics process. Data companion
Data companion User-facing AI analytics system that coordinates specialized agents through an end-to-end data-science workflow rather than acting as a single BI query tool. Business user, Agent coordinator, Frontend artifact viewer
Agent coordinator Orchestration layer that routes analytical subtasks to specialist agents and controls what context each agent receives. SQL writer agent, Plotter agent, Forecasting agent, Causal inference agent, Context manager, Result verification
SQL writer agent Specialized agent for querying tabular data under constrained workflows and guardrails. Agent coordinator, SQL guardrail workflow, Artifact store
Plotter agent Specialized visualization agent that can generate full plotting code in a sandbox when the risk profile is acceptable. Agent coordinator, Sandboxed Python runtime, Artifact store
Forecasting agent Specialized analytics worker for model-selection and forecasting tasks that remain differentiating beyond commodity SQL generation. Agent coordinator, Context manager, Artifact store
Causal inference agent Specialized analytics worker for causal-analysis tasks that require appropriate methodology and result verification. Agent coordinator, Context manager, Artifact store
Context manager Prompt-engineering layer that writes, selects, compresses, and distributes context instead of indiscriminately preloading it. Agent coordinator, Trigger messages, Document retrieval tools, Summarization handover, Artifact metadata interface
Trigger messages Very short hints preloaded into agent contexts to tell agents when a larger domain document may be relevant. Context manager, Document retrieval tools
Structured document store Version-controlled, structured domain-knowledge documents with prerequisites, related content, and examples. Document retrieval tools
Document retrieval tools Tools that let agents pull full documents on demand, including multiple parallel pulls when several domain techniques may apply. Trigger messages, Structured document store, Context manager
Artifact store Backend storage for materialized tables and intermediate results, implemented with systems such as PostgreSQL or Pandas DataFrames. SQL writer agent, Plotter agent, Forecasting agent, Causal inference agent, Artifact metadata interface, Frontend artifact viewer
Artifact metadata interface Compact context representation exposing table names, schemas, statistics, scales, lineage, and access operations without putting full data into the prompt. Context manager, Artifact store, Frontend artifact viewer
Frontend artifact viewer UI layer that uses the same endpoints as agents to page through generated table artifacts. Data companion, Artifact metadata interface, Artifact store
SQL guardrail workflow Constrained SQL-generation path retained for high-risk data access where PII and data protection require stronger controls. SQL writer agent, Result verification
Sandboxed Python runtime Low-risk execution environment where plotting agents can write and rerun full visualization code. Plotter agent, Result verification
Summarization handover Compression mechanism preferred over trimming when time-to-token allows an extra synthesis cycle, especially between agent handovers. Context manager, Agent coordinator
Result verification Accuracy-focused checking layer needed because analytics errors can accumulate across multi-step workflows. Agent coordinator, SQL guardrail workflow, Sandboxed Python runtime

Data flow

A business user asks a high-context analytics question. The data companion coordinates specialized agents, preloads only compact trigger messages, lets agents pull full domain documents when needed, writes intermediate tables into a backend artifact store, exposes compact metadata and lineage to agents, pages full data through endpoints when required, and sends low-risk plotting work to a sandbox while keeping SQL behind guardrails.

4 supporting quotes
“It's always human in the loop and the agent is a companion in a sense of a consultant like a data analyst is a consultant.”transcript, stated
“you quickly figure out you have need to have this multi- aent system because you will have a plotter you will have a SQL writer”transcript, stated
“it has tools and endpoints to actually read and write. So it could head and tail it could grab it. Um it could see meta data like summary statistics and and scales of the of the columns and it would have cont useful context like lineage like is this a result”transcript, stated
“we wouldn't have our agent write freestyle SQL for example. Um we have a workflow with a lot of guard rates here.”transcript, stated

Why this architecture

Explai chose this architecture because analytics work is context-rich, iterative, and accuracy-sensitive, while the initial preload-everything approach made instruction following worse as data and enterprise use cases scaled. Pull-based documents, artifact references, summarization, isolation, and risk-based autonomy keep the context window focused without reducing the agent to a single-query BI wrapper.

4 supporting quotes
“great data analytics was never about who is the greatest SQL coder who can do I mean analysts before AI have been done natural language to SQL”transcript, stated
“we really saw instruction falling degrading once we scaled it um once we had our real enterprise use cases and and and and scaled it to um rele data.”transcript, stated
“preloading the agent context really broke broke broke the reasoning because it was just too much information. So we do it in a very different way now. So here you see an example of how to compute um some gross metrics. So it's it's a kagger it it has a a”transcript, stated
“if you apply those tactics you can actually give the agent more autonomy because it has a more more powerful potent infrastructure.”transcript, stated

Models used: Frontier LLMs · LangChain-style agent patterns · PostgreSQL · Pandas DataFrames · Plotly · Sandboxed Python runtime

Scale

Alternatives considered (roads not taken)

Preload domain knowledge, table information, documents, and intermediate results into every agent context

Rejected because: Explai found that data samples and accumulated context polluted the prompt and degraded instruction following at enterprise scale.

3 supporting quotes
“rag on all the table info. We would have documents that would give business knowledge. So we'd kind of preload the the agent with all the information we got. I mean and then once the analysis starts of course you have intermediate results. Um and then you have um I mean you might”transcript, stated
“summarization to kind of um then reduce noise and and make sure there's enough signal. So uh we felt very smart doing it, but it didn't work very well. And the reason was that I mean data is isn't small even when you I mean even when you sample it. Um so and then as we saw”transcript, stated
“we felt very smart doing it, but it didn't work very well. And the reason was that I mean data is isn't small even when you I mean even when you sample it. Um so and then as we saw before there is business data process there's all those different um there's all the different”transcript, stated

Push full documents into prompts

Rejected because: The preferred pattern is to preload only short trigger messages and let agents pull the full version-controlled document when the trigger is relevant.

“It has a trigger message which is very short. So you can actually you can preload it in every context which because it's just a simple sentence, right? So it would say here um when is keer actually useful. So and this is just one sentence. So you can put it”transcript, stated
“then you would have tooling for the agents to actually pull the full document when this trigger um is relevant.”transcript, stated

Put actual intermediate table data into the agent context

Rejected because: Explai materializes tables as backend artifacts and exposes compact metadata, schemas, statistics, and lineage instead of full rows.

“none of this table would be pushed into agent context but each of this table is is uh generated as a materialized view in the back end.”transcript, stated
“the agent would just see okay there is a table artifact that have a certain schema and table name and then it has tools and endpoints to actually read and write. So it could head and tail it could grab it. Um it could see meta data like summary statistics”transcript, stated

Have the plotter produce a constrained Plotly JSON declaration

Rejected because: Explai found full plotting code more flexible once sandboxing made the task low-risk.

“we would have the agent um create a JSON declaration that would then be handed over to the um to the Python runtime to to create the plot.”transcript, stated
“But we've saw actually you can have the agent write the full code and it will do just fine. Um and this is much more flexible because it might pre-agregate data. um for example it might in our case it's actually looking at the plot and seeing if there are”transcript, stated

Let agents write freestyle SQL

Rejected because: SQL touches protected enterprise data, so Explai kept SQL behind constrained workflows and guardrails.

“we want to go freestyle SQL because we we want to make sure there are um um right there data there's data protection PII data and stuff.”transcript, stated
“we wouldn't have our agent write freestyle SQL for example. Um we have a workflow with a lot of guard rates here.”transcript, stated

Trim context first when prompts get too large

Rejected because: The speaker prefers summarization before trimming when latency budget allows an extra synthesis cycle.

“Summarizing is great. So um I think you should prefer it before trimming whenever whenever time to token allows you to have an extra syncing cycle”transcript, stated

Patterns

multi-agent-orchestration (architecture)

Explai splits analytics work across specialized agents for SQL, plotting, forecasting, causal inference, and related tasks, with coordination and verification across the workflow.

“you quickly figure out you have need to have this multi- aent system because you will have a plotter you will have a SQL writer”transcript, stated
“you need to coordinate this agent. Um you need to make sure they're skilled. You need to verify results because data analytics is a lot about accuracy.”transcript, stated

rag-retrieval (retrieval)

Explai reverses the usual push-style RAG flow: it preloads tiny trigger messages and lets agents pull full domain documents only when relevant.

“So this is reversing the rack. So I did re I I mean I mentioned how us preloading the agent context really broke broke broke the reasoning”transcript, stated
“you would have tooling for the agents to actually pull the full document when this trigger um is relevant.”transcript, stated

prompt-versioning (prompt-operations)

The domain-document system treats knowledge artifacts as controlled, versioned prompt context rather than ad hoc text blocks.

“first it's it's version controlled and it's um and kind of it's it can be accessed by the system in a in a in a controlled way.”transcript, stated

context-compaction (context-management)

Explai uses summarization, selective pull retrieval, artifact references, and context isolation to avoid context-window pollution.

“when context gets too big you want to comp compress. I already mentioned summarization, trimming”transcript, stated
“Summarizing is great. So um I think you should prefer it before trimming whenever whenever time to token allows you to have an extra syncing cycle”transcript, stated

agent-memory (context-management)

Intermediate analytical tables are persisted as artifacts in backend storage, with agents retaining references, metadata, and lineage instead of row data.

“generated as a materialized view in the back end. Um so it can be a postgress it can be pandas pandas data frame”transcript, stated
“it has a SQL so it will give information about the lineage in other context so but the agencies is one line so very few tokens”transcript, stated

tool-use-orchestration (agent-control)

Agents use document-pull tools, artifact read/write endpoints, head/tail/sample operations, and plotting execution tools rather than relying solely on prompt text.

“good tooling for the agents um if you think about the primitives that the agent needs you have good tooling for the agent to explore those”transcript, stated
“it has tools and endpoints to actually read and write. So it could head and tail it could grab it.”transcript, stated

guardrails-io-filtering (safety)

Explai grants full-code autonomy for low-risk plotting but keeps SQL behind guarded workflows because of protected enterprise data.

“there's data protection PII data and stuff. So we so we wouldn't have our agent write freestyle SQL for example.”transcript, stated
“Um we have a workflow with a lot of guard rates here. But creating a plot for example is something we are fully comfortable to say.”transcript, stated

human-in-the-loop-gate (workflow)

The analytics process is designed around a human business user and an agent companion iterating through follow-up questions and analytical judgment.

“if there's a signal then there's always follow up. And so you have this this the this social cultural process that's always multi-step.”transcript, stated
“It's always human in the loop and the agent is a companion in a sense of a consultant like a data analyst is a consultant.”transcript, stated

privacy-preserving-processing (safety)

The system treats SQL and enterprise data access differently from plotting because protected data and PII require constrained execution.

“there are um um right there data there's data protection PII data and stuff.”transcript, stated
“So we so we wouldn't have our agent write freestyle SQL for example. Um we have a workflow with a lot of guard rates here.”transcript, stated

Tradeoffs

Use pull-based domain documents

Chose Short trigger messages plus on-demand document retrieval over Preloading all domain and business knowledge into agent contexts.

Rationale: Pull-based documents reduce context pollution while still letting agents retrieve prerequisites, related content, and examples when the technique is relevant.

3 supporting quotes
“It has a trigger message which is very short. So you can actually you can preload it in every context”transcript, stated
“then you would have tooling for the agents to actually pull the full document when this trigger um is relevant.”transcript, stated
“needs you have good tooling for the agent to explore those and they're they do it very efficiently actively but you need the discipline to set up in a structured way and there's this recent um anthropic post on they have skills right and and um um and you cannot just do it for skills you can do”transcript, stated

Represent intermediate results as artifacts

Chose Materialized table artifacts with metadata, lineage, and read/write endpoints over Putting raw table rows or samples directly into context.

Rationale: Artifacts keep token use low while preserving access to the underlying data through tools and UI endpoints.

3 supporting quotes
“none of this table would be pushed into agent context but each of this table is is uh generated as a materialized view in the back end.”transcript, stated
“the agencies is one line so very few tokens but it has all it has this infrastructure”transcript, stated
“even the front end here would actually see this as a table artifact. It would use an endpoint”transcript, stated

Grant full code autonomy for plotting

Chose Sandboxed Python plotting code over A constrained Plotly JSON declaration grammar.

Rationale: Full code lets the agent pre-aggregate data, inspect plots, rerun, and adapt to customer library preferences, while sandboxing keeps the risk acceptable.

3 supporting quotes
“we would have the agent um create a JSON declaration that would then be handed over to the um to the Python runtime to to create the plot.”transcript, stated
“you can have the agent write the full code and it will do just fine.”transcript, stated
“it's actually looking at the plot and seeing if there are labels overlapping or it's too crowded it will actually rerun”transcript, stated

Keep SQL constrained

Chose Guardrailed SQL workflows over Freestyle SQL generation.

Rationale: SQL has a higher risk profile because it touches protected enterprise data and PII, so it gets more guardrails than plotting.

“we want to go freestyle SQL because we we want to make sure there are um um right there data there's data protection PII data and stuff.”transcript, stated
“we wouldn't have our agent write freestyle SQL for example. Um we have a workflow with a lot of guard rates here.”transcript, stated

Build a data companion rather than only a BI interface

Chose A multi-step consultant-like analytics agent over A natural-language-to-SQL or plotting wrapper around BI tools.

Rationale: Explai argues that analytical value comes from follow-up, context, and domain judgment rather than just producing a number or a chart.

3 supporting quotes
“a lot of people try to build natural language to SQL or or like producing plots or sprinkle sprinkle AI on on on BI tools”transcript, stated
“if a single query can answer then it wasn't interesting question to begin with.”transcript, stated
“the agent is a companion in a sense of a consultant like a data analyst is a consultant.”transcript, stated

Prefer summarization before trimming when latency allows

Chose An extra summarization cycle for compression over Immediate context trimming.

Rationale: Summarization can preserve signal better than simple trimming, especially at agent handovers, but costs extra time-to-token.

“you should prefer it before trimming whenever whenever time to token allows you to have an extra syncing cycle to spend on summarization.”transcript, stated
“That can be super powerful um especially between handovers of agent.”transcript, stated

Gotchas (what bit them)

Preloading all available context degraded reasoning instead of improving it.

Root cause: Business documents, table metadata, data-science guidance, samples, intermediate SQL results, and snapshots accumulated until the prompt became noisy and unfocused.

Resolution: Reverse the retrieval direction: preload compact triggers and let agents pull structured documents or artifacts only when needed.

3 supporting quotes
“we'd kind of preload the the agent with all the information we got.”transcript, stated
“they do accumulate, right? And um and kind of pollute the context in a sense.”transcript, stated
“preloading the agent context really broke broke broke the reasoning because it was just too much information.”transcript, stated

Sampled data is still large enough to poison an agent context.

Root cause: Enterprise analytics data, even previews or samples, can include thousands of rows and multiple accumulated result snapshots.

Resolution: Store data as backend artifacts and expose only schema, lineage, summary statistics, and endpoint access in the prompt.

3 supporting quotes
“There might be thousands of rows. So you do previews. So you get actual real data into the context, samples of it.”transcript, stated
“data is isn't small even when you I mean even when you sample it.”transcript, stated
“the agent would just see okay there is a table artifact that have a certain schema and table name”transcript, stated

Analytics agents need verification because errors can accumulate across steps.

Root cause: Data analysis chains multiple specialized operations, so an early SQL, forecasting, or plotting mistake can contaminate downstream reasoning.

Resolution: Coordinate specialist agents with explicit result verification and accuracy checks rather than treating each step as an isolated completion.

“You need to verify results because data analytics is a lot about accuracy. So you can't have errors accumulate.”transcript, stated

Tool-heavy interaction can add brittleness or friction.

Root cause: Some workflows require many subsequent tool calls, which can complicate execution and slow the agent down.

Resolution: Use full-code generation in sandboxed low-risk domains when code can compact multiple tool interactions into one flexible execution path.

“there's a lot of tool use and depending how well it works that that of course can you might have subsequent calls and um so it can be brittle or or add some friction”transcript, stated
“But we've saw actually you can have the agent write the full code and it will do just fine.”transcript, stated

Full autonomy is not equally safe across all analytics tasks.

Root cause: SQL execution touches data protection and PII concerns, while plotting in a sandbox is lower risk.

Resolution: Apply risk-based autonomy: full code for sandboxed plotting, but guardrailed workflows for SQL.

3 supporting quotes
“we want to make sure there are um um right there data there's data protection PII data and stuff.”transcript, stated
“creating a plot for example is something we are fully comfortable to say.”transcript, stated
“and if a user doesn't want if a customer doesn't want pl something else we can still we can also do it right so this is low risk we feel a sandbox and and so the flexibility of the sandbox is Durk, we're running short on time. >> That's fair. Let me wrap up 30 seconds, but that's a fair”transcript, stated

Without RL or fine-tuning, prompt/context management becomes the learning mechanism.

Root cause: Most workloads do not actually update model weights, so the system has to encode learning through prompts, context, tools, and structured knowledge.

Resolution: Treat prompt engineering and context-window management as core production infrastructure rather than cosmetic prompt polish.

“agents don't learn really so we don't have reinforcement learning or fine-tuning in most of our workloads”transcript, stated
“prompt engineering and what you what you put in the context window is really how you manufacture learning”transcript, stated

Evaluation

The talk does not present a formal benchmark table, but it does describe production evaluation needs: result verification for analytics accuracy, monitoring instruction-following degradation under enterprise data scale, checking context-management tactics against real workflows, and validating autonomy by task risk profile.

Metrics: Instruction-following degradation at enterprise data scale · Result accuracy across multi-step analytics · Error accumulation across agents · Number of parallel document-tool calls · Tokens consumed by table artifact references · Tool-call friction or brittleness · Plot correctness and rerun ability · PII/data-protection guardrail compliance

4 supporting quotes
“we really saw instruction falling degrading once we scaled it um once we had our real enterprise use cases”transcript, stated
“You need to verify results because data analytics is a lot about accuracy. So you can't have errors accumulate.”transcript, stated
“with the frontier models you would actually have it's no problem to have 5 10 15 calls in parallel.”transcript, stated
“the agencies is one line so very few tokens but it has all it has this infrastructure”transcript, stated

Outcomes

The transcript describes a two-year product journey, a first-year failure mode, real enterprise use cases, 5/10/15 parallel tool calls, thousands-row previews, and a 200-point artifact example; it does not provide quantitative accuracy, latency, or customer adoption results.

4 supporting quotes
“So uh we felt very smart doing it, but it didn't work very well. And the reason was that I mean data is isn't small even when you I mean even when you sample it.”transcript, stated
“with the frontier models you would actually have it's no problem to have 5 10 15 calls in parallel.”transcript, stated
“there's 200 data points here and we just see the first five and it can be paged interactively.”transcript, stated
“done um and give more autonomy to the agent here um and workflow is is a is is a is a goal and actually I saw once you have those primitives then reacting code works just fine so being overtime let me wrap up so here's three of us in the company that that love uh that love to talk to you so”transcript, stated