Blog

Most agent workflows should start as one good prompt

Before you draw a state graph for an AI agent, give it a clear goal and a way to check its own work. Often that is all it needs, and the rest can be handled with hooks, guardrails and evaluations.

Buried in last month's PHP security news was one small phrase: "find bad vulnerabilities in PHP."

That was the whole prompt, according to Chainguard CEO Dan Lorenc. His team had heard from a researcher that a problem was coming in PHP, the programming language behind WordPress, Wikipedia and a large share of the web. That same night, using the company's AI harness and a frontier model, they entered this prompt and were able to recreate an exploit1. How Chainguard then released its fix has started a real fight with the PHP maintainers, and that dispute is worth reading on its own.

A lot has been written about what this means for security. I keep thinking about the prompt. It is one clear statement of a goal, something a model can understand. Just as important, the model could use its tools to check whether it had succeeded. A vulnerability either reproduces or it does not.

Too often in my engagements, I see teams do the opposite. Before the model gets a chance to work the problem, they wrap it in a hand-drawn workflow. So please hear my cry: before you build a state graph for an agent, try just giving agents a clear measurable goal. Often that is all you need.

A graph decides the path before anyone sees the problem

Too often in my engagements, I see code like this:

Python
def build_graph():
    g = StateGraph(TicketState)
    # 1. Classification (LLM)
    g.add_node("classify", stub("classify"))
    # 2. Four team nodes
    for team in TEAMS:
        g.add_node(f"{team}_team", stub(f"{team}_team"))
    # 3. Deterministic enrichment nodes (no LLM)
    g.add_node("customer_lookup", stub("customer_lookup"))
    g.add_node("system_status", stub("system_status"))
    # 4. LLM synthesis chain
    g.add_node("narrate", stub("narrate"))
    g.add_node("reason", stub("reason"))
    g.add_node("summarize", stub("summarize"))

    g.add_edge(START, "classify")
    # Conditional fan-out: classify -> exactly one team
    g.add_conditional_edges(
        "classify",
        route_by_category,
        {team: f"{team}_team" for team in TEAMS},
    )
    # Every team fans out to BOTH deterministic nodes (run in parallel)
    for team in TEAMS:
        g.add_edge(f"{team}_team", "customer_lookup")
        g.add_edge(f"{team}_team", "system_status")
    # Join: narrate waits for both lookups to finish
    g.add_edge(["customer_lookup", "system_status"], "narrate")
    g.add_edge("narrate", "reason")
    g.add_edge("reason", "summarize")
    g.add_edge("summarize", END)
    return g.compile()

This is a LangGraph state graph. LangGraph is a popular open-source framework that builds an agent as a map of steps: each node is a function or a model call, and each edge says what runs next. This one triages support tickets. A model classifies the ticket and routes it to exactly one of four team nodes. Every team node then fans out to two lookups that run in parallel, one for the customer record and one for system status. Three more model calls follow in a fixed chain: narrate, reason, summarize.

It is a fine approach, and it will run. But strip away the nodes and the job comes down to two questions: what is this customer's issue, and who should own it? A capable model with access to the customer record and the status page can answer both in one pass, and it can decide for itself which lookups the ticket actually needs.

Here is roughly what that looks like as a prompt:

Prompt
A customer ticket is below. Work out what the customer's issue is
and which of our four support teams should own it.

You can look up the customer record and current system status.
Use whichever lookups the ticket needs.

Before you answer, check your work:
- Every fact in your summary comes from the ticket or a tool result.
- If the customer's tier or an active incident changes who should
  own it, say so.

Return the issue in two sentences, the owning team, and the
evidence you used.

The prompt says what done looks like and how to check it. The tools give the model a way to gather evidence. The order of operations is left to the model, which is the part it is good at.

Not every problem is a state machine

As engineers, we have a natural instinct to break everything down into a state machine. If we just model this set of tables or this class hierarchy, it will all make sense. In the graph above, every support ticket travels the same set of nodes in the same order.

I know what you are thinking. "We need to know that every ticket gets classified." "Won't the model just hallucinate a response?" Those are fair concerns, and I will come back to them. But the graph answers them by imposing a rigid path, and flexibility in how you respond was the whole reason to use an agent in the first place.

Models are already trained to work a problem

Most agents are built around a cycle called ReAct, short for reason and act2. The agent reasons about what the user wants, takes an action such as calling a tool, observes the result, and repeats until the task is done. There are plenty of clever variations, but this loop is the most common pattern.

For many current models, this way of working is trained in directly. After a model learns language, it goes through post-training: further rounds of training that teach it to follow instructions, reason step by step and use tools. Every lab's post-training is different, and it is one of the biggest differences between model families. Still, a lot of post-training data encodes reasoning and observation steps right into the model.

You can see this in NVIDIA's public Nemotron post-training dataset3. Here is one math row. The prompt:

Prompt
A cuboid with a square base has a diagonal of length $d$ and a surface area of $b$. Calculate the sum of the lengths of all edges of the cuboid.

And an excerpt from the response the model is trained to produce (the full trace is much longer):

Model output
<think>
I have a cuboid with a square base. That means the length and width are equal, and the height might be different. The diagonal is given as \( d \), and the surface area is \( b \). I need to find the sum of the lengths of all edges.

First, recall that a cuboid has 12 edges. Since the base is square, let's denote the side of the base as \( a \), and the height as \( h \).

[...]

Another way to think: since u = 2a + h, and u^2 = d^2 + b, as we derived.

And s = 4u, so yes.

I think that's correct.

So the answer is \( 4 \sqrt{d^2 + b} \)
</think>

Look at what is in that trace. The model names its variables, recalls the formulas it needs, does the algebra, and then checks its own answer before committing to it. All of that is behavior it has been rewarded for.

Now imagine that instead of the plain prompt, we built a graph: identify the shape, then get the formula, then send the work through arithmetic nodes for sum, minus, multiply and divide, then an answer check, then the answer. It would work. It would also be wasted effort, and it would interrupt the exact behavior the model was trained to perform.

Give it the goal and a clear way to validate success instead.

Why teams build graphs anyway

In my experience, teams end up with complicated graphs for three main reasons. One of them holds up well. The other two have better answers now.

Chasing determinism. Enterprises want AI to automate a workflow, but they also want to know exactly how it will respond every time. That is a good instinct, but hard-coding the path robs the system of resilience and flexibility. What if, instead of a support ticket, a prospect emails a product question to the wrong channel? Does the triage node have a route for product questions? Can the agent look up which account manager owns that prospect? Is it even connected to the CRM? A more freeform agent with the right tools could simply handle it.

You can get the same protections in other ways. A robust evaluation pipeline, meaning a set of realistic test cases you run against the agent before and after every change, gives you confidence that it is not making up answers. Agent frameworks also provide tool call hooks: functions that run just before or just after the agent calls a tool. A hook can interrupt the agent's cycle with a message like "This customer is a Tier 1 Support customer. Stop your response and escalate immediately." Here is a sketch using the Claude Agent SDK's PreToolUse hook4:

Python
from claude_agent_sdk import ClaudeAgentOptions, HookMatcher

# Runs before the agent calls the tool that sends a customer reply.
async def escalate_tier_one(input_data, tool_use_id, context):
    customer_id = input_data["tool_input"].get("customer_id", "")
    if lookup_support_tier(customer_id) == "tier_1":  # your CRM lookup
        return {
            "hookSpecificOutput": {
                "hookEventName": input_data["hook_event_name"],
                "permissionDecision": "deny",
                "permissionDecisionReason": (
                    "This customer is a Tier 1 Support customer. "
                    "Stop your response and escalate immediately."
                ),
            }
        }
    return {}  # anyone else: let the reply go through

options = ClaudeAgentOptions(
    hooks={
        "PreToolUse": [
            HookMatcher(matcher="mcp__support__send_reply",
                        hooks=[escalate_tier_one])
        ]
    }
)

If you need more, a guardrail (a second model or rule set that reviews the output) can critique a response for suitability before it reaches the customer. All of this controls the agent without resorting to hard-coded determinism.

Model strength. You cannot solve every problem with Claude Fable or GPT-5.6 Sol. Very small models can be very cost effective, but they need more active controls to stay on task. This reason is absolutely valid. In my work, I am often asked to run small models at the edge on dedicated hardware, and despite what you see on TikTok about hosting your own LLM, a 27B model does not perform like the frontier models. Walking a small model through a specific set of steps keeps its context clean, keeps it on task and keeps its output in the shape you need.

Runtime simplification. Agent frameworks like LangGraph and CrewAI fit neatly into server-side software. They expose natural HTTP endpoints and they call functions as tools, so they are an easy runtime for getting agents up and running. The most popular agents today do not work that way. Coding agents run inside a full Linux sandbox with tools to read, write, search and run code. New personal agents like Meta's Muse and Anthropic's Claude Duet do their work on their own cloud virtual machines5,6. That is a hard runtime to test and orchestrate.

It is also why more products are bridging the gap. Cursor made its Agent SDK8 generally available on October 20, built on the same harness behind its own review and security agents7. Anthropic's Claude Agent SDK9 embeds the Claude Code agent loop, with its tools, hooks and subagents, directly in your Python or TypeScript code. There are many open-source options too.

What to do instead

  • Write a clear goal. One or two sentences that say what done looks like, the way "find bad vulnerabilities in PHP" does.
  • Say how success gets checked. Tell the agent what evidence it needs and how to confirm its own answer: a test that passes, a fact traced to a tool result, a reproduction.
  • Give it enough safe tools to explore. Read access to the systems that matter, with hooks on anything that writes, sends or spends.
  • Use a subagent when context gets crowded. A subagent is a second agent the first one hands a focused task to, so the main conversation stays clean. Sometimes that is the only structure you need.
  • Evaluate on realistic data. Run the agent against real tickets, real documents and real edge cases before you trust it, and every time you change it.

If the evaluations show a specific failure, fix that failure with a hook, a check or a better tool. Add a graph only when the evidence says you need one.

The PHP prompt worked because the goal was clear and the result could be checked. Give your agents those two things before you give them a flowchart.

At ES Consulting, our senior engineers work inside your systems and alongside your team to build agents like these: clear goals, safe tools, and evaluations on your own data so you can see how they behave before they go live. You own the result, and your team knows how to keep building it. Talk to our team.

Sources

  1. PHP blames supply chain security biz Chainguard for putting huge chunks of the web at risk, The Register, October 2026↩
  2. ReAct: Synergizing Reasoning and Acting in Language Models, Yao et al., arXiv, October 2022↩
  3. Nemotron-Post-Training-Dataset-v1, NVIDIA on Hugging Face (CC BY 4.0)↩
  4. Intercept and control agent behavior with hooks, Anthropic, Claude Agent SDK docs↩
  5. Meta Launches Muse Personal AI Agent With Secure VM, WhatsApp Access and Payments, AI Cybr, September 2026↩
  6. Claude Duet: Anthropic Previews an AI Agent That Messages You First, VKTR, October 2026↩
  7. Introducing Agent SDK, Cursor, October 2026↩
  8. Agent SDK docs, Cursor↩
  9. Agent SDK overview, Anthropic, Claude Agent SDK docs↩

More from the blog

All posts

Predictive AI10 min read

Your AI agents need something to be right about

An LLM will tell you which customers are about to leave, but not with a probability you can check. Why agents need predictive models underneath them, and how to wire the two together.

Justin S.

Agents3 min read

What makes an AI-found bug report worth reading?

When an AI agent reports a bug, the report is part of the job. What a useful one contains, so a developer can see the problem again, judge its impact and decide what to do next.

Shane Z.

Part 1 of 3 · AI-native engineering

AI SDLC14 min read

Designing for AI-scale throughput

Most teams bought the same AI coding tools, and only some of them ship faster. What a team of three changed around the tools to go from 200 code changes a month to about 10,000.

Tobi O.

Work with us

Ready to get your AI into production?