Skip to content
JL

Home

About

Blog

Contact

Shop

Portfolio

Privacy

TOS

Click to navigate

  1. Home
  2. Joshua R. Lehman's Blog
  3. Designing the AI Agent Lifecycle

Table of contents

  • Share on X
  • Discuss on X

Related Articles

Next.js App Router Mental Model
Next.js
12m
Sep 17, 2026

Next.js App Router Mental Model

The App Router becomes much easier once you stop treating every component as a browser component. Learn how a route is assembled on the server, where interactivity belongs, and how layouts create durable UI boundaries.

#Next.js#App Router+4
Building Custom Utility Types in TypeScript
TypeScript
12m
Sep 15, 2026

Building Custom Utility Types in TypeScript

TypeScript's built-in utility types are useful because they transform a type you already trust. This post shows how to build the same kind of focused helpers yourself: shallow and deep partials, mutable views, nullable fields, and API-safe update inputs.

#TypeScript#Custom Utility Types+4
Utility Types Part 5: ReturnType and Parameters
TypeScript
9m
Sep 13, 2026

Utility Types Part 5: ReturnType and Parameters

ReturnType and Parameters are utility types that inspect function types rather than object types or unions. ReturnType extracts the type a function returns. Parameters extracts the types of its arguments as a tuple. Both are implemented using conditional types with infer, and both are essential for writing type-safe wrappers, decorators, and higher-order functions without duplicating type information.

#Utility Types#ReturnType+5
Ask me anything! 💬

© Joshua R. Lehman

Full Stack Developer

Crafted with passion • Built with modern web technologies

2026 • All rights reserved

Contents

  • An Agent Is a System
  • Define the Lifecycle
  • Give Each Stage a Contract
  • Design Tool Authority Deliberately
  • Verify Before You Act
  • Make Recovery a First-Class Path
  • A Small Production Blueprint
  • What Is Next
  • Key Takeaways
AI Engineering

Designing the AI Agent Lifecycle

September 20, 2026•6 min read
Joshua R. Lehman
Joshua R. Lehman
Author
AI agent lifecycle diagram connecting planning, tools, memory, evaluation, and human approval
Designing the AI Agent Lifecycle

The difference between a useful AI agent and an impressive demo is not the model alone. It is the lifecycle around the model: how work enters the system, how context is assembled, what the agent may do, how its results are checked, and what happens when it is uncertain or wrong.

Calling a model with a tool list is only one stage of that lifecycle. Production systems need explicit authority, observable state, verification, and a safe route back to a human. Those constraints make an agent more predictable, easier to debug, and more valuable than a prompt that occasionally produces an impressive answer.

An Agent Is a System

An agent can reason over a goal, select tools, inspect results, and decide what to do next. That loop makes it more capable than a one-shot chat completion. It also increases the number of ways the system can fail.

The model can misunderstand intent. Context can be stale. A tool can return incomplete data. A seemingly harmless action can be irreversible. An evaluation can reward a plausible answer instead of a correct outcome.

Engineering starts by treating those possibilities as normal system states rather than rare exceptions.

Autonomy Is a Product Decision

The right question is not whether an agent can take an action. It is whether the expected value of taking it automatically exceeds the cost of a mistake in this specific workflow.

Define the Lifecycle

A practical lifecycle has seven stages:

  1. Intake — accept a goal, identity, constraints, and success condition.
  2. Context — retrieve only the information needed to reason well.
  3. Plan — describe intended steps and identify required tools.
  4. Execute — call tools with bounded authority and structured inputs.
  5. Verify — inspect outputs against a deterministic check, policy, or reviewer.
  6. Decide — continue, ask for clarification, request approval, or stop.
  7. Record — persist an auditable summary, outcome, and feedback signal.

Not every task needs every stage at the same depth. A read-only research assistant may execute a few safe searches and return citations. A deployment agent needs strong identity checks, explicit approval, logs, rollback paths, and post-action verification.

Give Each Stage a Contract

Vague state is the enemy of reliable automation. Define what enters and leaves each stage as structured data:

type AgentRun = {
  goal: string;
  actorId: string;
  allowedTools: string[];
  approvalRequired: boolean;
  status:
    | "planning"
    | "executing"
    | "awaiting_approval"
    | "complete"
    | "failed";
};
 
type ToolResult = {
  tool: string;
  success: boolean;
  summary: string;
  evidence: string[];
  retryable: boolean;
};

These types do not make the model correct. They do make the system easier to inspect. A run log can answer: who started this, what authority did it receive, what tool was called, what evidence came back, and why did the workflow stop?

Design Tool Authority Deliberately

Tools are where an agent becomes operational. They should be designed like any other production API: small, typed, observable, and scoped to the caller.

Avoid a universal run_command tool or a generic database tool when a narrower operation is possible. create_draft_invoice, read_customer_summary, and request_deployment are easier to authorize and evaluate than one broad endpoint with an enormous input surface.

Read and Write Tools Are Different

Read-only tools can often run with much higher autonomy. Tools that create, delete, publish, charge, or change permissions should have explicit policy checks and, when appropriate, human approval.

Authority should be carried with the run, not assumed from the model. The workflow decides what the agent may call before the model chooses a tool. The tool service independently verifies that authorization before it acts.

Verify Before You Act

Models are good at proposing work. They are not a substitute for deterministic checks. Verification should match the risk:

  • validate a generated request against a schema;
  • run tests before opening a pull request;
  • compare an extracted value against source evidence;
  • show a preview before a destructive action; and
  • require a human decision when the policy cannot be made deterministic.

The key is separating generation from acceptance. An agent may draft an SQL migration, but a schema check and review process decide whether it is valid. An agent may summarize a support ticket, but a human or policy determines whether a refund is issued.

Make Recovery a First-Class Path

Failure should not mean the run vanishes into a retry loop. Each failure needs a next state: retry with a bounded budget, ask a question, route to a human, compensate an action, or stop with a useful audit record.

1

Classify errors as retryable, recoverable with new information, approval-required, or terminal.

2

Preserve the smallest useful context for a retry rather than replaying an unbounded conversation.

3

Record the reason for escalation so a human sees the decision point, not a raw transcript.

This is also where good observability pays off. Track tool latency, refusal reasons, retries, approval requests, and final outcomes. Those signals tell you whether the agent is genuinely helping or merely producing activity.

A Small Production Blueprint

For a first production agent, keep the loop intentionally narrow:

validated request
  → scoped context retrieval
  → proposed plan
  → read-only tools
  → deterministic verification
  → human approval for writes
  → audit record and outcome metric

Start with a workflow where a human already has a clear, repeatable process. Make the agent assist one expensive or error-prone stage. Measure the outcome. Then expand authority only after the evidence says the added autonomy is worth it.

What Is Next

The lifecycle tells you where context belongs. The next AI Engineering post focuses on context engineering: selecting, compressing, and refreshing the information an agent needs without burying the task in irrelevant history.

Key Takeaways

  • An agent is a lifecycle of decisions and controls, not just a prompt plus tools.
  • Define explicit contracts for intent, authority, tool results, verification, and recovery.
  • Keep tools narrow and independently authorized.
  • Separate model generation from deterministic or human acceptance.
  • Design escalation and auditability before increasing autonomy.

Operational Hardening Checklist

Before granting a lifecycle new authority, rehearse its unhappy paths. Simulate a duplicate user request, an expired credential, a tool timeout after a write may have succeeded, an indirect instruction hidden in retrieved content, a policy denial, and an operator who must reconstruct the run a week later. For each case, define the state transition, evidence retained, retry budget, user message, and human owner.

Make approval decisions bind to a specific proposed action and its parameters, not to a vague conversation. An approval to publish one draft must not become permission to publish a later regenerated draft. Similarly, make idempotency visible for consequential tools: the lifecycle should be able to resume safely after a network failure without charging, creating, or notifying twice. These details are what turn a compelling agent demo into an operable workflow.