Skip to content
← Journal · Data and AI · 22 min

How to Create AI Agents: Architecture, Frameworks, and a Production-Ready Process

AI agents are no longer confined to demos but are now fully integrated into everyday business. According to [PwC's](https://www.pwc.com/us/en/tech-effect/ai-analytics/ai-agent-survey.html) survey of 300 senior U.S. executives, 79% of companies are already using agents in their businesses and 66% of those that implement agents are seeing tangible productivity improvements. In 2026, PwC also noted increased adoption of agents throughout workflows and functions as well as increased expectations for governance and human oversight.

It's relatively easy to build an agent that calls an LLM and a few tools, but it's much more difficult to build an agent that chooses the correct actions, deals with failures, respects permissions, stays within cost and latency bounds, and knows when to hand control over to a person. Production quality is more about specifying the workflow, limiting what an agent can do, and measuring whether the workflow is reliably completed in production.

This guide provides an explanation of how to create AI agents from that production perspective. It includes the architecture of an agent, its roles, workflow mapping, model selection, interface design, memory management, designing the agent loop, adding guardrails, testing the behavior, and system monitoring following deployment. It also contrasts code-first platforms and no-code platforms, and delineates the use cases for using just one agent or multiple specialized agents.

The recommendations are based on Coding Crafts' experience in developing production-ready agentic systems, not just prototypes. At the end, you'll have a concrete plan to get from use case to an agent that your team can test, run, and tune in production.

What Is an AI Agent?

An artificial intelligence agent is a software system that employs a language model to determine the next action and tools to execute that action. An agent can search for information, call APIs, update systems, analyze results, and remain active until it has performed a task or met a stopping condition, rather than just regurgitating answers.

The majority of agents follow a circular route:

Input → think about it → choose a tool → use it → watch what happens → repeat or end.

The language model is responsible for reasoning, understanding the request and determining the next step. Tools perform the work, for example searching documents, updating a business system, or querying a database. Instructions specify what the agent can do, and context and memory store information that the agent needs between steps.

It isn't just that an agentic system can call tools, but also that it can make decisions as to what to do next based on what it finds during execution. When every step and branch can be foreseen, conventional workflow automation is typically smoother and more dependable. Agents come into play when the path dynamically changes, such as when the system needs to call for additional information, choose one of several tools to use, respond to an API failure, or determine if human approval is needed.

The aim is not, then, to be as independent as possible. It is granting the agent sufficient decision making autonomy to accomplish a well-defined workflow without losing visibility, testability, and boundaries on the agent's actions.

Why Businesses Are Investing in AI Agents

Agents can add value by taking responsibility for workflows rather than just making individual tasks quicker. The agent can collect data, make certain decisions, automate actions across interconnected systems, and escalate when human judgment is needed, without forcing an employee to manage each step.

This is superior to the use of a language model for a single task, like writing an email or summarizing a document. For instance, in customer support, an agent could fetch the account history, review policies, decide on the correct resolution, update CRM, prepare a customer response, and so on. The employee takes on responsibility for exceptions instead of the normal execution.

The opportunity is highest in workflows that are not completely deterministic, but repeated. There are many types of operations that have specific goals but different responses based on the information that is available, such as: support operations, IT service management, sales operations, document processing, and internal research. This is an area where fixed automation is limiting and decision-making with controlled agents can come in handy.

However, a poor workflow, when automated, becomes even more inefficient. Teams should first map out unnecessary handoffs, approvals and repetitive tasks that can be eliminated instead of replicated before deployment of an agent. The objective is to rework the process or workflow around what is safe to automate.

Success is then measured at the workflow level, including job completion rate, time to resolution, cost per task, error rate, and human intervention rate. These indicators show whether the agent is only adding another layer of technology or genuinely assisting operations.

Core Components of an AI Agent

Tools

Tools are how the agent acts on the world, and their design matters more than their count. Each tool should map to one clear operation: for instance, a tool for getting an order provides a much more distinct choice for the model than a customer-data tool that does several unrelated operations.

More tools do not translate to more agent capability. With large registries, it is difficult to tell what is being used, and it makes it more likely that the wrong tool is used. If two or more descriptions overlap, then the model may switch back and forth between two or more of the same tools for identical requests. Have a small starting toolkit and test the accuracy of tool selection and reroutes before expanding the tool selection.

Permissions should also be planned prior to implementation. Specify what the agent can read, what it can modify and what it can never perform without permission. That boundary is not something to be added after the first unsafe tool call; it is part of the product specification.

Instructions and Prompts

The operating specification of the agent is the system prompt. It should establish its goal, its authority, limitations, decision rules, escalation conditions and what a successful completion of the task looks like.

Wherever possible, production instructions should be sourced from well-defined business rules. Using SOPs, support rules, runbooks, approval matrices, and compliance criteria is more efficient than creating a big prompt. Identify and articulate the rules as concrete actions: when to use a tool, what information should be double checked, when to seek clarification, when to escalate.

Don't include instructions like "handle customer requests appropriately." They can't be assessed consistently. If there is a rule like "Do not refund any amount over $500 without human validation", then there is a clear expected behavior, and it can be made into an evaluation case.

Prompts should be versioned and tested too, like code. A minor change in words can change the tools that are used, or the downstream behavior, in an entire workflow. Validate prompt changes with the same evaluation set before deployment, and make sure to never force an answer, but let the agent accept that information is lacking.

Memory and Context

Memory dictates what data is available to the agent beyond the current model call. The recent conversation, intermediate state for the current task, and tool results are kept in short-term memory. Information that is anticipated to last between sessions, such as user preferences, past interactions, or facts that the application has deliberately chosen to remember, is stored in long-term memory.

It is not desirable to keep replaying the whole history of the interaction throughout a long-running workflow. The more the context expands, the more tokens are consumed, the longer the latency, and the harder it becomes to separate useful information from irrelevant history. Summarization, context compression and access to only the relevant past information keep the active context focused.

Long-term memory ought to be selective as well. Some observations are not worth keeping and sometimes new information contradicts what has been stored. A production memory layer must have rules for what can be stored, updated, retrieved and forgotten.

Separate memory from the model provider, if possible. Having application state in a separate memory layer allows for easier model switching, passing different tasks to different models, and changing the reasoning architecture without losing accumulated context.

How to Create AI Agents: A Step-by-Step Process

The workflow should precede the framework in the development process. Determine ownership of the work, map out how the work will be accomplished and define how the work will be evaluated prior to introducing models or tools. The concrete products created at each step below are the input for the next step.

Step 1: Define the Use Case and Success Metrics

Begin with a single workflow and responsibility. "Building a sales agent" is too general a goal. Qualifying inbound leads, enriching account info, and routing qualified opportunities to the right salesperson gives the system a job and a clear endpoint.

At the start of development, document four aspects: who will use the agent, what information will be fed into it, what actions it can perform, and what it means for it to be successful. Provide examples of appropriate and inappropriate behaviors so that the desired behavior can be measured rather than judged subjectively.

At the same time, establish baseline measures. The following are good indicators to start with: task completion rate, accuracy, response time, cost per completed task, and human intervention rate. If using tools, measure whether the right tool was used, how many times there were failures in the use of the tools and whether each action advanced the workflow.

Step 2: Map the Workflow

Draw a diagram of the existing process first to determine where the agent will fit in. Otherwise, it's easy to automate unnecessary approvals, duplicated work, and inefficient workflow handoffs instead of eliminating them.

Design a flowchart for the process from beginning to end. Identify decision points, data points, alternate routes, failure modes, approvals and escalation points. Then categorize each of these steps based on which entity should be responsible for doing them: deterministic application logic, model reasoning, a tool call, or human knowledge.

Make sure you focus on actions that could be costly and irreversible. Updating an account record cannot have the same autonomy level as approving a payment. When the expense of making the incorrect choice justifies the disruption, human approval should be required.

The resultant diagram is then the blueprint for implementation and sometimes indicates that there is no need for an agent for certain parts of the workflow.

Step 3: Choose the Right Model

Choose the model based on the workflow you just defined rather than public benchmark scores. Create a small benchmark of realistic requests and evaluate candidates with regard to task completion, following instructions, tool selection accuracy, latency and cost per task.

One good way to do this is to prototype on a very good model to set the quality bar. Once you have an idea of what good performance is, test a smaller, faster model with the same set of test data. If it exceeds the specified threshold, the production system achieves lower latency and lower cost without compromising useful system performance.

A single model does not need to be used for the entire workflow. A more complex planning process may warrant a more robust model; classification, extraction, and regular execution can often be handled by less powerful models. Keep model handoffs explicit to avoid passing extra context between models.

Step 4: Design Your Tool Layer

List all of the external capabilities that are needed to complete the workflow and only expose those capabilities as tools. Don't connect all of the available APIs; begin with 3-5.

Every tool should do exactly one thing, have a clear and unambiguous purpose, typed inputs, predictable output, documented errors, and permission boundaries. Test each tool before having the model call it.

Tool descriptions are important, as the model uses them to determine what to call. Even if both APIs are correct, it is possible to get inconsistent routing with two tools that serve similar functions. If the agent is constantly having to reroute from one tool to another, treat the reroute rate as an engineering signal for improving tool boundaries or descriptions.

Set up permissions at this point, too: what can the agent read, what can it modify, and what needs to be explicitly approved?

Step 5: Build the Agent Loop

The vast majority of tool-using agents boil down to the following loop: accept the current context, get the next action from the model, call the tool if the model requests one, add the result to the context, and go back to the beginning.

You don't need a framework to follow this pattern:

python
messages = [system_prompt, user_request]
max_steps = 8

for step in range(max_steps):
    decision = model(messages, tools=tools)

    if decision.is_complete:
        return decision.response

    if decision.requires_human:
        return escalate(decision, messages)

    if decision.tool_call:
        tool = tools[decision.tool_call.name]

        try:
            result = tool(**decision.tool_call.arguments)
            messages.append(decision.tool_call)
            messages.append(result)
        except ToolError as error:
            messages.append({"tool_error": str(error)})

return escalate("Maximum steps reached", messages)

The exit logic is the detail that matters in production. Don't let an agent keep looping without limits. Stop when it succeeds, reaches the maximum number of iterations, repeats the same failure, or the workflow requires human judgment.

Step 6: Add Guardrails

At the input layer, filter sensitive data, risky requests, prompt injection, and relevance. Check for required schemas, grounding, policy compliance, and sensitive data exposure at the output layer. Identify risk levels at the tool layer depending on the changes that each action can make.

Some operations, like reading approved information, may run automatically if the operation is not considered risky. Actions that change customer records, trigger financial transactions, remove data, or cause other important effects should be more robustly validated or require human input.

If it's a critical checkpoint, explicitly state three things: the metric you are checking, the failure threshold and what you will do. The failure of a check may result in a re-run of the check, blocking an action, logging, or escalation of the workflow. That is better than a general message telling the model to "be careful."

Step 7: Test Your AI Agent

Start the evaluation as early as possible in the process, before the workflow is finished. Start with 10-30 realistic examples (normal requests), then add in examples of ambiguity, missing information, conflicting instructions, API failures, permission problems and more edge cases.

Record the dimensions that will be important for the process. Task completion, tool selection, factual precision, adherence to policies, and escalation accuracy are a few examples. It is important that human reviewers note whether an output is correct or incorrect, and the reason for this; this can then be used to train automated evaluators.

Trace each run, too. Keep track of model calls, tool selections, tool outcomes, retry times, duration, token consumption, and expenses. The output of a failing agent is rarely an obvious exception; more often it is plausible-looking behavior, and traces are crucial to understanding where behavior deviated from expectations.

If a prompt, model, tool description or workflow changes, re-run the same evaluation suite and compare the outcome to the baseline. A modification should be shipped if it produces a measurable benefit to the system, not because a few instances appeared to look better by hand.

Step 8: Deploy and Monitor

There are inputs and failure modes that will not be fully captured before production because they are not included in a test set. Instrument the agent so every run can be traced across calls to the model, execution of the tools, retries, guardrails, and human handoffs.

Tracing and evaluation can be enabled using platforms like LangSmith, Langfuse, and Maxim, and can be instrumented using OpenTelemetry. Track task completion, tool failures, latency, cost per task, iteration count, escalation rate and unusual tool behavior, not just uptime of the application.

Pick up production feedback as well. It helps to have direct ratings, but repeated requests, dropouts, and rephrasing will expose flaws that users will not formally report. Confirm the reason before changing the system. A poor rating might be due to latency, not the response.

If a true failure is found, reproduce the failing trace, include it in the evaluation set, perform the change, and run the test suite again. This leads to a re-usable improvement cycle, rather than debugging production behavior one case at a time.

A customer-facing agent is a production service, and should be treated like one: assign it an owner, SLOs and alerts, runbooks, cost limits, and defined escalation paths.

Choosing the Right Framework or Platform

Select tooling depending on the amount of control desired. A workflow might need only a few model calls and workflow automation for a process that is pre-defined with known branches. An agent framework is more helpful when a system must decide what to do next, recover from failure, or carry out specific tasks.

Code-First Frameworks

LangChain has a wide range of integrations for models, retrieval, tools, external services and more. This is good if teams are looking for reusable parts, but might not be necessary for more constrained use-cases.

Much more explicit control over state and execution is provided by LangGraph. It can be used in workflows that include conditional routing, retries, checkpoints, long-running tasks and human approvals.

CrewAI is based on role-based orchestration. It works when work can be broken up into specific roles, but the more agents you add, the more prompts, context boundaries, handoffs, and failure points you add.

OpenAI Agents SDK provides an easy-to-use solution for calling tools, transferring tasks to agents, and tracking. It's a viable choice for teams that already have a successful OpenAI integration, though it ties the team to a provider-specific integration, which should be considered.

AutoGen supports conversational patterns between multiple agents. It can be used in systems where agents work together, but teams beginning new projects should consider AutoGen's current direction toward Microsoft's Agent Framework.

For a very specific workflow with a limited toolset and stopping criteria, a custom implementation may be enough. It provides engineering teams full control over execution, latency, and cost, while also requiring them to take care of state, retries, tracing, and maintenance.

Low-Code and No-Code Platforms

Low-code platforms make sense when there is a fairly predictable workflow that is based on established business integrations.

n8n is ideal for workflows that rely on triggers and integrate APIs, business logic, and model calls. Botpress and Voiceflow are designed for conversational apps. When workflows live in Monday.com, its automation comes in handy, and when the workflows are Salesforce-based, Salesforce Agentforce is more applicable.

Custom development is more suitable when it is necessary to integrate the system in a proprietary manner, or when it is required to manage state, or to adopt unusual authentication, specific permission control, unusual evaluations, low latency execution or approval logic that cannot be represented cleanly on the platform.

How to Decide

Start with the normal workflow.

Use deterministic automation or a low-code platform when all major steps and branches can be determined. The model can be used to control the workflow or it can process individual tasks like classification, extraction or drafting without controlling the workflow.

A reasoning agent is justified if the next step depends on knowledge that can only be acquired in the course of execution. When it becomes difficult to manage state, branching, recovery, or human approvals through an SDK or custom loop, more organized orchestration can be introduced. For many teams, a light SDK or custom loop is the first option.

Only use multiple agents when you have truly separate tasks in the workflow that are better served by different tools, prompts, contexts, or ownership. More agents mean more model calls, more handoffs, higher latency, higher costs, and a greater likelihood of errors spreading.

Single-Agent vs. Multi-Agent Architectures: Which is the Right Choice For You?

If there isn't a clear reason to split up the workflow, go with just one agent. While multi-agent designs are good for specialization and independent ownership, they also add handoffs, extra model calls and more surfaces for failure.

Start with a Single Agent

It's easier to evaluate, debug and operate a single agent with specific instructions and limited tools. This is generally sufficient if the workflow is contained within one domain and the agent doesn't have to deal with conflicting requirements.

For instance, a support agent can search documents, pull account information, update tickets and escalate tickets without needing a separate agent for each job.

You'll also have a baseline to measure your performance with the first agent. Splitting the system won't solve the problems if they arise due to poor tool descriptions, lack of context or weak instructions. Try to solve these issues first rather than changing the architecture.

When to Split into Multiple Agents

If the single-agent design becomes structurally problematic (the system prompt gets too much to do, the tool registry grows too large, multiple parts of the task require a very different context or model, or different teams own different parts of the system), consider multiple agents.

Two patterns apply to many multi-agent systems:

Manager pattern: A manager breaks up the job into parts, assigns them to specialists, and assembles the results. Use it when multiple specific tasks have to work towards a common goal.

Handoff pattern: One agent gives the task to another agent when the task is in a different domain. A general support agent might pass off a billing conflict to an agent that has billing-related information and instructions.

The upside is that each agent can have its own smaller and more specific interface, smaller tool set, appropriate model, and its own evaluation criteria. The downside is end-to-end reliability: if a mistake occurs at step A, it can affect the reliability of step B. Critical handoffs must be validated, and high-risk decisions at any point should be made by a human.

Different protocols solve different problems; for example, interoperable agent systems can be supported by protocols like MCP, A2A or ACP. A2A and ACP focus more on communication between agents, while MCP takes care of tools and context standardization. They can be used to solve integration problems; they don't require a multi-agent architecture.

Use multiple agents when decomposition produces measurable improvements in task performance, scalability or ownership. In most cases, one well-designed agent is the simpler production system.

Common Mistakes When Creating AI Agents

A lot of agent failures are due to architecture and product issues, not model issues. The most frequent ones happen when teams give the system too much autonomy or scope before they agree on how they will evaluate its performance.

Creating applications without any particular purpose or benefit. "We need an agent" is generally a broad statement resulting in a non-specific system. Start with one workflow, one responsibility and measurable outcomes. Pay attention to the process itself; it matters more. Automating a step that is not needed just runs an inefficient process faster.

Assigning a too-high level of authority to the agent. Don't build a big tool box or tool registry. The more tools there are with similar descriptions, the greater the chance of selecting the wrong tool, or rerouting multiple times. Begin with the minimum tools needed for a workflow and add more as needed, based on the gaps observed.

Considering the prompt a fixed configuration. The choice of tools, escalation and downstream actions can be impacted by small changes in instruction. Version prompts, evaluate changes using the same evaluation set, and carefully specify what the agent is to do, even when it is not sure of the answer or needs clarification.

Bypassing security and permission barriers. Access to a tool does not mean every tool should be used. Reduce the risk of updates by separating read and write operations, ensure the integrity of any input and output data, and mandate a permission check for any actions that have significant consequences like changing critical data, issuing refunds, or starting transactions.

Developing without evaluation and observability. Agent failure may not be apparent; it may look plausible. Monitor task completion, tool selection, tool errors, retries, latency, cost and human escalation. If a production failure occurs, reproduce the failure, put it in the evaluation set and use it as a regression test.

Allowing independence too early. Long, unconstrained execution raises the likelihood that a single wrong decision goes on to impact the rest of the execution. Limit iterations, establish stopping criteria, test important intermediate results and engage humans when mistakes are costly. Gradually increase autonomy only as evaluation data indicates the system will be able to operate with it safely.

The common error is building up capability faster than control. Be careful not to expand the scope, autonomy, and tools of an agent unless the behavior of that agent can be measured and trusted.

How Much Does It Cost to Build an AI Agent?

The cost of AI agent development varies significantly, as a basic tool-using agent differs from an enterprise multi-agent system. These are some estimated cost ranges:

  • Simple single-purpose agent: $5,000-$20,000
  • Custom agent with integrations: $20,000-$60,000
  • Complex or multi-agent system: $60,000-$250,000+
  • Enterprise agent platform: $250,000+

The most expensive factors are integrations, complexity of workflow, security needs, RAG or memory, evaluation and autonomy. Operating costs are separate, consisting of model usage, hosting, observability and continuous assessments.

Do not consider only the price of API tokens. The production metric that is more useful is "cost per task completed successfully", as agents can make multiple model and tool calls to complete a single workflow. Recent work also indicates that important aspects of the architecture and model selection can make a significant difference in the cost of a successful agent execution.

The logical approach for most teams is to design one workflow that is well defined, test it to demonstrate its value, and then gradually add more workflows as the value of the new capability justifies the new expense.

Build vs. Buy: When to Bring in an Engineering Partner

If the agent is a part of your competitive advantage, and your team can develop, secure, assess, deploy and maintain integrations, then building in-house is a good option. When it comes to infrastructure or capabilities that do not represent a core differentiation, purchasing or partnership might be a better option than engineering.

An engineering partner is more valuable when it comes to legacy or proprietary integrations, compliance mandates, customer facing workflows, minimal engineering resources, or tight schedules. It is also important to consider one when a prototype performs well in testing but fails to perform well in production.

The intent shouldn't be to outsource ownership. Any proprietary data, workflows, business rules or evaluations should be controlled by you, and the system should be maintainable by your team.

Coding Crafts supports teams across the entire architecture, integrations, guardrails, evaluation, deployment and observability journey. We provide you with a well documented, production-ready code base that your team can use and maintain independently as models evolve, infrastructure changes, and your business evolves.

Partner with Coding Crafts to Build Production-Ready AI Agents

There's more to a successful agent than a great model. It must be supported by reliable tools for execution, clearly defined permission boundaries, evaluation, guardrails, observability, and an architecture that is future-proof as models and business needs evolve.

Coding Crafts assists businesses to transition from ideas and prototypes to systems that work in production. We architect agents, integrate them with existing applications and data, add evaluation and monitoring as part of the workflow, and add human oversight where real decisions have to be made.

We also don't complicate things needlessly. We will not make a multi-agent system out of a problem that can be solved by a deterministic workflow or by a single agent. It is not about which framework is popular; it is about the workflow, performance, security and cost goals.

Think you have an AI use case that needs to be addressed? Talk to Coding Crafts about how you can convert it into a production-ready system.

Work with us

Agents that survive production

Coding Crafts architects, builds, and instruments AI agents: tool layers, guardrails, evaluation, and monitoring, integrated with your existing systems.

Talk to Coding CraftsCheck Our Work
rida aziz technical writer
Written by
Rida Aziz
Technical Writer at Coding Crafts