אחסון הוא רכיב קריטי של Microsoft 365 Agents SDK. היא מאפשרת לסוכנים להשאיר את מצב השיחה, נתוני המשתמש ומידע אחר בהפעלות השונות. ה- SDK תומך במגוון אפשרויות אחסון, כולל:
- אחסון בתוך הזיכרון
- Azure Cosmos DB
- אחסון Blob של Azure
- ספקי אחסון מותאמים אישית
אפשרויות אחסון מרכזיות
ה- SDK של הסוכנים מספק כמה ספקי אחסון מוכללים, שכל אחד מהם כולל מקרי שימוש ויתרונות משלו. באפשרותך לבחור את האפשרות המתאימה ביותר לצרכי הסוכן שלך. באפשרותך גם ליישם ספק אחסון מותאם אישית משלך.
אחסון זיכרון
- מתאים למטרות בדיקה ופיתוח.
- הנתונים נמחקים כאשר הסוכן מופעל מחדש, ולכן זה אינו מתאים לסביבת ייצור.
- הנתונים זמינים במופע של יישום האינטרנט בלבד, ולכן הם אינם ניתנים להתאמה בעת הפעלה באשכול.
Azure Cosmos DB
- מסד נתונים של ריבוי מודלים, בעל התפלגות גלובלית, אידיאלי לנציגי ייצור.
- תומך באחסון מחולק למחיצות לקבלת מדרגיות וביצועים משופרים.
אחסון Blob של Azure
- ממוטב לאחסון נתונים לא משותפים, כגון טקסט או קבצים בינאריים.
- משמש בדרך כלל עבור מצב סוכן ואחסון תעתיקים.
אפשרויות אחסון מותאמות אישית על-ידי יישום IStorage
שימוש בספקי אחסון שונים
אחסון זיכרון
כל הדוגמאות משתמשות ב- MemoryStorage. אחסון זה הוא נדיפות ומתאים לפיתוח ולבדיקה בלבד. עבור תרחישי ייצור, השתמש באפשרות אחסון עמידה יותר, כגון Azure Cosmos DB או Azure Blob Storage.
ב־Program.cs, הירשם MemoryStorage:
builder.Services.AddSingleton<IStorage, MemoryStorage>();
import { MemoryStorage, AgentApplication, TurnState } from '@microsoft/agents-hosting'
const storage = new MemoryStorage()
const app = new AgentApplication<TurnState>({
storage
})
from microsoft_agents.hosting.core import AgentApplication, TurnState, MemoryStorage
storage = MemoryStorage()
app = AgentApplication[TurnState](
storage=storage,
adapter=adapter,
authorization=authorization,
)
אחסון Azure CosmosDb
הוסף תלות בחבילה עבור Microsoft.Agents.Storage.CosmosDb.
ב 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);
});
קבל מידע נוסף ב- CosmosDbPartitionedStorageOptions.
הוסף תלות בחבילה עבור @microsoft/agents-hosting-storage-cosmos.
הגדר וצור את האחסון, ולאחר מכן העבר אותו אל AgentApplication:
import { AgentApplication, TurnState } from '@microsoft/agents-hosting'
import { CosmosDbPartitionedStorage } from '@microsoft/agents-hosting-storage-cosmos'
const storage = new CosmosDbPartitionedStorage({
databaseId: process.env.COSMOS_DATABASE_ID,
containerId: process.env.COSMOS_CONTAINER_ID,
cosmosClientOptions: {
endpoint: process.env.COSMOS_ENDPOINT,
key: process.env.COSMOS_KEY,
}
})
const app = new AgentApplication<TurnState>({
storage
})
קבל מידע נוסף ב- CosmosDbPartitionedStorageOptions.
הוסף תלות בחבילה עבור microsoft-agents-storage-cosmos.
הגדר וצור את האחסון ולאחר מכן העבר אותו אל AgentApplication:
from microsoft_agents.hosting.core import AgentApplication, TurnState
from microsoft_agents.storage.cosmos import CosmosDBStorage, CosmosDBStorageConfig
config = CosmosDBStorageConfig(
cosmos_db_endpoint="your-cosmosdb-endpoint",
database_id="your-database-id",
container_id="your-container-id",
credential=your_token_credential,
)
storage = CosmosDBStorage(config)
app = AgentApplication[TurnState](
storage=storage,
adapter=adapter,
authorization=authorization,
)
קבל מידע נוסף ב- CosmosDBStorageConfig.
אחסון Azure Blob
הוסף תלות בחבילה עבור Microsoft.Agents.Storage.Blobs.
ב 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);
});
הוסף תלות בחבילה עבור @microsoft/agents-hosting-storage-blob.
הגדר וצור את האחסון, ולאחר מכן העבר אותו אל AgentApplication:
import { AgentApplication, TurnState } from '@microsoft/agents-hosting'
import { BlobsStorage } from '@microsoft/agents-hosting-storage-blob'
const storage = new BlobsStorage(
process.env.BLOB_CONTAINER_ID,
process.env.BLOB_STORAGE_CONNECTION_STRING
)
const app = new AgentApplication<TurnState>({
storage
})
הוסף תלות בחבילה עבור microsoft-agents-storage-blob.
קבע את התצורה וצור את האחסון, ולאחר מכן העבר אותו אל AgentApplication:
from microsoft_agents.hosting.core import AgentApplication, TurnState
from microsoft_agents.storage.blob import BlobStorage, BlobStorageConfig
# Using a connection string
config = BlobStorageConfig(
container_name="agent-state",
connection_string="your-connection-string",
)
# Or using a TokenCredential
config = BlobStorageConfig(
container_name="agent-state",
url="https://your-storage-account.blob.core.windows.net",
credential=your_token_credential,
)
storage = BlobStorage(config)
app = AgentApplication[TurnState](
storage=storage,
adapter=adapter,
authorization=authorization,
)
קבל מידע נוסף ב- BlobStorageConfig.