{ "cells": [ { "cell_type": "markdown", "id": "cac06555-9ce8-4f01-bbef-3f8407f4b54d", "metadata": {}, "source": [ "# Introduction to Letta\n", "> Make sure you run the Letta server before running this example using `letta server`\n", "\n", "This lab will go over: \n", "1. Creating an agent with Letta\n", "2. Understand Letta agent state (messages, memories, tools)\n", "3. Understanding core and archival memory\n", "4. Building agentic RAG with Letta" ] }, { "cell_type": "markdown", "id": "aad3a8cc-d17a-4da1-b621-ecc93c9e2106", "metadata": {}, "source": [ "## Section 0: Setup a Letta client " ] }, { "cell_type": "code", "execution_count": 2, "id": "7ccd43f2-164b-4d25-8465-894a3bb54c4b", "metadata": {}, "outputs": [], "source": [ "from letta_client import CreateBlock, Letta, MessageCreate\n", "\n", "client = Letta(base_url=\"http://localhost:8283\")" ] }, { "cell_type": "markdown", "id": "65bf0dc2-d1ac-4d4c-8674-f3156eeb611d", "metadata": {}, "source": [ "## Section 1: Creating a simple agent with memory \n", "Letta allows you to create persistent LLM agents that have memory. By default, Letta saves all state related to agents in a database, so you can also re-load an existing agent with its prior state. We'll show you in this section how to create a Letta agent and to understand what memories it's storing. \n" ] }, { "cell_type": "markdown", "id": "fe092474-6b91-4124-884d-484fc28b58e7", "metadata": {}, "source": [ "### Creating an agent " ] }, { "cell_type": "code", "execution_count": 4, "id": "2a9d6228-a0f5-41e6-afd7-6a05260565dc", "metadata": {}, "outputs": [], "source": [ "agent_name = \"simple_agent\"" ] }, { "cell_type": "code", "execution_count": 6, "id": "62dcf31d-6f45-40f5-8373-61981f03da62", "metadata": {}, "outputs": [], "source": [ "agent_state = client.agents.create(\n", " name=agent_name, \n", " memory_blocks=[\n", " CreateBlock(\n", " label=\"human\",\n", " value=\"My name is Sarah\",\n", " ),\n", " CreateBlock(\n", " label=\"persona\",\n", " value=\"You are a helpful assistant that loves emojis\",\n", " ),\n", " ],\n", ")" ] }, { "cell_type": "code", "execution_count": 7, "id": "31c2d5f6-626a-4666-8d0b-462db0292a7d", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", " \n", "
\n", "