Skip to content

Commit 72ddef0

Browse files
rogerbarretoCopilot
andcommitted
Add MemorySearch sample to solution, FoundryAgents and AgentWithMemory READMEs
- Add FoundryAgents_Step26_MemorySearch.csproj to agent-framework-dotnet.slnx - Add Memory Search entry to FoundryAgents/README.md samples table - Add cross-reference from AgentWithMemory/README.md to MemorySearch sample Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 0cecee6 commit 72ddef0

4 files changed

Lines changed: 38 additions & 16 deletions

File tree

dotnet/agent-framework-dotnet.slnx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@
176176
<Project Path="samples/GettingStarted/FoundryAgents/FoundryAgents_Step13_Plugins/FoundryAgents_Step13_Plugins.csproj" />
177177
<Project Path="samples/GettingStarted/FoundryAgents/FoundryAgents_Step14_CodeInterpreter/FoundryAgents_Step14_CodeInterpreter.csproj" />
178178
<Project Path="samples/GettingStarted/FoundryAgents/FoundryAgents_Step15_ComputerUse/FoundryAgents_Step15_ComputerUse.csproj" />
179+
<Project Path="samples/GettingStarted/FoundryAgents/FoundryAgents_Step26_MemorySearch/FoundryAgents_Step26_MemorySearch.csproj" />
179180
</Folder>
180181
<Folder Name="/Samples/GettingStarted/ModelContextProtocol/">
181182
<File Path="samples/GettingStarted/ModelContextProtocol/README.md" />

dotnet/samples/GettingStarted/AgentWithMemory/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@ These samples show how to create an agent with the Agent Framework that uses Mem
77
|[Chat History memory](./AgentWithMemory_Step01_ChatHistoryMemory/)|This sample demonstrates how to enable an agent to remember messages from previous conversations.|
88
|[Memory with MemoryStore](./AgentWithMemory_Step02_MemoryUsingMem0/)|This sample demonstrates how to create and run an agent that uses the Mem0 service to extract and retrieve individual memories.|
99
|[Custom Memory Implementation](./AgentWithMemory_Step03_CustomMemory/)|This sample demonstrates how to create a custom memory component and attach it to an agent.|
10+
11+
> **See also**: [Memory Search with Foundry Agents](../FoundryAgents/FoundryAgents_Step26_MemorySearch/) - demonstrates using the built-in Memory Search tool with Azure Foundry Agents.

dotnet/samples/GettingStarted/FoundryAgents/FoundryAgents_Step26_MemorySearch/Program.cs

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,24 @@
88
using Azure.AI.Projects.OpenAI;
99
using Azure.Identity;
1010
using Microsoft.Agents.AI;
11+
using OpenAI.Responses;
1112

1213
string endpoint = Environment.GetEnvironmentVariable("AZURE_FOUNDRY_PROJECT_ENDPOINT") ?? throw new InvalidOperationException("AZURE_FOUNDRY_PROJECT_ENDPOINT is not set.");
1314
string deploymentName = Environment.GetEnvironmentVariable("AZURE_FOUNDRY_PROJECT_DEPLOYMENT_NAME") ?? "gpt-4o-mini";
1415

1516
// Memory store configuration
1617
// NOTE: Memory stores must be created beforehand via Azure Portal or Python SDK.
1718
// The .NET SDK currently only supports using existing memory stores with agents.
18-
string memoryStoreName = Environment.GetEnvironmentVariable("AZURE_AI_MEMORY_STORE_NAME") ?? throw new InvalidOperationException("AZURE_AI_MEMORY_STORE_NAME is not set.");
19+
string memoryStoreName = Environment.GetEnvironmentVariable("AZURE_FOUNDRY_MEMORY_STORE_NAME") ?? throw new InvalidOperationException("AZURE_FOUNDRY_MEMORY_STORE_NAME is not set.");
1920

2021
const string AgentInstructions = """
2122
You are a helpful assistant that remembers past conversations.
2223
Use the memory search tool to recall relevant information from previous interactions.
2324
When a user shares personal details or preferences, remember them for future conversations.
2425
""";
2526

26-
const string AgentName = "MemorySearchAgent";
27+
const string AgentNameMEAI = "MemorySearchAgent-MEAI";
28+
const string AgentNameNative = "MemorySearchAgent-NATIVE";
2729

2830
// Scope identifies the user or context for memory isolation.
2931
// Using a unique user identifier ensures memories are private to that user.
@@ -45,20 +47,9 @@ Use the memory search tool to recall relevant information from previous interact
4547
}
4648
};
4749

48-
// Create the agent with Memory Search tool using native SDK type
49-
AIAgent agent = await aiProjectClient.CreateAIAgentAsync(
50-
name: AgentName,
51-
creationOptions: new AgentVersionCreationOptions(
52-
new PromptAgentDefinition(model: deploymentName)
53-
{
54-
Instructions = AgentInstructions,
55-
Tools =
56-
{
57-
// MemorySearchTool can be implicitly converted to ResponseTool
58-
memorySearchTool
59-
}
60-
})
61-
);
50+
// Create agent using Option 1 (MEAI) or Option 2 (Native SDK)
51+
AIAgent agent = await CreateAgentWithMEAI();
52+
// AIAgent agent = await CreateAgentWithNativeSDK();
6253

6354
Console.WriteLine("Agent created with Memory Search tool. Starting conversation...\n");
6455

@@ -104,3 +95,30 @@ Use the memory search tool to recall relevant information from previous interact
10495
// NOTE: Memory stores are long-lived resources and are NOT deleted with the agent.
10596
// To delete a memory store, use the Azure Portal or Python SDK:
10697
// await project_client.memory_stores.delete(memory_store.name)
98+
99+
// --- Agent Creation Options ---
100+
#pragma warning disable CS8321 // Local function is declared but never used
101+
102+
// Option 1 - Using MemorySearchTool wrapped as MEAI AITool
103+
async Task<AIAgent> CreateAgentWithMEAI()
104+
{
105+
return await aiProjectClient.CreateAIAgentAsync(
106+
model: deploymentName,
107+
name: AgentNameMEAI,
108+
instructions: AgentInstructions,
109+
tools: [((ResponseTool)memorySearchTool).AsAITool()]);
110+
}
111+
112+
// Option 2 - Using PromptAgentDefinition with MemorySearchTool (Native SDK)
113+
async Task<AIAgent> CreateAgentWithNativeSDK()
114+
{
115+
return await aiProjectClient.CreateAIAgentAsync(
116+
name: AgentNameNative,
117+
creationOptions: new AgentVersionCreationOptions(
118+
new PromptAgentDefinition(model: deploymentName)
119+
{
120+
Instructions = AgentInstructions,
121+
Tools = { memorySearchTool }
122+
})
123+
);
124+
}

dotnet/samples/GettingStarted/FoundryAgents/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ Before you begin, ensure you have the following prerequisites:
5858
|[Using plugins](./FoundryAgents_Step13_Plugins/)|This sample demonstrates how to use plugins with a Foundry agent|
5959
|[Code interpreter](./FoundryAgents_Step14_CodeInterpreter/)|This sample demonstrates how to use the code interpreter tool with a Foundry agent|
6060
|[Computer use](./FoundryAgents_Step15_ComputerUse/)|This sample demonstrates how to use computer use capabilities with a Foundry agent|
61+
|[Memory search](./FoundryAgents_Step26_MemorySearch/)|This sample demonstrates how to use memory search tool with a Foundry agent|
6162

6263
## Running the samples from the console
6364

0 commit comments

Comments
 (0)