AgentToolBase<TDocument> Class
Generic base class for tool classes that operate on a specific document type. Provides dual-mode infrastructure (InMemory /> DocumentStorage) and two helpers — OpenDocument(String, String) and SaveDocument(String, TDocument) — that eliminate per-method mode branching in derived tool classes.
Inheritance
Inherited Members
Namespace: Syncfusion.AI.AgentTools.Core
Assembly: Syncfusion.DocumentSDK.AI.AgentTools.dll
Syntax
public abstract class AgentToolBase<TDocument> : AgentToolBase where TDocument : class
Type Parameters
| Name | Description |
|---|---|
| TDocument | The concrete Syncfusion document type this tool class operates on
(e.g., |
Remarks
Derived tool classes inherit one of two constructors to select the operating mode:
- Mode 1 (InMemory) — backed by a DocumentManagerBase<TDocument>. Documents are live, mutable references held in an in-memory dictionary for the session lifetime. Mutations are automatically visible without an explicit save.
- Mode 2 (DocumentStorage) — backed by a DocumentStorageManager and user-provided IDocumentStorage. Documents are deserialized from the storage on each OpenDocument(String, String) call and exist only for the duration of a single tool invocation. SaveDocument(String, TDocument) must be called after every mutation to persist changes.
The typical tool method pattern is: OpenDocument → mutate → SaveDocument.
Read-only methods may omit the SaveDocument call.
Constructors
AgentToolBase()
Declaration
protected AgentToolBase()
AgentToolBase(DocumentManagerBase<TDocument>, DocumentType)
Initializes a new instance of the AgentToolBase<TDocument> class in InMemory mode, backed by an in-memory document manager that holds documents for the session lifetime.
Declaration
protected AgentToolBase(DocumentManagerBase<TDocument> manager, DocumentType documentType)
Parameters
| Type | Name | Description |
|---|---|---|
| DocumentManagerBase<TDocument> | manager | The in-memory document manager that owns the document dictionary. |
| DocumentType | documentType | The DocumentType this tool class operates on (e.g., Word). |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | Thrown when |
AgentToolBase(DocumentStorageManager, DocumentType)
Initializes a new instance of the AgentToolBase<TDocument> class in DocumentStorage mode, backed by a DocumentStorageManager and user-provided IDocumentStorage.
Declaration
protected AgentToolBase(DocumentStorageManager manager, DocumentType documentType)
Parameters
| Type | Name | Description |
|---|---|---|
| DocumentStorageManager | manager | The storage manager that delegates all I/O to an IDocumentStorage implementation. |
| DocumentType | documentType | The DocumentType this tool class operates on (e.g., Word). |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | Thrown when |
Properties
InMemoryManager
Gets the in-memory document manager used in InMemory mode.
Declaration
protected DocumentManagerBase<TDocument> InMemoryManager { get; }
Property Value
| Type | Description |
|---|---|
| DocumentManagerBase<TDocument> | The DocumentManagerBase<TDocument> instance, or null when operating in DocumentStorage mode. |
Mode
Gets the current operating mode of this tool class.
Declaration
protected DocumentManagerMode Mode { get; }
Property Value
| Type | Description |
|---|---|
| DocumentManagerMode | InMemory when constructed with a DocumentManagerBase<TDocument>, or DocumentStorage when constructed with a DocumentStorageManager. |
StorageManager
Gets the document storage manager used in DocumentStorage mode.
Declaration
protected DocumentStorageManager StorageManager { get; }
Property Value
| Type | Description |
|---|---|
| DocumentStorageManager | The DocumentStorageManager instance, or null when operating in InMemory mode. |
Methods
OpenDocument(String, String)
Retrieves a document by ID or storage path, abstracting away the operating mode.
Declaration
protected TDocument OpenDocument(string documentIdOrFilePath, string password = null)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | documentIdOrFilePath | |
| System.String | password |
Returns
| Type | Description |
|---|---|
| TDocument | The strongly-typed document instance, or null if the document
is not found or if |
SaveDocument(String, TDocument)
Saves a document instance into given file path or document id. No operations in InMemory mode, if documentIdOrFilePath is null or empty.
Declaration
protected void SaveDocument(string documentIdOrFilePath, TDocument document)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | documentIdOrFilePath | |
| TDocument | document |
SaveFile(String, Stream)
Saves a document stream to respective file name in the storage and close it, abstracting away the operating mode. No operations in InMemory mode.
Declaration
protected void SaveFile(string documentIdOrFilePath, Stream stream)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | documentIdOrFilePath | |
| System.IO.Stream | stream |