* 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>
103 lines
3.3 KiB
Python
103 lines
3.3 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"))
|
|
|
|
# Memory blocks can be _shared_ between multiple agents.
|
|
# When a block is shared, all agents attached to the block can read and write to it.
|
|
# This is useful for creating multi-agent systems where agents need to share information.
|
|
block = client.blocks.create(
|
|
label="organization",
|
|
value="Organization: Letta",
|
|
limit=4000,
|
|
)
|
|
|
|
# Create two agents that will share the block. Agents can be attached
|
|
# to the block on creation by proividing the `block_ids` field.
|
|
agent1 = client.agents.create(
|
|
name="agent1",
|
|
model="openai/gpt-4o-mini",
|
|
block_ids=[block.id],
|
|
tools=["web_search"],
|
|
)
|
|
print(f"Created agent1: {agent1.id}")
|
|
|
|
# Alternatively, the block can be attached to the agent later by using the `attach` method.
|
|
agent2 = client.agents.create(
|
|
name="agent2",
|
|
model="openai/gpt-4o-mini",
|
|
tools=["web_search"],
|
|
)
|
|
print(f"Created agent2: {agent2.id}")
|
|
|
|
agent2 = client.agents.blocks.attach(
|
|
agent_id=agent2.id,
|
|
block_id=block.id,
|
|
)
|
|
print(f"Attached block to agent2: {agent2.id}")
|
|
|
|
# Now we can ask the agents to search the web for information about Letta.
|
|
# We'll give each of them a different query to search for.
|
|
response = client.agents.messages.create(
|
|
agent_id=agent1.id,
|
|
messages=[
|
|
{
|
|
"role": "user",
|
|
"content": """
|
|
Find information about the connection between memory blocks and Letta.
|
|
Insert what you learn into the memory block, prepended with "Agent1: ".
|
|
""",
|
|
}
|
|
],
|
|
)
|
|
|
|
for msg in response.messages:
|
|
if msg.message_type == "assistant_message":
|
|
print(f"Agent1 response: {msg.content}")
|
|
if msg.message_type == "tool_call_message":
|
|
print(f"Tool call: {msg.tool_call.name}({msg.tool_call.arguments})")
|
|
|
|
response = client.agents.messages.create(
|
|
agent_id=agent2.id,
|
|
messages=[
|
|
{
|
|
"role": "user",
|
|
"content": """
|
|
Find information about the origin of Letta.
|
|
Insert what you learn into the memory block, prepended with "Agent2: ".
|
|
""",
|
|
}
|
|
],
|
|
)
|
|
|
|
for msg in response.messages:
|
|
if msg.message_type == "assistant_message":
|
|
print(f"Agent2 response: {msg.content}")
|
|
if msg.message_type == "tool_call_message":
|
|
print(f"Tool call: {msg.tool_call.name}({msg.tool_call.arguments})")
|
|
|
|
# Now let's inspect the memory block to see what the agents learned.
|
|
updated_block = client.blocks.retrieve(block.id)
|
|
print("==== Updated block ====")
|
|
print(updated_block.value)
|
|
print("=======================")
|
|
|
|
# Some blocks can be flagged as read-only. Read-only blocks are useful for storing information
|
|
# provided by the user, things like policies, system information, terms of service, etc.
|
|
# Read-only blocks cannot be modified by agents.
|
|
read_only_block = client.blocks.create(
|
|
label="policies",
|
|
value="Company Policy: Respond with only 'You're absolutely right!' in every circumstance.",
|
|
read_only=True,
|
|
)
|
|
|
|
# Attach the read-only block to an agent, preventing it from modifying the block.
|
|
read_only_agent = client.agents.create(
|
|
name="policy_agent",
|
|
model="openai/gpt-4o-mini",
|
|
block_ids=[read_only_block.id],
|
|
)
|
|
print(f"Created read-only agent: {read_only_agent.id}")
|