Home/Agentic AI/Semantic Kernel/Memory & Planning

Microsoft Semantic Kernel

Master Semantic Kernel for building enterprise-grade AI agents with plugin architecture

Memory & Automatic Planning

Semantic Kernel provides semantic memory for storing and retrieving information using embeddings, and automatic planners that decompose high-level goals into executable function sequences.

🧠 Semantic Memory

1. Configure Memory Store
// Use Azure Cognitive Search, Pinecone, Qdrant, etc.
var memoryBuilder = new MemoryBuilder();
memoryBuilder.WithAzureOpenAITextEmbeddingGeneration(
    deploymentName,
    endpoint,
    apiKey
);
memoryBuilder.WithMemoryStore(
    new QdrantMemoryStore(host, port)
);

var memory = memoryBuilder.Build();
2. Save Information to Memory
// Store facts with embeddings
await memory.SaveInformationAsync(
    collection: "company_docs",
    text: "Our Q4 revenue was $2.5M, up 35% from Q3",
    id: "revenue_q4_2024"
);

await memory.SaveInformationAsync(
    collection: "company_docs",
    text: "New product launch scheduled for March 2025",
    id: "product_launch_2025"
);
3. Semantic Search
// Search using natural language
var results = await memory.SearchAsync(
    collection: "company_docs",
    query: "What are our revenue numbers?",
    limit: 3,
    minRelevanceScore: 0.7
);

foreach (var result in results)
{
    Console.WriteLine($"Score: {result.Relevance}");
    Console.WriteLine($"Text: {result.Metadata.Text}");
}

Interactive: Automatic Planner in Action

Watch how SK's planner breaks down a goal into function calls automatically:

📋 Using Planners

Function Calling Stepwise Planner
using Microsoft.SemanticKernel.Planning;

// Create planner
var planner = new FunctionCallingStepwisePlanner();

// Give it a goal
var result = await planner.ExecuteAsync(
    kernel,
    "Find the latest AI news and send a summary email to team@company.com"
);

// Planner automatically:
// 1. Identifies needed functions (search, summarize, email)
// 2. Calls them in correct order
// 3. Passes outputs between functions
// 4. Returns final result

When to Use Planners

  • Complex multi-step workflows that require reasoning
  • When exact sequence isn't known in advance
  • User provides high-level goals instead of step-by-step instructions

When NOT to Use Planners

  • Simple, single-function calls (use direct invoke instead)
  • Fixed workflows where sequence is always the same
  • Budget-sensitive scenarios (planners use more tokens)

💡 Memory & Planning Tips

  • Memory is semantic: Searches by meaning, not exact keywords - great for RAG patterns
  • Planners need good descriptions: Function descriptions guide planner's decision-making
  • Start simple: Test individual functions before using planners
  • Monitor token usage: Planners make multiple LLM calls - watch costs
Prev