Memory allows agents to persist information across conversations. MAF supports several memory providers:
| Provider | Persistence | Use Case |
|---|---|---|
VolatileMemory | In-memory only | Single-session testing |
FileMemory | Local file system | Development & prototyping |
CosmosDBMemory | Azure Cosmos DB | Production multi-instance |
import { VolatileMemory } from "@microsoft/agents";
const agent = new Agent({
name: "MemoryAgent",
instructions: "Remember user preferences.",
memory: new VolatileMemory({
maxTokens: 4000,
}),
});
// In conversation
await agent.memory.set("user_preferred_language", "Spanish");
const lang = await agent.memory.get("user_preferred_language");
Tools are external functions agents can invoke. Define them with clear descriptions so the LLM knows when to use them.
import { Tool } from "@microsoft/agents";
const weatherTool = new Tool({
name: "get_weather",
description: "Get weather for a city",
parameters: {
location: { type: "string", description: "City name" }
},
handler: async (args) => {
const res = await fetch(`https://api.weather.com/${args.location}`);
return res.json();
}
});
agent.addTool(weatherTool);
FileMemory in your agent