Member Junction
    Preparing search index...

    Client for executing AI operations through GraphQL. This class provides an easy way to execute AI prompts and agents from a client application.

    The GraphQLAIClient follows the same naming convention as other GraphQL clients in the MemberJunction ecosystem, such as GraphQLActionClient and GraphQLSystemUserClient.

    // Create the client
    const aiClient = new GraphQLAIClient(graphQLProvider);

    // Run an AI prompt
    const promptResult = await aiClient.RunAIPrompt({
    promptId: "prompt-id",
    data: { context: "user data" },
    temperature: 0.7
    });

    // Run an AI agent
    const agentResult = await aiClient.RunAIAgent({
    agentId: "agent-id",
    messages: [{ role: "user", content: "Hello" }],
    sessionId: "session-123"
    });
    Index

    Constructors

    Methods

    • Check the values a person is entering for a new record against the entity's existing records, and get back the ones to flag as possible duplicates.

      This calls the CheckDuplicateEntry mutation. The server finds vector candidates for the values, keeps those the current user can read, and asks a typed decision about them. It only flags: nothing is saved, merged or blocked. An entity whose documents do not turn the check on answers NotConfigured; a caller who may not run the check answers NotAuthorized.

      The method never throws. A failure on the server or in transport is Status: 'Failed' with an ErrorMessage and no candidates. It sets no timeout of its own: a caller with a latency budget abandons the promise when the budget runs out. The server bounds each check with its own budget, a little above the form's, so it stops working on an abandoned check soon after.

      Parameters

      Returns Promise<DuplicateEntryCheckResult>

      The flagged candidates, most probable first, or why there are none

      const result = await aiClient.CheckDuplicateEntry({
      EntityName: 'Accounts',
      Values: { Name: 'Acme', City: 'Boston' }
      });
      if (result.Status === 'Checked') {
      result.Candidates.forEach(c => console.log(`${c.DisplayName} (${c.Probability})`));
      }
    • Generate embeddings for text using local embedding models. This method is designed for interactive components that need fast similarity calculations.

      Parameters

      Returns Promise<EmbedTextResult>

      A Promise that resolves to an EmbedTextResult object

      const result = await aiClient.EmbedText({
      textToEmbed: ["Hello world", "How are you?"],
      modelSize: "small"
      });

      console.log('Embeddings:', result.embeddings);
      console.log('Model used:', result.modelName);
      console.log('Dimensions:', result.vectorDimensions);
    • Execute a simple prompt without requiring a stored AI Prompt entity. This method is designed for interactive components that need quick AI responses.

      Parameters

      Returns Promise<SimplePromptResult>

      A Promise that resolves to a SimplePromptResult object

      const result = await aiClient.ExecuteSimplePrompt({
      systemPrompt: "You are a helpful assistant",
      messages: [
      { message: "What's the weather?", role: "user" }
      ],
      modelPower: "medium"
      });

      if (result.success) {
      console.log('Response:', result.result);
      if (result.resultObject) {
      console.log('Parsed JSON:', JSON.parse(result.resultObject));
      }
      }
    • Fetch vectors with metadata from Pinecone for a given entity document. Returns the vector IDs, embedding values, and metadata stored in the vector index.

      Parameters

      • params: FetchEntityVectorsParams

        The parameters for fetching entity vectors

      Returns Promise<FetchEntityVectorsResult>

      A Promise that resolves to a FetchEntityVectorsResult

    • Approve a pending tag suggestion. The server-side TagGovernanceEngine either creates a new tag (when strategy is 'create-new') or merges into an existing tag (when strategy is 'merge-into-existing'), then re-points any existing free-text ContentItemTag rows whose Tag matches ProposedName.

      Parameters

      • params: {
            strategy: "create-new" | "merge-into-existing";
            suggestionID: string;
            targetTagID?: string;
        }

      Returns Promise<PromoteSuggestionResult>

    • Rebuild persisted tag embeddings for tags whose EmbeddingModelID doesn't match the configured embedding model. Run after a global model change.

      Returns Promise<RebuildTagEmbeddingsResult>

    • Reject a pending tag suggestion with optional reviewer notes.

      Parameters

      • params: { reviewerNotes?: string; suggestionID: string }

      Returns Promise<RejectSuggestionResult>

    • Run an AI agent with the specified parameters.

      This method invokes an AI agent on the server through GraphQL and returns the result. The agent can maintain conversation context across multiple interactions.

      If a progress callback is provided in params.onProgress, this method will subscribe to real-time progress updates from the GraphQL server and forward them to the callback.

      Parameters

      • params: ExecuteAgentParams

        The parameters for running the AI agent

      • OptionalsourceArtifactId: string
      • OptionalsourceArtifactVersionId: string

      Returns Promise<ExecuteAgentResult>

      A Promise that resolves to a RunAIAgentResult object

      const result = await aiClient.RunAIAgent({
      agentId: "agent-id",
      messages: [
      { role: "user", content: "What's the weather like?" }
      ],
      sessionId: "session-123",
      data: { location: "New York" },
      onProgress: (progress) => {
      console.log(`Progress: ${progress.message} (${progress.percentage}%)`);
      }
      });

      if (result.success) {
      console.log('Response:', result.payload);
      console.log('Execution time:', result.executionTimeMs, 'ms');
      } else {
      console.error('Error:', result.errorMessage);
      }
    • Run an AI agent using an existing conversation detail ID. This is an optimized method that loads conversation history server-side, avoiding the need to send large attachment data from client to server.

      Use this method when:

      • The user's message has already been saved as a ConversationDetail
      • The conversation may have attachments (images, documents, etc.)
      • You want optimal performance by loading history on the server

      Parameters

      Returns Promise<ExecuteAgentResult>

      A Promise that resolves to an ExecuteAgentResult object

      const result = await aiClient.RunAIAgentFromConversationDetail({
      conversationDetailId: "detail-id-123",
      agentId: "agent-id",
      maxHistoryMessages: 20,
      createArtifacts: true,
      onProgress: (progress) => {
      console.log(`Progress: ${progress.message}`);
      }
      });
    • Run an AI prompt with the specified parameters.

      This method invokes an AI prompt on the server through GraphQL and returns the result. Parameters are automatically serialized as needed, and results are parsed for consumption.

      Parameters

      Returns Promise<RunAIPromptResult>

      A Promise that resolves to a RunAIPromptResult object

      const result = await aiClient.RunAIPrompt({
      promptId: "prompt-id",
      data: { key: "value" },
      temperature: 0.7,
      topP: 0.9
      });

      if (result.success) {
      console.log('Output:', result.output);
      console.log('Parsed Result:', result.parsedResult);
      } else {
      console.error('Error:', result.error);
      }
    • Run a typed decision (Likelihood, Choice, Score) on the server in one round trip.

      This calls the RunDecision mutation, the fast path for browser features with a tight latency budget such as routing a message or checking for a duplicate: it carries none of the Run Decision action's execution overhead. The questions and the state are serialized for the wire and the answers parsed back.

      The method never throws. A failure on the server or in transport is Success: false with an ErrorMessage and empty Answers.

      Parameters

      • params: RunDecisionParams

        The questions, the state, and optionally the prompt and a timeout

      Returns Promise<RunDecisionResult>

      A Promise that resolves to the answers by question key, or the reason there are none

      const result = await aiClient.RunDecision({
      State: { message: "Show me last quarter's renewals" },
      Questions: {
      route: {
      Kind: 'Choice',
      Instructions: 'Which agent should answer this message?',
      Options: [
      { Value: 'sage', Description: 'General questions about the product' },
      { Value: 'analyst', Description: 'Questions about data and reports' }
      ]
      }
      },
      TimeoutMS: 250
      });

      const route = result.Answers.route;
      if (result.Success && route?.Kind === 'Choice') {
      console.log(`Route to ${route.Value} (confidence ${route.Confidence})`);
      }
    • Run the Tag Health emitters (merge / low-usage / wide-node) on demand. All threshold parameters fall back to DEFAULT_TAG_HEALTH_THRESHOLDS server-side.

      Parameters

      • Optionalparams: {
            maxImplicitChildren?: number;
            maxUsage?: number;
            minCoOccurrence?: number;
            minEmbeddingSimilarity?: number;
            minNameSimilarity?: number;
        }

      Returns Promise<RunTagHealthResult>