๐—ง๐—ต๐—ฒ ๐— ๐—ฒ๐˜€๐˜€๐—ฎ๐—ด๐—ฒ๐˜€ ๐—”๐—ฟ๐—ฟ๐—ฎ๐˜† ๐—–๐—ผ๐˜€๐˜ ๐—ง๐—ฟ๐—ฎ๐—ฝ

Part 3 of Building TinyAgent. AI agents have no memory. You create memory with a messages array. You send the full history every time you call the API.

This costs you money. Turn 1: You send 1 message. Turn 10: You send 19 messages. Turn 30: You send 59 messages.

The cost is not a straight line. It curves up. You pay for every old message on every new turn.

The first 10 turns feel free. This is a trap. The bill jumps at turn 20.

Three ways to fix this:

Anthropic has a trick called caching. It stores the prompt state. You pay 10% for cached input. This makes long system prompts cheap.

Stop guessing. Measure your turns. Pick the best strategy for your users.

Next: We teach the agent to run functions.

Source: https://dev.to/jasmin/the-messages-array-in-4-gifs-1k1j