The AI Query API class provides the methods to interact with the AI Query API. This API implements the Nevermined AI Query Protocol

See

https://docs.nevermined.io/docs/protocol/query-protocol.

Remarks

This API is oriented for AI Builders providing AI Agents and AI Subscribers interacting with them.

Hierarchy

  • NVMBackendApi
    • AIQueryApi

Constructors

Methods

  • Parameters

    Returns Promise<void>

  • Parameters

    • _callback: ((err?) => any)
        • (err?): any
        • Parameters

          • Optional err: any

          Returns any

    • opts: SubscriptionOptions

    Returns Promise<void>

  • Parameters

    • _callback: ((err?) => any)
        • (err?): any
        • Parameters

          • Optional err: any

          Returns any

    • opts: SubscriptionOptions

    Returns Promise<void>

  • Parameters

    • _callback: ((err?) => any)
        • (err?): any
        • Parameters

          • Optional err: any

          Returns any

    • tasks: string[]
    • history: boolean = true

    Returns Promise<void>

  • It creates the step/s required to complete an AI Task

    Parameters

    • did: string

      Agent DID

    • taskId: string

      Task ID

    • steps: any

      The list of Steps to create

    Returns Promise<AxiosResponse<any, any> | {
        data: any;
        headers: any;
        status: any;
    }>

    The result of the operation

    Remarks

    This method is used by the AI Agent to create the steps required to complete the AI Task.

  • Subscribers can create an AI Task for an Agent. The task must contain the input query that will be used by the AI Agent.

    Parameters

    • did: string

      Agent DID

    • task: CreateTaskDto

      Task object. The task object should contain the query to execute and the name of the task. All the attributes here:

    • queryOpts: AIQueryOptions

      The query options

    • Optional _callback: ((err?) => any)

      The callback to execute when a new task log event is received (optional)

        • (err?): any
        • Parameters

          • Optional err: any

          Returns any

    Returns Promise<AxiosResponse<any, any> | {
        data: any;
        headers: any;
        status: any;
    }>

    The result of the operation

    See

    Remarks

    This method is used by subscribers of a Payment Plan required to access a specific AI Agent or Service. Users who are not subscribers won't be able to create AI Tasks for that Agent.

    Because only subscribers can create AI Tasks, the method requires the access token to interact with the AI Agent/Service. This is given using the queryOpts object (accessToken attribute).

    Example

    const accessConfig = await payments.getServiceAccessConfig(agentDID)
    const queryOpts = {
    accessToken: accessConfig.accessToken,
    proxyHost: accessConfig.neverminedProxyUri
    }

    const aiTask = {
    query: "https://www.youtube.com/watch?v=0tZFQs7qBfQ",
    name: "transcribe",
    "additional_params": [],
    "artifacts": []
    }

    await payments.query.createTask(
    agentDID,
    aiTask,
    queryOpts
    )
  • Parameters

    • url: string
    • data: any
    • reqOptions: HTTPRequestOptions

    Returns Promise<AxiosResponse<any, any> | {
        data: any;
        headers: any;
        status: any;
    }>

  • Parameters

    • url: string
    • reqOptions: HTTPRequestOptions = ...

    Returns Promise<AxiosResponse<any, any> | {
        data: any;
        headers: any;
        status: any;
    }>

  • It retrieves the complete information of a specific step given a stepId

    Parameters

    • stepId: string

      the id of the step to retrieve

    Returns Promise<any>

    The complete step information

    Remarks

    This method is used by the AI Agent to retrieve information about the steps part of tasks created by users to the agents owned by the user

    Example

    await paymentsBuilder.query.getStep('step-1234')
    
  • It retrieves all the steps that the agent needs to execute to complete the different tasks assigned.

    Parameters

    • status: undefined | AgentExecutionStatus = AgentExecutionStatus.Pending

      The status of the steps to retrieve

    • dids: string[] = []

      The list of DIDs to filter the steps

    Returns Promise<AxiosResponse<any, any> | {
        data: any;
        headers: any;
        status: any;
    }>

    The steps of the task

    Remarks

    This method is used by the AI Agent to retrieve information about the steps part of tasks created by users to the agents owned by the user

  • It retrieves all the steps that the agent needs to execute to complete a specific task associated to the user.

    Parameters

    • did: string

      Agent DID

    • taskId: string

      Task ID

    • Optional status: string

      The status of the steps to retrieve

    Returns Promise<AxiosResponse<any, any> | {
        data: any;
        headers: any;
        status: any;
    }>

    The steps of the task

    Remarks

    This method is used by the AI Agent to retrieve information about the tasks created by users to the agents owned by the user

  • It returns the full task and the steps resulted of the execution of the task.

    Parameters

    Returns Promise<AxiosResponse<any, any> | {
        data: any;
        headers: any;
        status: any;
    }>

    The task with the steps

    Remarks

    This method is used by subscribers of a Payment Plan required to access a specific AI Agent or Service. Users who are not subscribers won't be able to create AI Tasks for that Agent.

    Because only subscribers get the results of their AI Tasks, the method requires the access token to interact with the AI Agent/Service. This is given using the queryOpts object (accessToken attribute).

    Example

    const accessConfig = await payments.getServiceAccessConfig(agentDID)
    const queryOpts = {
    accessToken: accessConfig.accessToken,
    proxyHost: accessConfig.neverminedProxyUri
    }

    await payments.query.createTask(
    agentDID,
    taskId,
    queryOpts
    )
  • It retrieves all the tasks that the agent needs to execute to complete the different tasks assigned.

    Returns Promise<AxiosResponse<any, any> | {
        data: any;
        headers: any;
        status: any;
    }>

    The tasks of the agents

    Remarks

    This method is used by the AI Agent to retrieve information about the tasks created by users to the agents owned by the user

  • It emits a log message related to a task

    Parameters

    Returns Promise<void>

    Remarks

    This method is used by the AI Agent to emit log messages

  • Parameters

    • additionalHeaders: {
          [key: string]: string;
      }
      • [key: string]: string

    Returns {}

    • Parameters

      • uri: string
      • reqOptions: HTTPRequestOptions

      Returns string

    • Parameters

      • url: string
      • data: any
      • reqOptions: HTTPRequestOptions

      Returns Promise<AxiosResponse<any, any> | {
          data: any;
          headers: any;
          status: any;
      }>

    • Parameters

      • url: string
      • data: any
      • reqOptions: HTTPRequestOptions

      Returns Promise<AxiosResponse<any, any> | {
          data: any;
          headers: any;
          status: any;
      }>

    • It search steps based on the search parameters. The steps belongs to the tasks part of the AI Agents owned by the user.

      Parameters

      Returns Promise<AxiosResponse<any, any> | {
          data: any;
          headers: any;
          status: any;
      }>

      The result of the search query

      Remarks

      This method is used by the AI Agent to retrieve information about the steps part of tasks created by users to the agents owned by the user

      Example

      await paymentsBuilder.query.searchSteps({ step_id: "my-step-id" })
      

      See

      SearchSteps

    • It searches tasks based on the search parameters associated to the user

      Parameters

      Returns Promise<AxiosResponse<any, any> | {
          data: any;
          headers: any;
          status: any;
      }>

      The result of the search query

      Remarks

      This method is used by the AI Agent to retrieve information about the tasks created by users to the agents owned by the user

      Example

      await paymentsBuilder.query.searchTasks({ did: "did:nv:1234" })
      

      See

      SearchTasks

    • Parameters

      • token: string

      Returns void

    • It subscribes to the Nevermined network to retrieve new AI Tasks requested by other users.

      Parameters

      • _callback: ((err?) => any)

        The callback to execute when a new event is received

          • (err?): any
          • Parameters

            • Optional err: any

            Returns any

      • opts: SubscriptionOptions = DefaultSubscriptionOptions

        The subscription options

      Returns Promise<void>

      Remarks

      This method is used by AI agents to subscribe and receive new AI Tasks sent by other subscribers

    • It subscribes to receive the logs generated during the execution of a task/s

      Parameters

      • _callback: ((err?) => any)

        The callback to execute when a new task log event is received

          • (err?): any
          • Parameters

            • Optional err: any

            Returns any

      • tasks: string[]

        The list of tasks to subscribe to

      • history: boolean = true

        If true, it retrieves the history of the logs emitted before the subscription

      Returns Promise<void>

      Remarks

      This method is used by users/subscribers of AI agents after they create a task on them

    • It updates the step with the new information

      Parameters

      • did: string

        Agent DID

      • step: Step

        The Step object to update.

      Returns Promise<AxiosResponse<any, any> | {
          data: any;
          headers: any;
          status: any;
      }>

      The result of the operation

      Remarks

      This method is used by the AI Agent to update the status and output of an step. This method can not be called by a subscriber.

      Example

      const result = await payments.query.updateStep(step.did, step.task_id, step.step_id, {
      step_id: step.step_id,
      task_id: step.task_id,
      did: step.did,
      step_status: AgentExecutionStatus.Completed,
      is_last: true,
      output: 'LFG!',
      cost: 1
      })

      See

      https://docs.nevermined.io/docs/protocol/query-protocol#steps-attributes