Last active
November 29, 2025 20:24
-
-
Save cpfiffer/b63df4d768a6a5d0d32d87ecf06ed2b2 to your computer and use it in GitHub Desktop.
context window compilation for letta agents
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from letta_client import Letta | |
| import os | |
| # Initialize client | |
| client = Letta(api_key=os.getenv("LETTA_API_KEY")) | |
| agent_id = "AGENT ID" | |
| agent = client.agents.retrieve(agent_id) | |
| context = "<memory>" | |
| for block in agent.blocks: | |
| header = f"\n<{block.label} description=\"{block.description}\">" | |
| content = "\n" + block.value | |
| footer = f"\n</{block.label}>" | |
| context += header + content + footer | |
| context += "</memory>" | |
| print(context) |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example output: