LogoLogo
HomeNewsSupportVideos
  • Welcome
  • Wisej.NET
  • Concepts
    • Getting Started
    • General Concepts
    • Architecture
    • Extensibility
    • AI Providers
    • Vector Databases
    • Usage Metrics
    • Logging & Error Handling
  • Markup
  • Components
    • API
      • SmartAdapter
        • SmartAudioTTSAdapter
        • SmartAudioWhisperAdapter
        • SmartCalendarAdapter
        • SmartChartAdapter
        • SmartChartJS3Adapter
        • SmartChatBoxAdapter
        • SmartComboBoxAdapter
        • SmartCopilotAdapter
        • SmartDataEntryAdapter
        • SmartDocumentAdapter
        • SmartFullCalendarAdapter
        • SmartObjectAdapter
        • SmartPictureBoxAdapter
        • SmartQueryAdapter
        • SmartRealtimeAdapter
        • SmartReportAdapter
        • SmartTextBoxAdapter
        • SmartAdapter.ExtendsAttribute
        • SmartAdapter.FieldNameAttribute
        • SmartAdapter.FieldPromptAttribute
        • SmartAdapter.FieldRectangleAttribute
        • SmartAdapter.WorksWithAttribute
      • SmartEndpoint
        • AmazonBedrockEndpoint
        • AnthropicEndpoint
        • AzureAIEndpoint
        • CerebrasEndpoint
        • DeepSeekEndpoint
        • GoogleAIEndpoint
        • GroqCloudEndpoint
        • GroqCloudEndpointWhisper
        • HuggingFaceEndpoint
        • HuggingFaceJavaScriptEndpoint
        • LocalAIEndpoint
        • LocalAIEndpointImageGen
        • LocalAIEndpointTTS
        • LocalAIEndpointWhisper
        • NvidiaAIEndpoint
        • OllamaEndpoint
        • OpenAIEndpoint
        • OpenAIEndpointDallE
        • OpenAIEndpointRealtime
        • OpenAIEndpointTTS
        • OpenAIEndpointWhisper
        • SambaNovaEndpoint
        • SmartHttpEndpoint
        • TogetherAIEndpoint
        • XAIEndpoint
        • SmartEndpoint.Metrics
        • SmartEndpoint.Response
      • SmartExtensions
      • SmartHub
        • SmartSession.ConvertParameterEventArgs
        • SmartSession.ConvertParameterEventHandler
        • SmartSession.ErrorEventArgs
        • SmartSession.ErrorEventHandler
        • SmartSession.InvokeToolEventArgs
        • SmartSession.InvokeToolEventHandler
        • SmartSession.MessagesEventArgs
        • SmartSession.MessagesEventHandler
      • SmartObject
      • SmartPrompt
        • SmartAgentPrompt
        • SmartParallelPrompt
        • SmartPrompt.Parameter
        • SmartSession.ConvertParameterEventArgs
        • SmartSession.ConvertParameterEventHandler
        • SmartSession.ErrorEventArgs
        • SmartSession.ErrorEventHandler
        • SmartSession.InvokeToolEventArgs
        • SmartSession.InvokeToolEventHandler
        • SmartSession.MessagesEventArgs
        • SmartSession.MessagesEventHandler
      • SmartRealtimeSession
      • SmartSession
        • SmartSession.ConvertParameterEventArgs
        • SmartSession.ConvertParameterEventHandler
        • SmartSession.ErrorEventArgs
        • SmartSession.ErrorEventHandler
        • SmartSession.InvokeToolEventArgs
        • SmartSession.InvokeToolEventHandler
        • SmartSession.Message
        • SmartSession.MessageCollection
        • SmartSession.MessageRole
        • SmartSession.MessagesEventArgs
        • SmartSession.MessagesEventHandler
        • SmartSession.TrimmingStrategy
      • SmartTool
        • SmartTool.IToolProvider
        • SmartTool.ToolAttribute
        • SmartTool.ToolContext
      • Markup
        • MarkupExtensions
      • Controls
        • UVLightOverlay
      • Embeddings
        • EmbeddedDocument
        • Embedding
        • Matches
        • Metadata
      • Helpers
        • ApiKeys
        • Markdown
        • TextTokenizer
      • Services
        • DefaultSessionTrimmingService
        • IDocumentConversionService
          • DefaultDocumentConversionService
        • IEmbeddingGenerationService
          • DefaultEmbeddingGenerationService
          • HuggingFaceEmbeddingGenerationService
        • IEmbeddingStorageService
          • AzureAISearchEmbeddingStorageService
          • ChromaEmbeddingStorageService
          • FileSystemEmbeddingStorageService
          • MemoryEmbeddingStorageService
          • PineconeEmbeddingStorageService
          • QdrantEmbeddingStorageService
        • IHttpClientService
          • DefaultHttpClientService
        • ILoggerService
          • DefaultLoggerService
        • IOCRService
          • DefaultOCRService
        • IRerankingService
          • DefaultRerankingService
          • LocalAIRerankingService
          • PineconeRerankingService
        • ISessionTrimmingService
          • DefaultSessionTrimmingService
        • ITextSplitterService
          • RecursiveCharacterTextSplitterService
          • TextSplitterServiceBase
        • ITokenizerService
          • DefaultTokenizerService
        • IWebSearchService
          • BingWebSearchService
          • BraveWebSearchService
          • GoogleWebSearchService
      • Tools
        • ArxivTools
        • ChartJS3Tools
        • DatabaseTools
        • DataTableFilterTools
        • DocumentSearchTools
        • DocumentTools
        • FullCalendarTools
        • IToolsContainer
        • MathTools
        • ToolsContainer
        • UtilityTools
        • WebSearchTools
    • Built-in Services
      • IOCRService
      • ILoggerService
      • ITextSplitterService
      • ITokenizerService
      • IHttpClientService
      • IWebSearchService
      • IRerankingService
      • ISessionTrimmingService
      • IDocumentConversionService
      • IEmbeddingStorageService
      • IEmbeddingGenerationService
    • Built-in SmartTools
      • ToolsContainer
      • MathTools
      • UtilityTools
      • DatabaseTools
      • DocumentTools
      • DocumentSearchTools
      • WebSearchTools
      • ChartJS3Tools
      • FullCalendarTools
    • Built-in SmartAdapters
      • SmartAdapter
      • SmartAudioTTSAdapter
      • SmartAudioWhisperAdapter
      • SmartCalendarAdapter
      • SmartChartAdapter
      • SmartChartJS3Adapter
      • SmartChatBoxAdapter
      • SmartComboBoxAdapter
      • SmartCopilotAdapter
      • SmartDataEntryAdapter
      • SmartDocumentAdapter
      • SmartFullCalendarAdapter
      • SmartObjectAdapter
      • SmartPictureBoxAdapter
      • SmartQueryAdapter
      • SmartRealtimeAdapter
      • SmartReportAdapter
      • SmartTextBoxAdapter
    • Configure Services
    • Using SmartHub
    • Using SmartTools
    • Using SmartPrompt
    • Using SmartSession
    • Using SmartRealTimeAdapter
    • UVLightOverlay Control
Powered by GitBook
On this page
  • Constructors
  • SmartSession(hub, systemPrompt)
  • SmartSession(endpoint, systemPrompt)
  • Properties
  • Endpoint
  • HasModelOptions
  • Hub
  • IsDisposed
  • Messages
  • ModelOptions
  • Response
  • SystemPrompt
  • Methods
  • AskAsync(question, image)
  • AskAsync(message)
  • AskAsyncCore(question)
  • ConvertParameter(value)
  • Dispose()
  • GetParameterValue(parameter)
  • IsTerminated()
  • PrepareSessionMessages(messages)
  • RemoveTool(tool)
  • ReplaceParameters(prompt)
  • TrimMessagesAsync(messages)
  • UseTool(tool)
  • UseTools(target)
  • Inherited By
Export as PDF
  1. Components
  2. API

SmartSession

Wisej.AI.SmartSession

PreviousSmartRealtimeSessionNextSmartSession.Message

Last updated 5 days ago

Namespace: Wisej.AI

Assembly: Wisej.AI (3.5.0.0)

Represents a session that manages interactions with a smart hub and endpoint, handling prompts, messages, and tools within the session context.

public class SmartSession : SmartObject
Public Class SmartSession
    Inherits SmartObject

The class is responsible for managing the lifecycle of a session, including initialization, message handling, and tool usage. It supports asynchronous operations for asking questions and processing responses, and it can handle context overflow through truncation or summarization strategies.

Constructors

SmartSession(hub, systemPrompt)

Initializes a new instance of the class with the specified hub and optional system prompt.

Name
Type
Description

hub

The smart hub associated with the session.

systemPrompt

The optional system prompt for the session. Default is null.

Throws:

  • Thrown when the hub is null.

SmartSession(endpoint, systemPrompt)

Name
Type
Description

endpoint

The smart endpoint associated with the session.

systemPrompt

The optional system prompt for the session. Default is null.

Throws:

Properties

Methods

Asynchronously asks a question and returns the response message.

Parameter
Type
Description

question

The question to ask.

An optional image associated with the question. Default is null.

Throws:

Asynchronously asks a question using a message and returns the response message.

Parameter
Type
Description

message

The message containing the question.

Throws:

Asynchronously sends a question to the AI and processes the response.

Parameter
Type
Description

question

The message containing the question to be sent to the AI.

This method handles the communication with the AI, including managing the session's message context, handling tool calls, and processing AI responses. It ensures that the session is not disposed and that the question is not null before proceeding. The method also manages the context window size and handles exceptions such as token limit exceedance.


var response = await AskAsyncCore(new Message { Text = "What is the weather today?" });
Console.WriteLine(response.Text);
Parameter
Type
Description

value

Gets the value of a parameter.

Parameter
Type
Description

parameter

The parameter to get the value for.

Prepares session messages by replacing parameters in the system and user messages.

Parameter
Type
Description

messages

The collection of messages to prepare.

Removes a tool from the smart session.

Parameter
Type
Description

tool

The tool to remove.

Throws:

Replaces parameters in the given prompt with their values.

Parameter
Type
Description

prompt

The prompt containing parameters to replace.

Trims messages in the session based on the specified truncation strategy.

Parameter
Type
Description

messages

The collection of messages to trim.

Registers a tool using a delegate.

Parameter
Type
Description

tool

The delegate representing the tool to register.

Throws:

Registers the tools declared on the target.

Parameter
Type
Description

target

The target object containing tools to register.

Inherited By

Name
Description

Initializes a new instance of the class with the specified endpoint and optional system prompt.

Thrown when the endpoint is null.

Endpoint

: Gets the smart endpoint associated with the session.

HasModelOptions

: Gets a value indicating whether the session has model options.

Hub

: Gets the smart hub associated with the session.

IsDisposed

: Gets a value indicating whether the session has been disposed.

Messages

: Gets the collection of messages in the session.

ModelOptions

: Gets or sets the model options for the session.

Response

: Gets the last response message from the assistant.

SystemPrompt

: Gets the system prompt for the session.

AskAsync(question, image)

image

Returns: . A task representing the asynchronous operation, with a as the result.

Thrown when the session is disposed.

Thrown when the question is null.

AskAsync(message)

Returns: . A task representing the asynchronous operation, with a as the result.

Thrown when the session is disposed.

Thrown when the message is null.

AskAsyncCore(question)

Returns: . A task representing the asynchronous operation, with a as the result containing the AI's response.

ConvertParameter(value)

Raises the event.

Returns: .

Dispose()

Releases all resources used by the .

GetParameterValue(parameter)

Returns: . The value of the parameter as a string.

IsTerminated()

Returns: .

PrepareSessionMessages(messages)

RemoveTool(tool)

Returns: . The current instance.

Thrown when the tool is null.

ReplaceParameters(prompt)

Returns: . The prompt with parameters replaced by their values.

TrimMessagesAsync(messages)

Returns: .

UseTool(tool)

Returns: . The current instance.

Thrown when the tool is null.

UseTools(target)

Returns: . The current instance.

SmartSession
ArgumentNullException
SmartEndpoint
Boolean
SmartHub
Boolean
MessageCollection
Object
Message
SmartPrompt
Task<Message>
Message
ObjectDisposedException
ArgumentNullException
Task<Message>
Message
ObjectDisposedException
ArgumentNullException
Task<Message>
Message
String
SmartSession
String
Boolean
SmartSession
SmartSession
ArgumentNullException
String
Task
SmartSession
SmartSession
ArgumentNullException
SmartSession
SmartSession
ConvertParameter
SmartHub
SmartPrompt
SmartEndpoint
SmartPrompt
String
Image
Message
Message
Object
Parameter
MessageCollection
Delegate
String
MessageCollection
Delegate
Object
SmartRealtimeSession
SmartObject
SmartSession
SmartSession
SmartSession
ArgumentNullException