ストレージはMicrosoft 365 エージェント SDKの不可欠なコンポーネントです。 これにより、エージェントはセッション間で会話の状態、ユーザーデータ、その他の情報を永続化できます。 SDKは、以下のような様々なストレージオプションをサポートしています。
- メモリ内ストレージ
- Azure Cosmos DB
- Azure Blob Storage
- カスタム ストレージ プロバイダー
キー ストレージ オプション
Agents SDK には、用途や利点が異なる複数の組み込みストレージプロバイダーが用意されています。 エージェントのニーズに最も合ったものをお選びいただけます。 カスタムストレージプロバイダーを実装することもできます。
メモリストレージ
- テストおよび開発目的に適しています。
- エージェントを再起動するとデータが消去されるため、本番環境には適していません。
- データはウェブアプリインスタンス上でのみ利用可能なため、クラスタ環境では適していません。
Azure Cosmos DB
- グローバルに分散されたマルチモデルデータベースで、本番環境のエージェントに最適です。
- スケーラビリティとパフォーマンス向上のため、パーティション化ストレージをサポートしています。
Azure Blob Storage
- テキストやバイナリファイルなどの非構造化データの保存に最適化されています。
- 主にエージェントの状態やトランスクリプトのストレージに使用されます。
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 Cosmos DB ストレージ
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 Storage
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 を参照してください