Search Results for

    Show / Hide Table of Contents

    Call the assistant from scripts

    Scripts can ask the AI Assistant a question with the DSL API IAiApi, for example to summarize the records of a case, classify an incoming request or draft a text. The assistant answers with the same tools and knowledge sources as in the chat, under the same permissions.

    • In a scripted activity: ctx.Use<IAiApi>()
    • In a rule: @apiFactory.Get<IAiApi>()

    Start and continue a session

    var aiApi = ctx.Use<IAiApi>();
    
    // a new session on the default profile and model
    var result = aiApi.StartSession("Summarize the open applications of this company");
    Log.Info("The assistant said: {Response}", result.Response);
    
    // continue the same session
    var next = aiApi.ResumeSession(result.SessionId, "Now list them by submission date");
    
    // another profile and model, by name or id
    var review = aiApi.StartSession("Review this application",
        new AiSessionOptions { Profile = "Case review", Model = "Claude" });
    
    Member Description
    StartSession(prompt) Starts a new session and returns the answer, on the default profile and model.
    StartSession(prompt, options) Starts a new session on the profile and model the options ask for.
    ResumeSession(sessionId, prompt) Continues a session with a new prompt.
    ResumeSession(sessionId, prompt, options) Continues a session on the profile and model the options ask for.

    AiSessionOptions:

    Property Description
    Profile The assistant profile, by id or name. It must be a profile the user may use. Empty: the default.
    Model The model connection, by id or name, or the profile's name for it in the picker. A model the profile does not offer is never used. Empty: the profile's default model.

    AiSessionResult:

    Property Description
    SessionId The id of the session, to continue it with ResumeSession.
    Response The answer of the assistant.
    ProfileId The assistant profile the session runs on.

    How a script session works

    • It acts as the user the script runs as: it reaches only what that user may reach, and the profile must be one they may use. Without options, it uses the first profile of the worker site that the user may use, and its default model.
    • It cannot change anything that needs a confirmation. A script has no chat to show a card in, so every form submit, workflow start and plugin call that needs the user's confirmation is declined, and the assistant is told why. Plugin methods that do not ask first are called. Use the assistant in scripts to read, count, search and write text, and let the script itself make the changes.
    • It waits for the answer. The call returns when the answer is finished, so keep the questions short and the profile's tools few. The profile's limits apply, and every answer is recorded with its tokens, as in the chat.
    • Script sessions are not shown in the chat's list of conversations.
    Warning

    Every call asks the model and costs tokens and time. Do not call the assistant in access rules, which can run on every request. In other rules and in web triggers, cache the answer with ICacheApi where you can.

    In This Article
    Back to top Generated by DocFX