Skip to main content

Agents

RAG gives a model the right information to answer a question. An agent goes further: it pursues a goal over several steps, deciding by itself which information to look up and which actions to take, until the goal is reached.

An agent is an LLM that uses tools in a loop. Given a task such as "find out why this customer was charged twice and prepare a refund", it might search the billing system, read the payment history, check the refund policy, compare the two charges, and draft the refund for approval, choosing each step based on what it learned in the previous one.

Workflows and agents​

Not every multi-step LLM application needs to be an agent. Anthropic's article Building effective agents makes a useful distinction:

WorkflowAgent
Who decides the stepsDeveloper, in codeModel, at runtime
PathPredefined: classify, then extract, then validateOpen: the model chooses tools and order
PredictabilityHighLower
Cost and latencyKnown in advanceVariable
Good forWell-understood tasks with fixed stepsOpen-ended tasks that are hard to specify in advance

Use an agent when the task is complex (many steps, hard to predict), valuable enough to justify higher cost and latency, and when errors can be caught, through tests, review or approval before consequential actions. Otherwise, a workflow or a single LLM call is simpler, cheaper and easier to test.

The agentic loop​

At the core of every agent is the same loop:

  1. The model receives the goal, its instructions, and the list of available tools.
  2. It decides on the next step: answer directly, or call one or more tools with specific parameters.
  3. The surrounding software executes the tool calls and returns the results.
  4. The model reads the results and decides again.
  5. The loop ends when the model considers the task done, or when a limit is reached (steps, time, tokens, cost), or when a human must approve the next action.

The model itself never executes anything. It only proposes tool calls; the software around it decides whether and how to run them. That software is the harness.

The harness​

The harness is everything around the model that turns it into an agent: it runs the loop, executes tools, manages context and enforces rules. In practice, when people say "the agent", they usually mean the model plus its harness, and the harness is the part you build, configure and operate. Claude Code, for example, is a harness around Claude models.

Harness componentResponsibility
InstructionsSystem prompt: role, goal, rules, style, when to ask for help
Tool registry and executionWhich tools exist, their schemas, and the code that runs them safely
Loop controlCalling the model, handling tool calls (often in parallel), stop conditions, retries, limits
Context managementKeeping the conversation within the context window: summarizing (compaction), clearing old tool results, loading information only when needed
MemoryInformation kept across sessions: user preferences, facts learned, previous results
Permissions and approvalsWhich tools may run automatically and which need human confirmation
SandboxAn isolated environment (container or virtual machine) for running code, files and shell commands
HooksCustom logic before and after tool calls: validation, logging, policy checks
Sessions and statePersisting the agent's progress, so long tasks can pause, resume or be inspected
ObservabilityTraces of every model call and tool call, with tokens, latency and cost

Agent quality depends as much on the harness as on the model: good tools, focused context and clear stop rules often matter more than switching to a stronger model.

Tools​

A tool is a function the agent can call. It is described to the model by:

  • a name, such as get_order_status
  • a description explaining what it does and when to use it; this is effectively a prompt, and its quality strongly affects how well the agent uses the tool
  • an input schema (JSON Schema) defining the parameters
{
"name": "get_order_status",
"description": "Returns the current status, items and shipping details of a customer order. Use when the user asks about an order or delivery.",
"input_schema": {
"type": "object",
"properties": {
"order_id": { "type": "string", "description": "Order number, e.g. ORD-12345" }
},
"required": ["order_id"]
}
}
Kind of toolExamples
ReadSearch documents (RAG), query a database, read a file, call a read-only API, search the web
ActCreate a ticket, send an email, update a record, start a deployment
ComputeRun code in a sandbox, perform calculations, transform files
HumanAsk the user a question, request approval

Good tool design:

  • Fewer, well-designed tools beat many overlapping ones. Design tools around tasks ("find customer by email"), not around raw API endpoints.
  • Clear errors. Return messages the model can act on ("Order not found. Check the format ORD-12345"), not stack traces.
  • Concise results. Return what the model needs, not entire API responses that fill the context.
  • Safe by design. Read-only where possible; consequential actions behind approval; the agent acts with the user's permissions, not a powerful technical account (see identity and access management).

See also the tool use documentation for how tools are defined and called with Claude.

Tools for business systems are increasingly provided through the Model Context Protocol (MCP): a system exposes its capabilities once, as an MCP server, and any MCP-compatible agent can use them.

Frameworks and SDKs​

Agents can be built from scratch on a model API, but most teams use an SDK or framework that provides the harness.

Framework / SDKProviderCharacteristics
Claude API tool use (docs)AnthropicTools on the Messages API; you write the loop, or let the SDK's tool runner drive it. Maximum control, you host everything
Claude Agent SDKAnthropicThe Claude Code harness as a library: built-in file, shell and web tools, MCP, subagents, hooks, permissions and sessions. You host it
Claude Managed AgentsAnthropicHosted harness and sandbox: agents defined as versioned configurations, sessions run on Anthropic's infrastructure, with MCP and custom tools
OpenAI Agents SDKOpenAILightweight SDK with agents, tools, handoffs between agents and guardrails
Agent Development Kit (ADK)GoogleFramework for single and multi-agent systems, integrated with Google Cloud
Strands AgentsAWS (open source)Model-driven agent SDK with MCP support, integrated with Amazon Bedrock and AgentCore
Microsoft Agent FrameworkMicrosoftFramework for agents and multi-agent workflows in .NET and Python, integrated with Azure
LangGraphLangChain (open source)Agents and workflows as explicit graphs of steps and state; strong control over complex flows
CrewAIOpen sourceMulti-agent "crews" with roles and tasks
Pydantic AIOpen sourceType-safe Python agent framework with structured outputs
LlamaIndexOpen sourceAgents with a strong focus on retrieval and document data

How to choose:

  • Provider SDKs (Claude Agent SDK, OpenAI Agents SDK, ADK) get new model features first and are tuned for their models.
  • Model-neutral frameworks (LangGraph, CrewAI, Strands, Pydantic AI) make it easier to switch or mix model providers.
  • Hosted harnesses (Claude Managed Agents, AgentCore Harness, Amazon Bedrock Agents) remove the need to run the loop and sandbox yourself, in exchange for less control.
  • Whatever the choice, keep tools behind MCP or clean interfaces, so they can be reused when the framework changes.

Reference architecture: deploying an agent on AWS​

The following example deploys a customer service agent on AWS, using Amazon Bedrock for models and Amazon Bedrock AgentCore for running and operating the agent.

AgentCore is a set of modular services that work with any framework and model. The main ones, according to the AgentCore documentation:

AgentCore servicePurpose
RuntimeServerless hosting for agents built with any framework (Strands, LangGraph, CrewAI, OpenAI Agents SDK, Google ADK and others), with session isolation and support for long-running work
HarnessA managed agent loop: define model, instructions and tools in configuration, without writing the loop
GatewayTurns APIs, Lambda functions and existing services into MCP tools, and connects to existing MCP servers
IdentityAgent identity and authentication, integrated with existing identity providers (Cognito, Okta, Entra ID and others), including access to downstream systems on behalf of users
MemoryShort-term memory for conversations and long-term memory across sessions
Code Interpreter and BrowserIsolated sandboxes for running code and using websites
PolicyDeterministic rules on which tools an agent may call and under which conditions, enforced on every tool call through the Gateway
Observability and EvaluationsOpenTelemetry-based tracing of every step, and automated quality evaluation

How it works:

  1. Entry: users reach the agent through an application and Amazon API Gateway (the entry point for callers of the agent, not for model traffic), authenticated by Amazon Cognito or the corporate identity provider. Background agents are triggered by Amazon EventBridge schedules or events.
  2. Agent runtime: the agent code, built with a framework such as Strands Agents, LangGraph or the Claude Agent SDK, runs in AgentCore Runtime, isolated per session. Simple agents can use AgentCore Harness instead and skip the code.
  3. Model gateway: the agent does not call models directly, but through a LiteLLM gateway, self-hosted as a container, for example on Amazon ECS. It offers one OpenAI-compatible endpoint for all models, per-team virtual keys with budgets and rate limits, routing and fallbacks between models and regions, and central logging of usage and cost. This is the AI gateway described in AI transformation, shared by all agents and AI applications.
  4. Models: the gateway forwards requests to foundation models such as Claude in Amazon Bedrock. Amazon Bedrock Guardrails filter harmful content and sensitive information.
  5. Tools: business capabilities are exposed as MCP tools through AgentCore Gateway: Lambda functions, internal APIs, SaaS systems and the knowledge base used for RAG.
  6. Identity and policy: AgentCore Identity lets the agent call downstream systems on behalf of the signed-in user, with that user's permissions; Policy checks every tool call against rules, for example "refunds above 500 EUR require human approval".
  7. Memory: AgentCore Memory keeps the conversation and relevant facts across sessions.
  8. Operations: every model and tool call is traced in AgentCore Observability and Amazon CloudWatch; Evaluations measure quality continuously. Secrets are stored in AWS Secrets Manager.

Alternatives on AWS​

OptionWhen to choose it
Amazon Bedrock AgentsFully managed, configuration-based agents for simpler use cases, with little code
AgentCore HarnessManaged loop with configurable tools and sandbox, without hosting framework code
AgentCore Runtime + frameworkFull control over the agent logic, any framework, managed hosting and operations (the architecture above)
Self-hosted on ECS or LambdaMaximum control, or existing platform standards; you build session handling, scaling, memory and observability yourself
Claude Managed Agents through Claude Platform on AWSAnthropic's hosted harness and sandbox, with AWS authentication and billing. Note that it is operated by Anthropic and is separate from Amazon Bedrock, where Managed Agents is not available

The same building blocks exist on other clouds and platforms. The architectural questions stay the same: where the loop runs, how tools are exposed, how identity flows to downstream systems, and how every step is observed.

Running agents in production​

ConcernPractice
SecurityLeast-privilege tools; the agent acts with the user's permissions; approvals for consequential actions; all tool results and documents treated as untrusted (prompt injection); sandboxed code execution. See the OWASP Top 10 for LLM Applications
LimitsMaximum steps, time and cost per task; budgets per user and tenant; clear behavior when a limit is reached
ReliabilityTimeouts and retries for tools; idempotent actions, so a retried step does not refund twice; graceful handling of failing tools
EvaluationTest sets of realistic tasks with expected outcomes, run on every change of prompt, tools, model or framework; measure task success, not just answer quality
ObservabilityTraces of every step: which tools were called with which inputs, what they returned, and why the agent chose them (see observability)
Human oversightClear points where humans review, approve or take over; audit logs of what the agent did on whose behalf

Common pitfalls​

  • Agent for everything: using an agent where a fixed workflow or single call would be cheaper, faster and more predictable.
  • Too many tools: dozens of overlapping tools with vague descriptions confuse the model and fill its context.
  • Powerful service accounts: agents that can access everything, regardless of who asked.
  • No limits: loops that run, and spend, far longer than intended.
  • Testing by demo: a few impressive examples instead of systematic evaluations on realistic tasks.
  • Framework lock-in: business logic written deep inside framework-specific constructs instead of reusable tools and services.