שימוש ב-storage בסוכן שלך

אחסון הוא רכיב חיוני ב-Microsoft 365 Agents SDK. הוא מאפשר לסוכנים לשמר את מצב השיחה, נתוני המשתמש ומידע נוסף בין sessions. ה-SDK תומך במגוון אפשרויות storage, כולל:

  • אחסון בזיכרון
  • Azure Cosmos DB
  • Azure Blob Storage
  • ספקי אחסון מותאמים אישית

אפשרויות storage עיקריות

Agents SDK מספק מספר ספקי שירותי אחסון מובנים, שלכל אחד מהם מקרי שימוש ויתרונות משלו. באפשרותך לבחור את האפשרות המתאימה ביותר לצורכי הסוכן שלך. באפשרותך גם לממש custom storage provider משלך.

  1. אחסון זיכרון

    • מתאים למטרות בדיקה ופיתוח.
    • הנתונים נמחקים כאשר הסוכן מופעל מחדש, ולכן אינו מתאים ל-production.
    • הנתונים זמינים רק ב-web app instance, ולכן אינו מתאים להפעלה ב-cluster.
  2. Azure Cosmos DB

    • מסד נתונים multimodel מבוזר גלובלית, אידיאלי עבור סוכני production.
    • תומך ב-partitioned storage לצורך scalability וביצועים.
  3. Azure Blob Storage

    • מותאם לאחסון נתונים לא מובנים כגון טקסט או קבצים בינארים.
    • משמש בדרך כלל לאחסון מצב הסוכן וטרנסקריפטים.
  4. אפשרויות custom storage באמצעות מימוש IStorage

שימוש ב-storage providers שונים

אחסון זיכרון

כל הדוגמאות משתמשות ב- MemoryStorage. storage זה הוא volatile ומתאים לפיתוח ולבדיקות בלבד. עבור תרחישי ייצור, השתמש באפשרות אחסון עמידה יותר, כגון Azure Cosmos DB או Azure Blob Storage.

ב- Program.cs, רשום MemoryStorage:

builder.Services.AddSingleton<IStorage, MemoryStorage>();

אחסון Azure Cosmos DB

  1. הוסף תלות בחבילה עבור Microsoft.Agents.Storage.CosmosDb.

  2. ב- Program.cs, להוסיף (או להחליף קים) IStorage רישום עם:

    builder.Services.AddSingleton<IStorage>(sp =>
    {
          var options = new CosmosDbPartitionedStorageOptions()
          {
             CosmosDbEndpoint = "your-cosmosdb-endpoint",
             DatabaseId = "your-database-id",
             ContainerId = "your-container-id",
    
             // Get a TokenCredential from your defined Connections
             TokenCredential = sp.GetService<IConnections>().GetConnection("ServiceConnection").GetTokenCredential()
          };
    
          return new CosmosDbPartitionedStorage(options);
    });
    
  3. מידע נוסף זמין כאן: CosmosDbPartitionedStorageOptions.

אחסון Azure Blob

  1. הוסף תלות בחבילה עבור Microsoft.Agents.Storage.Blobs.

  2. ב- Program.cs, להוסיף (או להחליף קים) IStorage רישום עם:

    builder.Services.AddSingleton<IStorage>(sp =>
    {
       // Get a TokenCredential from your defined Connections
       var tokenCredential = sp.GetService<IConnections>().GetConnection("ServiceConnection").GetTokenCredential();
    
       return new BlobsStorage(
          new Uri("{{your-blobs-storage-endpoint}}/agent-state"),
          tokenCredential);
    });