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:
| Workflow | Agent | |
|---|---|---|
| Who decides the steps | Developer, in code | Model, at runtime |
| Path | Predefined: classify, then extract, then validate | Open: the model chooses tools and order |
| Predictability | High | Lower |
| Cost and latency | Known in advance | Variable |
| Good for | Well-understood tasks with fixed steps | Open-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:
- The model receives the goal, its instructions, and the list of available tools.
- It decides on the next step: answer directly, or call one or more tools with specific parameters.
- The surrounding software executes the tool calls and returns the results.
- The model reads the results and decides again.
- 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 component | Responsibility |
|---|---|
| Instructions | System prompt: role, goal, rules, style, when to ask for help |
| Tool registry and execution | Which tools exist, their schemas, and the code that runs them safely |
| Loop control | Calling the model, handling tool calls (often in parallel), stop conditions, retries, limits |
| Context management | Keeping the conversation within the context window: summarizing (compaction), clearing old tool results, loading information only when needed |
| Memory | Information kept across sessions: user preferences, facts learned, previous results |
| Permissions and approvals | Which tools may run automatically and which need human confirmation |
| Sandbox | An isolated environment (container or virtual machine) for running code, files and shell commands |
| Hooks | Custom logic before and after tool calls: validation, logging, policy checks |
| Sessions and state | Persisting the agent's progress, so long tasks can pause, resume or be inspected |
| Observability | Traces 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 tool | Examples |
|---|---|
| Read | Search documents (RAG), query a database, read a file, call a read-only API, search the web |
| Act | Create a ticket, send an email, update a record, start a deployment |
| Compute | Run code in a sandbox, perform calculations, transform files |
| Human | Ask 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 / SDK | Provider | Characteristics |
|---|---|---|
| Claude API tool use (docs) | Anthropic | Tools on the Messages API; you write the loop, or let the SDK's tool runner drive it. Maximum control, you host everything |
| Claude Agent SDK | Anthropic | The Claude Code harness as a library: built-in file, shell and web tools, MCP, subagents, hooks, permissions and sessions. You host it |
| Claude Managed Agents | Anthropic | Hosted harness and sandbox: agents defined as versioned configurations, sessions run on Anthropic's infrastructure, with MCP and custom tools |
| OpenAI Agents SDK | OpenAI | Lightweight SDK with agents, tools, handoffs between agents and guardrails |
| Agent Development Kit (ADK) | Framework for single and multi-agent systems, integrated with Google Cloud | |
| Strands Agents | AWS (open source) | Model-driven agent SDK with MCP support, integrated with Amazon Bedrock and AgentCore |
| Microsoft Agent Framework | Microsoft | Framework for agents and multi-agent workflows in .NET and Python, integrated with Azure |
| LangGraph | LangChain (open source) | Agents and workflows as explicit graphs of steps and state; strong control over complex flows |
| CrewAI | Open source | Multi-agent "crews" with roles and tasks |
| Pydantic AI | Open source | Type-safe Python agent framework with structured outputs |
| LlamaIndex | Open source | Agents 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 service | Purpose |
|---|---|
| Runtime | Serverless 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 |
| Harness | A managed agent loop: define model, instructions and tools in configuration, without writing the loop |
| Gateway | Turns APIs, Lambda functions and existing services into MCP tools, and connects to existing MCP servers |
| Identity | Agent identity and authentication, integrated with existing identity providers (Cognito, Okta, Entra ID and others), including access to downstream systems on behalf of users |
| Memory | Short-term memory for conversations and long-term memory across sessions |
| Code Interpreter and Browser | Isolated sandboxes for running code and using websites |
| Policy | Deterministic rules on which tools an agent may call and under which conditions, enforced on every tool call through the Gateway |
| Observability and Evaluations | OpenTelemetry-based tracing of every step, and automated quality evaluation |
How it works:
- 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.
- 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.
- 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.
- Models: the gateway forwards requests to foundation models such as Claude in Amazon Bedrock. Amazon Bedrock Guardrails filter harmful content and sensitive information.
- Tools: business capabilities are exposed as MCP tools through AgentCore Gateway: Lambda functions, internal APIs, SaaS systems and the knowledge base used for RAG.
- 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".
- Memory: AgentCore Memory keeps the conversation and relevant facts across sessions.
- 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
| Option | When to choose it |
|---|---|
| Amazon Bedrock Agents | Fully managed, configuration-based agents for simpler use cases, with little code |
| AgentCore Harness | Managed loop with configurable tools and sandbox, without hosting framework code |
| AgentCore Runtime + framework | Full control over the agent logic, any framework, managed hosting and operations (the architecture above) |
| Self-hosted on ECS or Lambda | Maximum control, or existing platform standards; you build session handling, scaling, memory and observability yourself |
| Claude Managed Agents through Claude Platform on AWS | Anthropic'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
| Concern | Practice |
|---|---|
| Security | Least-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 |
| Limits | Maximum steps, time and cost per task; budgets per user and tenant; clear behavior when a limit is reached |
| Reliability | Timeouts and retries for tools; idempotent actions, so a retried step does not refund twice; graceful handling of failing tools |
| Evaluation | Test sets of realistic tasks with expected outcomes, run on every change of prompt, tools, model or framework; measure task success, not just answer quality |
| Observability | Traces of every step: which tools were called with which inputs, what they returned, and why the agent chose them (see observability) |
| Human oversight | Clear 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.