AgentFile (.af)
Define agent configurations as code using AgentFile
AgentFile (.af) is an open standard file format for serializing stateful agents. It provides a portable way to share agents with persistent memory and behavior across different environments.
You can import and export agents to and from any Letta server (including both Docker servers and the Letta API) using the .af file format.
What is AgentFile?
Section titled “What is AgentFile?”AgentFiles package all components of a stateful agent:
- System prompts
- Editable memory (personality and user information)
- Tool configurations (code and schemas)
- LLM settings
By standardizing these elements in a single format, AgentFile enables seamless transfer between compatible frameworks, while allowing for easy checkpointing and version control of agent state.
Why Use AgentFile?
Section titled “Why Use AgentFile?”The AI ecosystem is experiencing rapid growth in agent development, with each framework implementing its own storage mechanisms. AgentFile addresses the need for a standard that enables:
- Portability: Move agents between systems or deploy them to new environments
- Collaboration: Share your agents with other developers and the community
- Preservation: Archive agent configurations to preserve your work
- Versioning: Track changes to agents over time through a standardized format
- Testing: Run reproducible evaluations by using agent files as eval targets
What State Does .af Include?
Section titled “What State Does .af Include?”A .af file contains all the state required to re-create the exact same agent:
| Component | Description |
|---|---|
| Model configuration | Context window limit, model name, embedding model name |
| Message history | Complete chat history with in_context field indicating if a message is in the current context window |
| System prompt | Initial instructions that define the agent’s behavior |
| Memory blocks | In-context memory segments for personality, user info, etc. |
| Tool rules | Definitions of how tools should be sequenced or constrained |
| Environment variables | Configuration values for tool execution |
| Tools | Complete tool definitions including source code and JSON schema |
You can view the complete .af schema in the Letta repository.
Using AgentFile with Letta
Section titled “Using AgentFile with Letta”Importing Agents
Section titled “Importing Agents”You can import .af files using the Agent Development Environment (ADE), REST APIs, or developer SDKs.
Using ADE
Section titled “Using ADE”Upload downloaded .af files directly through the ADE interface to easily re-create your agent.

// Install SDK with `npm install @letta-ai/letta-client`import { Letta, toFile } from "@letta-ai/letta-client";import { readFileSync } from "fs";
// Create a client to connect to Lettaconst client = new Letta({ apiKey: process.env.LETTA_API_KEY });
// Import your .af file from any locationconst file = await toFile(readFileSync("/path/to/agent/file.af"), "agent.af");const importResult = await client.agents.importFile({ file });
console.log(`Imported agent: ${importResult.agent_ids[0]}`);# Install SDK with `pip install letta-client`from letta_client import Lettaimport os
# Create a client to connect to Lettaclient = Letta(api_key=os.getenv("LETTA_API_KEY"))
# Import your .af file from any locationimported_agent = client.agents.import_file(file=open("/path/to/agent/file.af", "rb"))
print(f"Imported agent: {imported_agent.id}")curl -X POST "https://app.letta.com/v1/agents/import" \ -H "Authorization: Bearer LETTA_API_KEY" \ -F "file=@/path/to/agent/file.af"Exporting Agents
Section titled “Exporting Agents”You can export your own .af files to share by selecting “Export Agent” in the ADE.

// Install SDK with `npm install @letta-ai/letta-client`import Letta from "@letta-ai/letta-client";
// Create a client to connect to Lettaconst client = new Letta({ apiKey: process.env.LETTA_API_KEY });
// Export your agent into a serialized schema object (which you can write to a file)const schema = await client.agents.exportFile("<AGENT_ID>");# Install SDK with `pip install letta-client`from letta_client import Lettaimport os
# Create a client to connect to Lettaclient = Letta(api_key=os.getenv("LETTA_API_KEY"))
# Export your agent into a serialized schema object (which you can write to a file)schema = client.agents.export_file(agent_id="<AGENT_ID>")curl -X GET "https://app.letta.com/v1/agents/{AGENT_ID}/export" \ -H "Authorization: Bearer LETTA_API_KEY"Using AgentFiles for Evaluations
Section titled “Using AgentFiles for Evaluations”Agent files are the recommended way to define evaluation targets in Letta Evals. When you use an agent file as a target, the evaluation framework creates a fresh agent instance for each test case, ensuring isolated and reproducible results.
target: kind: agent agent_file: ./agents/my_agent.af base_url: https://api.letta.comThis approach is preferred over using agent_id because:
- Reproducibility: Each test case gets a clean agent state
- Parallel execution: Test cases can run concurrently since they don’t share state
- Version control: Agent files can be committed alongside your test suites
See the Letta Evals documentation for more on setting up automated testing for your agents.
Does .af work with frameworks other than Letta?
Section titled “Does .af work with frameworks other than Letta?”Theoretically, other frameworks could also load in .af files if they convert the state into their own representations. Some concepts, such as context window “blocks” which can be edited or shared between agents, are not implemented in other frameworks, so may need to be adapted per-framework.
How does .af handle secrets?
Section titled “How does .af handle secrets?”Agents have associated secrets for tool execution in Letta. When you export agents with secrets, the secrets are set to null for security reasons.
Contributing to AgentFile
Section titled “Contributing to AgentFile”The AgentFile format is a community-driven standard that welcomes contributions:
- Share Example Agents: Contribute your own
.affiles to the community - Join the Discussion: Connect with other agent developers in our Discord server
- Provide Feedback: Offer suggestions and feature requests to help refine the format
For more information on AgentFile, including example agents and the complete schema specification, visit the AgentFile repository.