Production AI Agents with Dynamic Planning and Reactive Evaluation

hex · Tech · 2023 · source Agentic: yes · promotional bias: low · summary-only (no fetched source) · extracted with prompt 0.5.6 (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: Data science notebook automation

Hex needed production agents that could automate multi-step data analysis workflows without letting open-ended plans, bloated context windows, or compounding errors make the Magic product unreliable.

Constraints:

Architecture

Hex Magic uses a constrained planning agent for data analysis workflows. The system infers a bounded plan, turns it into a DAG of dependent agent requests, runs independent steps in parallel, and keeps downstream nodes reactive to user edits. It bootstraps tools from proven human-facing capabilities such as SQL generation, prunes context aggressively for GPT-4 Turbo/GPT-3.5 calls, and evaluates with task-specific assertions and execution checks.

Diagram confidence: reconstructed (reconstructed from prose).

flowchart LR
  magic-user-interface["Magic user interface"] --> constrained-planning-agent["Constrained planning agent"]
  constrained-planning-agent["Constrained planning agent"] --> dag-execution-planner["DAG execution planner"]
  dag-execution-planner["DAG execution planner"] --> specialized-analysis-agents["Specialized analysis agents"]
  dag-execution-planner["DAG execution planner"] --> reactive-rerun-controller["Reactive rerun controller"]
  specialized-analysis-agents["Specialized analysis agents"] --> human-facing-feature-tools["Human-facing feature tools"]
  specialized-analysis-agents["Specialized analysis agents"] --> notebook-environment["Notebook environment"]
  context-pruning-layer["Context pruning layer"] --> specialized-analysis-agents["Specialized analysis agents"]
  context-pruning-layer["Context pruning layer"] --> gpt-4-turbo-model["GPT-4 Turbo model"]
  context-pruning-layer["Context pruning layer"] --> gpt-3-5-fallback["GPT-3.5 fallback"]
  reactive-rerun-controller["Reactive rerun controller"] --> specialized-analysis-agents["Specialized analysis agents"]
  evaluation-suite["Evaluation suite"] --> specialized-analysis-agents["Specialized analysis agents"]
  evaluation-suite["Evaluation suite"] --> execution-evaluator["Execution evaluator"]
  execution-evaluator["Execution evaluator"] --> notebook-environment["Notebook environment"]
Drag to pan · scroll or use +/− to zoom · reconstructed from the source's described component topology

Components

Component Role Interacts with
Magic user interface Interactive notebook surface where analysts ask questions, inspect outputs, and correct agent results. Constrained planning agent
Constrained planning agent Creates bounded multi-step plans using allowed response/interface types rather than arbitrary agent actions. Magic user interface, DAG execution planner
DAG execution planner Represents inferred plans as dependency graphs and schedules independent/dependent steps. Constrained planning agent, Specialized analysis agents, Reactive rerun controller
Specialized analysis agents Execute steps such as SQL generation, data transformation, and chart creation using product-aware tools. DAG execution planner, Human-facing feature tools, Notebook environment
Human-facing feature tools Capabilities first built for users directly, then exposed to agents once context and UX were understood. Specialized analysis agents
Notebook environment Execution context containing variables, packages, code, data frames, and generated analysis outputs. Specialized analysis agents, Execution evaluator
Context pruning layer Selects the minimal context needed for each prompt to control latency and correctness. Specialized analysis agents, GPT-4 Turbo model, GPT-3.5 fallback
GPT-4 Turbo model Primary model used for agent reasoning and generation. Context pruning layer
GPT-3.5 fallback Lower-cost model used only for specific tasks proven capable enough. Context pruning layer
Reactive rerun controller Reruns downstream agent steps when upstream user corrections change dependencies. DAG execution planner, Specialized analysis agents
Evaluation suite Family of evaluators and per-case assertions that define what AI features must pass. Specialized analysis agents, Execution evaluator
Execution evaluator Runs generated code and compares environment state before and after to assess correctness. Notebook environment, Evaluation suite

Data flow

A user asks Magic for a data analysis task. The planning step produces a constrained set of allowed steps rather than arbitrary sub-agent behavior. Hex converts that plan into a DAG, uses dependency information to parallelize independent steps and sequence dependent ones, and lets users correct upstream outputs. When an upstream response changes, affected downstream agents rerun without restarting the entire workflow.

3 supporting quotes
“Hex's agent system constructs a directed acyclic graph (DAG) under the hood based on the inferred plan.”summary, stated
“By understanding these dependencies, the system can execute independent steps in parallel while properly sequencing dependent ones.”summary, stated
“if a user makes a change to an upstream agent's response, the system knows which downstream agents need to be re-run.”summary, stated

Why this architecture

Hex chose bounded plan diversity and DAG reactivity because early open-ended agent planning had too much entropy. The architecture keeps users close to the chain, exposes tools learned from human workflows, and reduces latency by minimizing context rather than relying mainly on smaller models or fine-tuning.

3 supporting quotes
“The core problem was that they allowed for high diversity in the planning stage. The agent could decide how to structure its plan and orchestrate sub-agents with essentially "anything goes" flexibility.”summary, stated
“Before building a sub-agent that generates SQL as part of answering a question, they first built the standalone capability for users to generate SQL.”summary, stated
“The speed comes from aggressive pruning of what goes into the context window.”summary, stated

Models used: GPT-4 Turbo · GPT-3.5

Scale

Alternatives considered (roads not taken)

Open-ended plan generation with anything-goes sub-agent orchestration

Rejected because: It produced high-entropy behavior that was exciting in demos but unreliable for production.

“While this initially produced exciting results, it proved unsustainable for production use.”summary, stated

Ever-expanding libraries of narrow tools

Rejected because: Too-narrow tools require exponentially more tooling, while too-general tools let agents go off the rails.

“Tools that are too general allow the agent to go off the rails; tools that are too narrow require exponentially more tooling and create a rigid, limited interface.”summary, stated

Stuff more into long context windows

Rejected because: Hex found speed through context minimization, systematically removing unnecessary context.

“This contrasts with what he observed at AI meetups in summer 2023, where the focus was on jamming more and more into expanding context windows.”summary, stated

Generic reusable evaluation metrics only

Rejected because: Many Hex evals are case-specific assertions and execution checks, because correctness is nuanced.

“At Hex, many evaluators aren't broadly reusable across hundreds of test cases. Instead, each evaluation case comes with its own set of assertions.”summary, stated

Patterns

multi-agent-orchestration (architecture)

Hex uses a planner plus specialized sub-agents, but constrains the kinds of steps they can execute.

“Hex's initial approach to agents followed what has become a common pattern: having one agent generate a plan, then dispatching sub-agents to execute individual steps of that plan.”summary, stated

durable-execution (orchestration)

The DAG representation tracks dependencies so downstream work can be rerun after upstream edits.

“The system infers which steps in the plan require upstream response values, allowing for proper dependency management.”summary, stated

context-engineering (prompting)

Hex aggressively prunes prompt context to preserve speed while retaining enough information for correctness.

“• Systematically whittle down to determine what's actually needed”summary, stated

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

Users remain close to the agent pipeline so they can observe, correct, and steer outputs.

“The agents handle doing more things simultaneously and reactively, but everything comes from an interactivity paradigm. Users are right there to observe and reflect. This reduces death loops and increases productive iteration.”summary, stated

eval-driven-development (evaluation)

AI feature specifications are expressed as evals and per-case assertions that outputs must satisfy.

“Brian sees the new version of feature specs for AI features as: "these are the evals I want to pass." It sounds like an unusual form of test-driven development, but provides a concrete target: what the user asks, what the user gets in an ideal case, distilled down to important aspects.”summary, stated

latency-optimization (operations)

Latency is improved through minimal context construction rather than primarily by smaller models or fine-tuning.

“When the interviewer expressed surprise at how fast the system responds despite calling multiple models, Brian revealed their approach is fundamentally about context minimization”summary, stated

Tradeoffs

Plan constraint level

Chose Bounded general tools and prescribed step types over Either arbitrary tools or an ever-growing set of narrow tools.

Rationale: Bounded generality gives agents enough power without inviting uncontrolled behavior or rigid tool explosion.

“The key insight is that there's an inherent tension between tool generality and reliability. Tools that are too general allow the agent to go off the rails; tools that are too narrow require exponentially more tooling and create a rigid, limited interface.”summary, stated

Human workflow bootstrapping

Chose Build user-facing capabilities before exposing them to agents over Inventing sub-agent tools first.

Rationale: Human usage teaches the context, display UX, and refinements the agent will need later.

“When it came time to make these capabilities available to a supervising agent, they could leverage all these learnings.”summary, stated

Latency strategy

Chose Context pruning with GPT-4 Turbo primary over Mainly fine-tuning or switching to smaller models.

Rationale: Hex attributes speed to careful context minimization and uses GPT-3.5 only where it is good enough.

“The team uses GPT-4 Turbo as their primary model, falling back to GPT-3.5 only when they've identified it's capable enough for specific tasks. The speed comes from aggressive pruning of what goes into the context window.”summary, stated

Autonomy boundary

Chose Interactive agent pipeline with user correction over Devon-style unattended long-running automation.

Rationale: Keeping users nearby reduces loops and allows course correction.

“Rather than building Devon-style "click go, come back in two days" systems, Hex focuses on keeping the user close to the agent pipeline.”summary, stated

Gotchas (what bit them)

Open-ended plans were too high entropy.

Root cause: The planner could choose arbitrary structures and sub-agent orchestration patterns.

Resolution: Constrain the types of steps while preserving useful planning ability.

“The team encountered what Brian describes as "too high entropy" - not quite the death loops that plague some agent applications, but unexpected behaviors that made the system unreliable.”summary, stated

Context stuffing hurts latency and may not improve correctness.

Root cause: Teams tend to add every possible variable, package, history item, or query to the prompt.

Resolution: Start broad, then iteratively remove context until only the necessary pieces remain.

“Their process typically starts big and goes small:”summary, stated

Text-to-SQL fails without tacit institutional context.

Root cause: Schemas and RAG do not capture undocumented caveats like table migrations and business rules.

Resolution: Invest in data dictionaries, known query context, latent relationships, and better retrieval/search.

“This leads to the need for a data dictionary with "meta-metadata" - not just table schemas but all the caveats and institutional knowledge about the data.”summary, stated

Reliability compounds poorly across long agent chains.

Root cause: Even high per-step reliability can degrade over many chained steps.

Resolution: Keep the chain short and interactive rather than sending agents away for long unattended runs.

“A common critique of agents is that unreliable steps compound exponentially - if each step is 95% reliable and you chain 10 of them, overall reliability drops dramatically.”summary, stated

Evaluation

Hex builds a family of evaluators, often with per-case assertions and execution checks, so the desired product behavior becomes the specification for AI features.

Metrics: per-case assertions · toxicity guardrails · extractive statistics checks · vocabulary level · execution correctness · data frame generation

3 supporting quotes
“The approach at Hex involves building a family of evaluators where each tests one specific thing they care about.”summary, stated
“Execution evaluation is particularly valuable for code generation: executing the result and comparing the environment before and after provides rich information about correctness.”summary, stated
“At Hex, many evaluators aren't broadly reusable across hundreds of test cases. Instead, each evaluation case comes with its own set of assertions. Some are reusable (did it generate a data frame?), but there's significant nuance in determining correctness.”summary, stated

Outcomes

No cached source transcript is available, so quantitative production adoption is not independently stated beyond model choices and workflow shape.

“Hex has built a product called "Magic" that uses AI agents to help data scientists and analysts perform multi-step data analysis tasks.”summary, stated
“This reactivity allows users to intervene and correct agent behavior without having to restart the entire pipeline.”summary, stated