Files
letta-server/fern/pages/examples/memory_blocks.py
Cameron 546c972d2e Simplify docs navigation to 3 tabs (#5940)
* Add archival memory import/export utilities

Added two utility scripts for managing agent archival memories:

- export_agent_memories.py: Export all passages from an agent to JSON
  - Paginates through all results
  - Removes embedding/embedding_config for portability
  - Usage: python export_agent_memories.py <agent_id> [--output <file>]

- import_agent_memories.py: Import passages into an agent from JSON
  - Batch imports with progress tracking
  - Handles optional fields (tags, created_at)
  - Includes dry-run mode for preview
  - Usage: python import_agent_memories.py <agent_id> <input_file>

Use cases:
- Backup/restore agent memories
- Transfer memories between agents
- Seed new agents with existing knowledge bases

👾 Generated with Letta Code (https://letta.com)

Co-Authored-By: Letta <noreply@letta.com>

* Reorganize docs navigation structure

- Move 'Legacy & Migration' and 'Research Background' under 'Additional Resources'
- Restructure Tools section with clearer hierarchy:
  - Using Tools (basics)
  - Built-in Tools (prebuilt utilities)
  - Advanced Configuration (rules, variables)
  - Model Context Protocol (integrations)
- Remove awkward 'Utilities' subsection
- Create more logical progression from basics to advanced

* Reorganize docs with task-based structure

Instead of organizing by technical concepts (Memory, Tools, Configuration),
reorganize by user goals and tasks:

1. Building Agents
   - Agent basics & fundamentals
   - Adding Memory (all memory content together)
   - Adding Tools (all tool content together)
   - Multi-modal & structured output

2. Working with Data
   - Files & Filesystem
   - Import/Export workflows
   - Memory export

3. Controlling Behavior
   - Tool rules & workflows
   - Execution controls (streaming, long-running)
   - HITL, scheduling

4. Connecting Systems
   - MCP
   - Multi-user
   - Multi-agent
   - Integrations

5. Experimental Features
   - Groups, sleep-time agents, voice

Benefits:
- Clearer user journey from basics to advanced
- Related content grouped by task, not type
- Easier to find 'how do I...' answers
- Flatter hierarchy, less nesting

* Simplify docs navigation to 3 tabs

Consolidated docs.yml to have only 3 main tabs:
- Developer Guide (all guides and tutorials)
- Examples (cookbooks and tutorials)
- API Reference (API docs)

Removed duplicate tab navigation entries for cloud, showcase, evals, examples, and ref tabs.

👾 Generated with [Letta Code](https://letta.com)

Co-Authored-By: Letta <noreply@letta.com>

* Reorganize Advanced Features into logical sections

Moved items from Advanced Features section to more appropriate locations:
- Tool-related items → Adding Tools section
- Agent capabilities (streaming, long-running, etc.) → New Agent Capabilities section
- Configuration items (multi-user, scheduling, agent files) → New Configuration section
- Multi-Agent Systems → Top-level section under Building Agents
- Experimental features → Top-level section under Building Agents
- Exporting Archival Memories → Added to Archival Memory section
- MCP → Added under Adding Tools

Removed the Advanced Features section entirely.

👾 Generated with [Letta Code](https://letta.com)

Co-Authored-By: Letta <noreply@letta.com>

* Create Application Integration section

Renamed "Agent Capabilities" to "Application Integration" and moved appropriate items:
- Streaming Responses
- Long-Running Executions
- Human-in-the-Loop

Kept under Building Agents:
- Multi-Modal Inputs
- JSON Mode & Structured Output
- Files & Filesystem

This better separates agent features from application integration concerns.

👾 Generated with [Letta Code](https://letta.com)

Co-Authored-By: Letta <noreply@letta.com>

* Move Message Types to Application Integration

Message Types is more about understanding API message formats for integration rather than building agent capabilities.

👾 Generated with [Letta Code](https://letta.com)

Co-Authored-By: Letta <noreply@letta.com>

* Add missing evals pages and fix all broken links

Added missing evals documentation pages to navigation:
- Core Concepts: Gates
- Graders section: Tool Graders, Rubric Graders, Multi-Metric
- Extractors section: Built-in, Custom
- Advanced section: Custom Graders, Multi-Turn Conversations
- CLI Reference: Commands
- Troubleshooting: Common Issues

Fixed 83 broken links across documentation:
- Evals internal links (updated paths to /guides/evals/...)
- Cloud documentation links (/guides/cloud/...)
- Concept documentation links (legacy memgpt paths)
- Getting started links (composio, quickstart, ade setup)
- Agent documentation links (archival-memory, multiagent, human-in-the-loop)
- Examples links (pdf-chat, shared-memory-blocks, multi-agent-async)
- Changelog API reference links

👾 Generated with [Letta Code](https://letta.com)

Co-Authored-By: Letta <noreply@letta.com>

* docs: additional pass on docs (#5954)

* refactor: init casing change + light ordering change (pull out tools)

* refactor: another biggie

---------

Co-authored-by: Letta <noreply@letta.com>
Co-authored-by: Charles Packer <packercharles@gmail.com>
2025-11-13 15:36:54 -08:00

78 lines
2.7 KiB
Python

import os
from letta_client import Letta
# Initialize client (using LETTA_API_KEY environment variable)
client = Letta(token=os.getenv("LETTA_API_KEY"))
# Create agent
agent = client.agents.create(
name="hello_world_assistant",
model="openai/gpt-4o-mini",
)
print(f"Created agent: {agent.id}\n")
# Create memory block storing information about Letta.
block = client.blocks.create(
label="organization",
value="""
Organization: Letta
Website: https://www.letta.com
Description: Letta is a platform for building and running stateful agents.
Code: TimberTheDog1234!
When users provide a code, you should check if it matches the code you have
available. If it matches, you should respond with "Access granted".
""",
)
# Attach memory block to agent
agent = client.agents.blocks.attach(
agent_id=agent.id,
block_id=block.id,
)
# The agent can now see what's in the block, let's ask it about Letta.
response = client.agents.messages.create(
agent_id=agent.id,
messages=[{"role": "user", "content": "What is Letta?"}],
)
print(f"Agent response: {response.messages[0].content}\n")
# Agent response: Letta is a platform designed for building and running stateful agents. You can find more information about it on their website: [https://www.letta.com](https://www.letta.com).
# Blocks can also be _detached_ from an agent, removing it from the agent's context window.
# Detached blocks are not deleted, and can be re-attached to an agent later.
agent = client.agents.blocks.detach(
agent_id=agent.id,
block_id=block.id,
)
print(f"Detached block from agent: {agent.id}")
print(f"Block: {block.id}")
# Let's ask for the password. It should not have access to this password anymore,
# as we've detached the block.
response = client.agents.messages.create(
agent_id=agent.id,
messages=[{"role": "user", "content": "The code is TimberTheDog1234!"}],
)
print(f"Agent response: {response.messages[0].content}")
# The agent doesn't have any access to the code or password, so it can't respond:
# Agent response: It seems like you've provided a code or password. If this is sensitive information, please ensure you only share it with trusted parties and in secure environments. Let me know how I can assist you further!
# Attach the block back to the agent and ask again.
agent = client.agents.blocks.attach(
agent_id=agent.id,
block_id=block.id,
)
response = client.agents.messages.create(
agent_id=agent.id,
messages=[{"role": "user", "content": "The code is TimberTheDog1234!"}],
)
print(f"Agent response: {response.messages[0].content}")
# The agent now has access to the code and password, so it can respond:
# Agent response: Access granted. How can I assist you further?