Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

A compact AI agent can be understood as four connected parts: a language model, memory, tools, and an action loop. In a small TypeScript example, those parts appear as a model API call, conversation messages plus saved notes, tool definitions and handlers, and a loop that gives the model a bounded chance to act on tool results. This is a useful teaching framework—not a universal definition of an agent.

What the four-part model explains

The four labels describe a practical arrangement of responsibilities in an agent implementation. They help answer four questions: what decides the next step, what context is available, what operations can the system perform, and how does it continue or stop?

Component In the TypeScript example Responsibility
Brain client.messages.create Ask the language model to respond or request a tool.
Memory The messages array and notes.json Keep current conversation context and provide notes saved for later runs.
Tools Tool schemas, handlers, and the execute dispatcher Describe available operations and run the matching application code.
Action loop The bounded loop in runAgent Send model output, execute requested tools, return their results, and continue or stop.

These components work together, but the model’s tool request is not the tool execution. The application receives the request, dispatches it to a handler, and adds the handler’s result to the conversation. Anthropic describes agent implementations as language models using tools in response to environmental feedback; its discussion also distinguishes agents that dynamically direct process and tool use from workflows that follow predefined code paths (Anthropic, “Building effective agents”).

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How the example’s TypeScript parts fit together

The small illustrative implementation imports the Anthropic SDK and sets up state for the current run. It includes a messages array, an array for current-run expenses, and notes loaded from notes.json. It defines three tools—add_expense, get_total, and save_note—and uses execute to dispatch model-requested calls to their handlers.

Brain: request a model response

client.messages.create sends the conversation and tool definitions to the model. The model can return a normal response or indicate that it wants one of the available tools. This call is the model-facing decision point; it does not itself perform the application’s expense calculation or write a note.

Memory: keep the conversation and load lasting notes

The messages array holds the current interaction’s conversation state, including tool requests and the results returned by handlers. The example also loads notes.json so saved information can be supplied on a later run. The file is application-managed persistence: the model does not remember it automatically. Code must load the notes and include them in the context it sends.

Rank #2
TypeScript Programming Language - Software Engineer & Coder T-Shirt
  • TypeScript implements a superset of syntax for strictly typed development, facilitating deep static analysis and enhanced development environment integration. The compiler translates source into standard script formats, ensuring parity across any runtime.
  • TypeScript is ideal for front-end developers, full-stack engineers, and software architects who build large-scale web applications. It serves those looking to improve code excellence, reduce bugs through static checking, and maintain complex projects more.
  • Lightweight, Classic fit, Double-needle sleeve and bottom hem

This illustrates two different scopes of memory. In-context history is available within the current conversation state; persisted notes can be loaded across runs. A real application still needs to decide what is worth saving, how to update it, and how to handle file or data errors.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Tools: define an interface, then implement it in code

The tool definitions tell the model which operations exist and what inputs they accept. Their descriptions and schemas are part of the model-facing interface: vague descriptions or loose input requirements make it harder for the model to choose and call the right operation. The handlers contain the actual behavior, while execute matches a requested tool to its handler and returns the result.

  • add_expense adds an expense to the current run’s expense data.
  • get_total calculates a total from that data. Deterministic arithmetic belongs in code rather than in a language-model estimate.
  • save_note persists a note so application code can load it in a later run.

Return useful tool results and expose failures clearly. If a handler fails, concealing the error can leave the model without reliable feedback about what happened. Anthropic recommends thoughtful tool documentation and testing, while noting that its article’s tooling details may have changed since publication; it is best used here for durable design guidance rather than current product specifics.

Action loop: alternate between the model and tool results

runAgent repeatedly calls the model, checks whether it requested a tool, executes that tool, and appends the result to conversation state for the next model call. When the model returns a non-tool response, the function exits with a final answer. This repeated exchange is what lets the program respond to results from its environment rather than treating the first model response as the entire task.

The example caps the loop at six calls. That limit is an explicit stop condition: it prevents the agent from continuing indefinitely. If the cap is reached, the function returns a stop message instead of making another call. The exact cap is a design choice in this example, not a general rule for agents; an application should choose limits and failure behavior appropriate to its task.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

When this model is useful—and when a fixed workflow is better

Not every AI feature needs an agent loop. A single model call may be enough when the task is to generate or transform text without acting on external results. A fixed workflow can be a better fit when steps are known in advance and predictable execution matters. A dynamically directed agent is more useful when the next operation depends on what the model learns from tool results.

Approach What drives the next step Useful when
Single model call The application sends context and uses one response. The task needs a response but no multi-step interaction with tools.
Fixed workflow Predefined application code controls the sequence. Steps are known in advance and consistency or predictability is important.
Dynamic agent loop The model can choose tools and respond to their results. The path depends on intermediate information or actions.

Anthropic recommends starting with the simplest solution and adding complexity only when needed. Agentic systems can trade increased latency and cost for improved task performance, so flexibility is not automatically an advantage. Decide whether model-directed tool use is worth the additional execution paths and control work.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Practical design checks before expanding the example

  • Keep tool boundaries clear. Give each tool a specific purpose and a schema that constrains its inputs.
  • Keep deterministic work in application code. Calculations such as an expense total should be computed by a handler.
  • Make state explicit. Distinguish the current conversation from notes loaded across runs, and make clear which data is sent to the model.
  • Control the loop. Set a maximum iteration count and define what the application returns when that limit is reached.
  • Understand abstractions. SDKs and frameworks can simplify API calls, tool parsing, and chaining, but developers should understand the execution and failure behavior underneath them. Anthropic advises starting directly with APIs when practical and understanding a framework’s underlying behavior.

The four-part grouping is one author’s teaching model, not a formal standard. Anthropic notes that “agent” is used in multiple ways, including for systems with predefined workflows and systems where the model dynamically directs the process. OpenAI’s current Agents documentation likewise organizes implementation concerns across areas such as state, tools, orchestration, guardrails, observability, and evaluation. The four labels are a helpful entry point, not a complete architecture checklist.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.