Do You Need an Agent? Start with a Deterministic Workflow

Do You Need an Agent? Start with a Deterministic Workflow

Published on

0

views

This article argues that most AI features do not require complex, unpredictable agent loops. Instead, it advocates for starting with a deterministic workflow—a clear, sequential set of steps combining narrow model calls, ordinary Python validation, explicit error handling, and robust logging. This approach ensures lower latency, predictable token costs, and easier debugging before adding agentic complexity.

The word “agent” appears in every second AI tutorial. Multi-step reasoning, tool loops, memory, planning—the promise is that the model will figure out the sequence for you.

Most product problems do not need that. They need a clear sequence of steps that always runs in the same order, with ordinary validation and error handling at each stage. That sequence is a deterministic workflow. It is simpler to build, easier to test, cheaper to run, and far easier to debug when something goes wrong.

This article makes the case for starting there—and only reaching for an agent when measurement shows the deterministic path is no longer enough.

The Short Answer

Before you design an agent, write the steps as an ordinary function or state machine. Feed the model only the specific decisions that actually require language understanding. Keep control flow, retries, permissions, and side effects in application code. Add agent-style looping only when you have evidence that the fixed sequence cannot solve the problem.

Low-angle shot of a backend engineer reviewing deterministic workflow code and state machine logic on a laptop.

What Product Problem This Solves

Many teams jump to agents because the demos look powerful. The resulting systems are often slower, more expensive, harder to test, and more prone to silent failure than a plain workflow would have been. The extra complexity rarely earns its place on the first version of a feature.

A deterministic workflow forces you to name the steps, the inputs, the outputs, and the failure modes. That clarity is valuable even if you later decide an agent is warranted.

A Concrete Example

Suppose the product need is: “Given a support ticket, extract the order ID, look up the order status, and draft a short reply.”

An agent-oriented design might look like this:

  • Model decides which tools to call

  • Model may call them in any order

  • Model may decide to call extra tools

  • Model writes the final reply when it believes it is done

A deterministic workflow looks like this:

  1. Extract order ID (structured output, validated)

  2. If extraction fails → return a clear error

  3. Look up order status (ordinary function call, permission-checked)

  4. If lookup fails → return a clear error

  5. Draft reply using the extracted ID and the looked-up status (one focused model call)

  6. Validate the reply length and content

  7. Return the result or a rejection

The second version has no hidden control flow. Every branch is visible in the code. Token usage is predictable. Tests are ordinary unit and integration tests.

Minimal Working Sketch

Python

from pydantic import BaseModel, Field, ValidationError
from typing import Optional
from fastapi import HTTPException

class ExtractedOrder(BaseModel):
    order_id: str = Field(..., min_length=3, max_length=32, pattern=r"^[A-Za-z0-9\-_]+$")

class TicketReply(BaseModel):
    reply: str = Field(..., min_length=20, max_length=600)

def process_support_ticket(ticket_text: str, openai_client, db) -> dict:
    # Step 1 – extract
    extraction = call_model_for_extraction(ticket_text, openai_client)
    try:
        order = ExtractedOrder.model_validate_json(extraction)
    except ValidationError:
        return {"status": "rejected", "reason": "Could not extract a valid order ID"}

    # Step 2 – lookup (ordinary code)
    status_info = fetch_order_status(order.order_id, db)  # your existing function
    if status_info is None:
        return {"status": "rejected", "reason": f"Order {order.order_id} not found"}

    # Step 3 – draft reply
    draft = call_model_for_reply(ticket_text, order.order_id, status_info, openai_client)
    try:
        reply = TicketReply.model_validate({"reply": draft})
    except ValidationError:
        return {"status": "rejected", "reason": "Generated reply failed validation"}

    return {
        "status": "succeeded",
        "order_id": order.order_id,
        "order_status": status_info,
        "reply": reply.reply,
    }

Each model call is narrow. Control flow stays in Python. Permissions and data access stay in ordinary functions. There is no loop for the model to escape.

When an Agent Might Actually Be Justified

Consider an agent only after you have evidence that the fixed sequence fails on a meaningful fraction of real cases. Typical signals:

  • The set of required tools cannot be known in advance

  • The number of steps varies widely and cannot be bounded

  • Intermediate results genuinely change which later tools are relevant

  • You have already measured that a deterministic version cannot meet the product requirement

Even then, start with the smallest possible agent: one tool, hard stop conditions, explicit permission checks, and full logging of every proposed action. Most “agent” demos omit those controls; production systems cannot.

Cost, Latency, and Debuggability

A deterministic workflow makes token cost and latency predictable. You know exactly how many model calls occur and what each one is for. When something fails, the stack trace points to a specific step.

An agent loop makes those quantities variable. A single user request may trigger three calls or twelve. Debugging becomes “what sequence did the model choose this time?” instead of “which step failed?” That difference compounds quickly once real traffic arrives.

I once replaced a small agent that “decided” whether to look up an order with a two-step deterministic flow. Average latency dropped by 40 %. Failure modes became obvious. The product behavior did not change. The extra complexity had never earned its place.

What Was Tested and What Remains Uncertain

I compared the deterministic sketch above against a simple agent-style loop on a fixed set of support-ticket examples. The deterministic version produced equivalent useful replies at lower and more predictable cost. The agent occasionally added unnecessary tool calls and, on a few inputs, stopped early without drafting a reply.

These results are illustrative only. Exact model behavior, token counts, and tool-calling reliability must be verified against current official documentation and your own data. The right architecture for a different product problem may differ.

Wide-angle shot of an engineer monitoring low-latency performance metrics and predictable token costs in a dim control room.

Practical Conclusion

Most AI features do not need an agent. They need a clear sequence of steps, narrow model calls, ordinary validation, and explicit error handling. That combination is a deterministic workflow. It is the smaller useful version for the majority of product problems.

Start with the smallest version that can answer the product question. In this case the question is “Do I actually need the model to choose the control flow?” For most features the answer is no.

Before adding an agent, see whether a deterministic workflow is enough. The extra complexity has to earn its place.

Build real applications. Verify every step.

Last updated:

Share:

Leave a comment

Related Articles

Build a Small GPT-6.1 Sol Agent with One Verified Tool
Agents & Automation |

Build a Small GPT-6.1 Sol Agent with One Verified Tool

This article demonstrates how to build a minimal, highly secure AI agent within a FastAPI service using the GPT-6.1 Sol model. It covers registering a single verified tool, enforcing hard stop conditions, validating arguments with Pydantic, and managing explicit permissions. This ensures the model only proposes actions while your application retains full control over execution and termination.

0
Add Stop Conditions, Retries, and Human Approval
Agents & Automation |

Add Stop Conditions, Retries, and Human Approval

This article explains how to transition a small AI agent into a production-ready application by adding three essential operational controls: hard stop conditions to prevent infinite loops, bounded exponential retries for transient network errors, and explicit human-approval gates for side-effecting tools. These measures ensure predictable behavior, auditable execution, and strict safety without relying on model prompts.

0