← Back to Tutorials

4. Agent Capabilities

Memory & Context Management

Memory allows agents to persist information across conversations. MAF supports several memory providers:

ProviderPersistenceUse Case
VolatileMemoryIn-memory onlySingle-session testing
FileMemoryLocal file systemDevelopment & prototyping
CosmosDBMemoryAzure Cosmos DBProduction 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");

Function Tools

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);

Hands-On Lab: Memory & Tools

  1. Configure FileMemory in your agent
  2. Create a tool that saves notes to a local file
  3. Create a tool that retrieves saved notes
  4. Test: "Remember that I like cats" → "What do I like?"
💡 Tip: Always set clear descriptions on tools and parameters. The LLM uses descriptions to decide which tool to invoke.
✏️ Exercise: Build an agent with persistent memory that stores user preferences (theme, language, notification preferences) and retrieves them in later conversations. Use FileMemory during development.