Recommended Free Tools
A small AI agent can be understood through four parts: a language model, memory, tools, and an action loop. In the TypeScript example, those map to a model API call, conversation state and persisted notes, tool definitions and handlers, and a loop that gives the model a limited number of chances to act. This is a useful teaching framework—not a universal definition of an agent.
What are the four components?
- Brain: The language model interprets the request and chooses what to do next.
- Memory: The application keeps conversation history and can load saved information for later runs.
- Tools: Schemas describe available actions to the model; application code implements those actions.
- Action loop: The application repeatedly asks the model what to do, runs requested tools, and returns results until the model finishes or a limit is reached.
These labels group the example’s code for learning. Anthropic notes that “agent” has multiple definitions. It distinguishes workflows, which follow predefined code paths, from agents whose language models dynamically direct the process and tool use. See Anthropic’s guidance on building effective agents.
As an Amazon Associate I earn from qualifying purchases.
How does the TypeScript example map to the model?
The illustrative example described in Zahid Hasan Tonmoy’s DEV Community article maps each component to recognizable parts of a compact program. The mapping below explains the design; it is not a claim that the code was independently run or tested.
| Component | Example code | Role |
|---|---|---|
| Brain | client.messages.create |
Sends the conversation and tool definitions to the model and receives its response. |
| Memory | messages array and notes.json |
Keeps the current conversation in memory and loads notes saved for later runs. |
| Tools | Tool schemas, handlers, and execute |
Describes available actions and dispatches a requested action to its implementation. |
| Action loop | The bounded loop inside runAgent |
Repeats model calls and tool execution until completion or the iteration cap. |
Brain: the model call
client.messages.create is the point where the application sends the current conversation and tool descriptions to a language model. The model can return a normal response or request a tool. That request is an instruction to the application, not execution by itself.
#1 Best Overall
Memory: conversation plus saved notes
The messages array carries the history for the current run, so later model calls can use earlier turns and tool results. Separately, the example loads lasting notes from notes.json and supplies them to the model. The file does not become model memory on its own: application code is responsible for loading and including the notes, and for saving updates.
This distinction matters in practice. In-context history is temporary conversation state; persisted memory is information that the application deliberately stores and retrieves across runs.
Rank #2
- 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
Tools: definitions and application-owned handlers
The example defines add_expense, get_total, and save_note. Their schemas tell the model what each tool does and what inputs it accepts. Their handlers perform the actual work in application code, and execute dispatches a requested tool to its matching handler.
For example, after the model requests add_expense, the application must identify that tool, pass the supplied arguments to its handler, and append the result to the conversation. Only then can the model respond using that result. Tool descriptions and input schemas are part of the model-facing interface: make descriptions specific, validate inputs, and return useful errors. Keep deterministic work such as arithmetic in code rather than relying on the model to calculate it. Anthropic also recommends thoughtful tool documentation and testing.
Action loop: model, tool, feedback
Inside runAgent, a bounded loop makes another model call, checks whether the response requests a tool, executes that tool, and adds its result to the conversation. The model then sees the result on a subsequent call. If the response is not a tool request, the function exits with the final answer. The example caps this cycle at six calls and returns a stop message if the cap is reached.
This feedback cycle is what makes a tool-using system different from a single model response: the model can choose an action, receive the application’s result, and decide what to do next. The application—not the model—controls which handlers run and when the loop stops.
Why set a limit on the loop?
A maximum number of iterations is a concrete stop condition. Without one, a tool-using process could continue making calls when a tool fails, the model repeatedly requests an action, or the task does not converge. Anthropic recommends explicit stopping conditions, including maximum iterations, as a way to maintain control.
Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minuteWindows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallThe example’s six-call cap is a design choice for that illustration, not a universal setting. Real applications should choose limits that fit the task and define what users see when the limit is reached. Depending on the system, useful controls can include timeouts, allowed-tool checks, and clear handling of tool errors.
Best Value
When is a dynamic agent the right choice?
Not every task needs an agent loop. A fixed workflow can be a better fit when the steps are known in advance and consistency matters. A dynamic agent is useful when the next step depends on what the model learns from tool results, but that flexibility can add latency, cost, and more execution paths to control.
| Approach | What determines the next step | Typical trade-off |
|---|---|---|
| Fixed workflow | Predefined application code paths | More predictable and consistent; less flexible when the situation changes. |
| Dynamic agent | Model decisions informed by tool results | More adaptable; introduces additional calls and behavior to manage. |
| Single model call | One response without a repeated tool cycle | Simpler execution; cannot act on tool results through a multi-turn loop. |
Anthropic recommends starting with the simplest solution that meets the need: “We recommend finding the simplest solution possible, and only increasing complexity when needed.” If a fixed sequence can solve the task, adding an agent loop may make it harder to predict and debug without adding useful capability.
What should you inspect when building one?
- Tool contract: Check that each description explains when to use the tool and that its schema matches the handler’s expected inputs.
- Dispatch: Confirm that only recognized tool names reach handlers and that invalid arguments or tool failures become understandable results.
- State: Verify that messages include the relevant prior turns and tool outputs, and that persisted notes are explicitly loaded and saved by the application.
- Stopping behavior: Decide what happens on a final model response, a tool error, or the iteration cap.
- Visibility: Log model calls, tool requests, tool results, and stop reasons in a way that supports debugging without exposing sensitive data.
SDKs and frameworks can simplify API calls, tool parsing, and chaining, but abstractions do not remove the need to understand execution and failure behavior. Anthropic advises starting directly with APIs when practical and understanding what a framework does underneath. For a broader current implementation map, OpenAI’s Agents documentation organizes related topics including state, tools, orchestration, guardrails, observability, and evaluation.
Quick Recap
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.




