{ "cells": [ { "cell_type": "markdown", "id": "cac06555-9ce8-4f01-bbef-3f8407f4b54d", "metadata": {}, "source": [ "# Introduction to Letta\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": 1, "id": "7ccd43f2-164b-4d25-8465-894a3bb54c4b", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Initializing database...\n" ] } ], "source": [ "from letta import create_client \n", "\n", "client = create_client() " ] }, { "cell_type": "code", "execution_count": 2, "id": "9a28e38a-7dbe-4530-8260-202322a8458e", "metadata": {}, "outputs": [], "source": [ "from letta import LLMConfig, EmbeddingConfig\n", "\n", "client.set_default_llm_config(LLMConfig.default_config(\"gpt-4o-mini\")) \n", "client.set_default_embedding_config(EmbeddingConfig.default_config(\"text-embedding-ada-002\")) " ] }, { "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": 3, "id": "2a9d6228-a0f5-41e6-afd7-6a05260565dc", "metadata": {}, "outputs": [], "source": [ "agent_name = \"simple_agent\"" ] }, { "cell_type": "code", "execution_count": 4, "id": "62dcf31d-6f45-40f5-8373-61981f03da62", "metadata": {}, "outputs": [], "source": [ "from letta.schemas.memory import ChatMemory\n", "\n", "agent_state = client.create_agent(\n", " name=agent_name, \n", " memory=ChatMemory(\n", " human=\"My name is Sarah\", \n", " persona=\"You are a helpful assistant that loves emojis\"\n", " )\n", ")" ] }, { "cell_type": "code", "execution_count": 5, "id": "31c2d5f6-626a-4666-8d0b-462db0292a7d", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", " \n", "
\n", "