October 26, 2016
Hot Topics:

Interactive Help Systems with MS Agents

  • January 12, 2000
  • By Richard C. Leinecker
  • Send Email »
  • More Articles »

How would you like develop a completely interactive help system for your Web-based application? How about the ability to programmatically give your Web site's visitors the guided tour of your site's products and services? Imagine being able to have the genie answer a user's question such as "How do I create a new customer invoice?", or a butler that guides the user through a system's workflow? Sound impossible for a Web site? Well it's not. Microsoft has developed a very powerful and extensible technology and made it available to everyone. The technology (built from ActiveX) allows you to move characters such as those pictured to the right around on the screen and allow them to accept user's natural language queries. They can even verbally respond to the user's request for information! The technology is called Microsoft Agents and it will be the key to next generation of on-line, interactive help systems.

Yes, these are the same little guys that pop up when you hit the F1 key in the Microsoft Office products. Well, as it turns out, these little guys can be used to incorporate a natural language help system for your Web applications as well!

This article is the first in a three-part series on Microsoft Agents and will illustrate everything you need to get started. In this article you will learn how to install the different Agent components on your system (and how to have them automatically download from your Web page), how to display an agent, how to programmatically move an agent around the screen (via VBScript) and how to make the agent display a textual message. Once you've covered the basics with the first article, the second article will illustrate how to use a database to control your agent. This is where your agent will display an edit control to accept user input and respond by displaying textual answers to the user's queries from the database. Finally, in the third and last article in this series, you will discover how to incorporate speech recognition with your agents so that your users can verbally direct the agent!

Before We Start

Before going any further, you need to install the components on your cmputer. There are three essential pieces: the Microsoft Agent component, the text-to-speech component, and the character files. If you skip this step you can still read the article, but the examples I'm going to show you won't be very meaningful.

Step 1: Download the Microsoft Agent Core
ComponentsInstall Microsoft Agent
Core Componentsversion 2.0 (395K)

Note: Windows 2000 Users skip this step. The Microsoft Agent Core Components are already installed on Windows 2000.

Step 2: Download the Text-to-Speech component

The Lernout & Hauspie TruVoice Text-to-Speech (TTS) Engine provides speech output capabilities for Microsoft Agent so you can hear what the characters are saying through your sound speakers.
Install the Lernout & Hauspie TruVoice,
Text-to-Speech Engine (English version) - 1 MB

Note: If you've already installed this, you should see Lernout & Hauspie TruVoice American English TTS Engine in the Control Panel's Add/Remove Programs list.

Step 3: Download at least one Microsoft Agent Character

There are many Agent characters available and many more are being created. Now that you have Microsoft Agent installed on your computer, you only have to download additional Characters (files with .ACS extensions) as they become available and save them to your C:\WINDOWS\MSAGENT\CHARS or C:\WINNT\MSAGENT\CHARS folder, depending on your operating system. (The installation programs save them the the correct directory without any intervention on your part.)

Note: You must download these characters since they are used in the examples. Additional characters are available on a link page

Filename Size Creator
Peedy.exe Merlin.exe Genie.exe
3.3 MB 1.8 MB 1.6 MB

First Example

Hopefully you've installed the Microsoft Agent, Text-to-Speech, and Microsoft Agent files by now. We're going to start with our first demo so that you can get your feet wet and understand the basics of using agents in your Web pages.

Click on the following link to see a very simple example. Then I'll explain the code.

Here is the simplified (irrelevant formatting codes removed) HTML Code for the First Example. Annotations are inserted.

Using Microsoft Agents - Example 1

Using Microsoft Agents in Web Pages

Example 1: Loading and displaying an agent in your Web page

Below is the code that instantiates the Microsoft Agent control and the Text-to-Speech control.

The VB Script is next.

<script Language="VBScript"> Dim Genie

Before the agent can be used, a few initialization items must be taken care of.

  1. The AgentControl's Connected property is set to true.
  2. The character (in this case it's the Genie) is loaded.
  3. A Genie object is obtained from the AgentControl object.
  4. The language can be set in the LanguageID property. This is not necessary for English since that's the default. See Table 1.

Now that everything is initialized, you can put the Genie into action

Show the Genie with the Show method.
Have the Genie speak with the Speak method.

In this HTML file, the Window_OnLoad() subroutine 
does all the work. 
Sub Window_OnLoad()
 AgentControl.Connected = True
 AgentControl.Characters.Load "Genie", "Genie.acs"
 Set Genie = AgentControl.Characters("Genie")
 Genie.LanguageID = &H409
 Genie.Speak "Hello. Welcome to sourceDNA"
End Sub
</script> </body> </html>

Below is the table containing language IDs for the speech engine.

Table 1 - Language IDs

Arabic &H0401
Basque &H042D
Chinese (Simplified) &H0804
Chinese (Traditional) &H0404
Croatian &H041A
Czech &H0405
Danish &H0406
Dutch &H0413
English (British) &H0809
English (US) &H0409
Finnish &H040B
French &H040C
German   &H0407
Greek &H0408
Hebrew &H040D
Hungarian &H040E
Italian &H0410
Japanese &H0411
Korean &H0412
Norwegian &H0414
Polish &H0415
Portuguese &H0816
Portuguese (Brazilian) &H0416
Romanian &H0418
Russian &H0419
Slovakian &H041B
Slovenian &H0424
Spanish &H0C0A
Swedish &H041D
Thai &H041E
Turkish &H041F

Code Robustness

Right now some of you might be asking what happens if something goes wrong. What if the agent doesn't load, or some other error occurs. If you're asking that, then your concerns are well founded. The examples in this article are intended to be simple and clearly illustrate a small number of items. For that reason, I'm going to keep the code simple and avoid error trapping.

In spite of the fact that the examples don't have any error trapping, that doesn't mean you want to take that option yourself. This section shows you have to handle errors so that your code is robust. This will end up saving you endless embarassment when your boss shows the Web page to his friends and it crashes.

Automatic Control and Character Loading

The first thing we'll look at is handling the case where the client computer doesn't have the Microsoft Agent, the Text-to-Speech, or the Character files installed.

The only change you must make to the OBJECT tag that instantiates the controls, is to specify the URL from which the control can be downloaded. Of course, the version number is part of this too. But example 1 included the version number so all you would need to add is the URLs as follows.

click here to view example.

Making Sure the Agent is Installed

Before your code does anything, you might want to check to see if the Microsoft Agent control is installed. Your Web page needs to have alternative code in the event that the control hasn't been installed. I have two functions below that I suggest using to determine if the control has been installed.

The GetScriptVersion function determines the major version of the scripting engine. If it's an earlier version of the scripting engine, it won't support the Microsoft Agent and therefore even if the Agent has been installed, it won't be able to be loaded.

Function GetScriptVersion()
 ' Purpose: Returns major version of the Scripting Engine
 On Error Resume Next

 Dim Ver
 Ver = 0

 Ver = ScriptEngineMajorVersion
 If Ver = 0 Then Ver = 1

 GetScriptVersion = Ver

End Function

The AgentInstalled function determines if the Agent has been installed. First, though, it calls the ScriptVersion function to make sure the scripting engine will handle the Agent control. An attempt is made to instantiate an Agent control using the CreateObject function. Once this is done, the IsObject function makes the final determination that the Agent is indeed installed and loadable.

Function AgentInstalled()
' Purpose: Returns True if Agent 2.0 is installed, else False
On Error Resume Next

 Dim AgentControl
 Dim ScriptVersion
 ScriptVersion = GetScriptVersion()
 If ScriptVersion > 1 Then
  Set AgentControl = CreateObject("Agent.Control.2")
  AgentInstalled = IsObject(AgentControl)
  AgentInstalled = False
 End If

End Function

Now you can simply call the AgentInstalled function and execute the appropriate code as follows:

If Not AgentInstalled() Then
 ' Do code here for the occasion when the Agent control isn't loaded
 ' Do other code here since the Agent control is loaded
End If

Automatic Character Loading

You're also going to want to make sure that a character has been loaded. It's not difficult, but there are a few steps. In example 1, we called the AgentControl.Characters.Load method.

Here's an example of how to error trap this call and if an error happens, attempt to load the character file from a URL.

 On Error Resume Next

 AgentControl.Characters.Load "Genie", "Genie.acs"

 If Err <> 0 Then
  Window.Status = "Loading Genie Character. Please Wait..."
  Set GenieReq = AgentControl.Characters.Load("Genie",
  Window.Status = ""
 End If

An Interactive Example

It's time to put some interaction into the example. This Web page does a lot more than the last. First, it displays four lines of text that offer interaction choices. Users can click on either of the choices and have Merlin moving to the upper left corner of the screen, moving to the center of the screen, saying something, and laughing.

After taking a look, you'll be interested to know what's going on behind the Web page. Of course, you can simply look at the source, or you can follow along with the discussion below.

First is the DHTML stuff that makes up the user interface part of the code. The following lines are used to display four lines of text and defines each of their IDs differently:

Move Merlin to upper left

Move Merlin to center

Make Merlin talk

Make Merlin laugh

There are four sets of subroutines that handle the user interaction. In all four sets, the onMouseOver subroutine turns the text into a goldenrod color; while the onMouseOut subroutine turns it back to black.

What's different for them all is the onMouseClick subroutine which does something different for each user action.

Click here for code example.

You may have noticed the use of several variables such as MerlinCenterX and MerlinCenterY. These were declared in the VBScript and a special function was used to assign their values. The function is below:

See code example here.


Adding Microsoft Agents to your Web site isn't that difficult after all. And it sure will jazz up your presentation, not to mention add a new dimension in functionality. Go ahead and experiment, that'll get you ready for our next article.

Send me your questions, I'll do my best to get you an answer. Also, please send me the URL to your Web pages if you use an Agent.

The next article in this series will show you how to make the Agents into database driven animals. I'll populate a database, then move an agent around while he carries on a conversation.

Contributed by sourceDNA.


Comment and Contribute


(Maximum characters: 1200). You have characters left.



Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Sitemap | Contact Us

Thanks for your registration, follow us on our social networks to keep up-to-date
Rocket Fuel