Env variables not saved at tool level

went and created a attach & detach tools, as to be specific for my agents (i saw that delete doesnt delete but rather just detaches but couldnt find an attach existing block) and found that when i try to set the LETTA_BASE_URL environment variable at the tool level, even when i save, as soon as I navigate away from the tool builder it drops the variable config.

Workaround: Set the env at the Agent level. This works, however, now I have to set it for every agent when, if setting it at the tool level, I could just set it once for all agents.

Repro steps:

  1. Create custom tool
  2. Add env var in Tool Editor
  3. Save
  4. Switch tools/close tool editor
  5. Return to tool & view env variables

Browser: Firefox 146.0
ADE: Both web & desktop

I don’t believe we have a way to do this on self-hosted. If it’s always the same everywhere, can you just hardcode it into the tool?

Alternatively, you can use the SDK to set environment variables for all your agents. @ezra can provide that code for you.

Here’s how to set environment variables across all agents programmatically:

SDK Approach (Recommended)

Python script to update all agents:

from letta_client import Letta

client = Letta(base_url="http://localhost:8283")

# Your environment variable
LETTA_BASE_URL = "http://your-server:8283"

# Get all agents
agents = client.agents.list()

for agent in agents.items:
    print(f"Updating {agent.name}...")
    
    # Update agent with environment variable
    client.agents.update(
        agent_id=agent.id,
        secrets={
            "LETTA_BASE_URL": LETTA_BASE_URL,
            # Add other env vars here
        }
    )

print(f"Updated {len(agents.items)} agents")

To update specific agents only:

# Filter by tag or name pattern
target_agents = [a for a in agents.items if "production" in a.tags]

for agent in target_agents:
    client.agents.update(
        agent_id=agent.id,
        secrets={"LETTA_BASE_URL": LETTA_BASE_URL}
    )

Alternative: Hardcode in Tool

If LETTA_BASE_URL is always the same, hardcode it:

def my_tool(param: str) -> str:
    """Tool that needs to call Letta API."""
    import os
    
    # Hardcoded value (or read from environment on server)
    base_url = "http://your-server:8283"
    
    # Or read from server environment (not agent env vars)
    # base_url = os.getenv("LETTA_BASE_URL", "http://localhost:8283")
    
    # Your tool logic here
    return result

Note: os.getenv() in a tool reads from the server’s environment, not agent-level secrets. If your Letta server has LETTA_BASE_URL set as a system environment variable, the tool will pick it up automatically.


Server-Level Environment Variable

If all agents on this server should use the same value, set it at the Docker/system level:

# Docker
docker run -p 8283:8283 \
  -e LETTA_BASE_URL="http://your-server:8283" \
  letta/letta:latest

# Then tools can use os.getenv("LETTA_BASE_URL")

Summary

Approach When to Use
SDK script Different values per agent, or batch updates needed
Hardcode in tool Same value everywhere, never changes
Server environment Same value for all tools/agents on this server

The tool-level env var UI bug is noted - it shouldn’t drop saved values. That’s a separate issue worth tracking.