An Agent at your Fingertips

by Doug Lenos

Almost a year ago, Microsoft very quietly released a technology that could be a lot of fun to add to your Web site and really enhance a site's presentation to the user. They called it Microsoft Interactive Agent. If you've worked with Microsoft's Office 97 suite, you're familiar with the animated assistants such as the Paper Clip and Genius. The Microsoft Agent is really an enhancement of this technology and allows the Agent to provide speech and sound feedback to the user. This can give your Web a conversational interface in addition to the usual Windows graphical user interface (GUI).

Exposing the Agent

Initially, Microsoft released three Agents: Genie, Merlin, and Robbie the Robot, shown in Figures A, B, and C respectively.

Figure A: Here's the Genie Agent.

[ Figure A ]

Figure B: Here's the Merlin Agent.

[ Figure B ]

Figure C: Here's the Robbie the Robot Agent.

[ Figure C ]

An Agent is essentially an animation that's displayed in a transparent, borderless window on top of your Web page. This gives the Agent the appearance of hovering directly over the page. Each Agent animation has a complete palette of animations, a distinct synthesized voice that can be synchronized with the agent's various movements, and the ability to react to mouse events and user voice commands. Additionally, an Agent can display speech in a balloon and move its mouth in sync with the text being spoken. Actually, you can provide recorded voices for the Agent, giving you even more flexibility. The tradeoff is the extra work involved to record and integrate the new voice, and the added download time the user will experience.

All this functionality is derived from the Microsoft Agent service provider, and includes an OLE automation server (AGENTSVR.EXE) and a file and docfile provider (AGENTDPV.DLL). In order to reduce the complexity of programming the Agent, the Agent control, AGENTCTL.DLL, allows the programmer to control the Agent via VBScript. What this does, though, is limit the Agent's use to Web browsers that support VBScript--namely Internet Explorer 3.0 and above. Alternatively, you can control the Agent with JScript, allowing the Agent to appear with any JScript compatable browser.

All these support files add substantial overhead to the download time of your Web. The first time a user accesses a site using an Agent, the browser must download the support files, the Agent's character definition file (which provides the unique characteristics of that Agent), and install them. This process can take 5 to 10 minutes, depending on the speed of the Internet connection. This is definitely something you want to consider when deciding when and where to deploy an Agent.

Inherent to each Agent character is a set of methods and states. A method is an invocable function that causes the Agent to perform an action. For example, the SHOW method causes the Agent to appear. A STATE is snapshot of the Agent's current status. One state for an Agent's SHOW method is SHOWING. Animations are assigned to each state and the accompanying return state. Animations that aren't already assigned to states can be given custom names and called as needed. This allows for the Agent to have an unlimited number of animations and still support the core Agent methods.

There are two ways to program the Microsoft Agent, either through a COM (Component Object Model) interface or the more commonly used ActiveX control. For our purposes, we'll be using Microsoft FrontPage 98 and VBScript, which requires the ActiveX control.

Deploying the Agent

In our example, we're going to program Merlin to appear on command, greet us with a brief welcome message, congratulate us on another job well done, and bid farewell. To assist developers, Microsoft has made the three Agents available on their Web site. As a developer, you can either have the Agent provider services loaded on your network, or simply reference the character in the Agents LOAD method by pointing to the characters URL on Microsoft's Web site.

If you're installing your site on an intranet, you can load the animation files from a local or network drive. The Microsoft Agent Data Provider supports loading character data stored as a single structured file (ACS) containing both the character data and animation data together. The LOAD method provides access to all the character's animations. To reference the Merlin character from a local drive, you would enter the following VBScript code:


AgentControl.Characters.Load "merlin","c:\program files\
	microsoft agent\merlinsfx.acs"
Or, you may access the separate character data (ACF) and animation (AAF) files using HTTP when you want to load the animation files individually from a remote Internet site. For ACF files, you also use the GET method to load animation data. To access the Merlin character from the Microsoft Web site, you would use the following:

AgentControl.Characters.Load "merlin","http://agent.
	microsoft.com/characters/merlinsfx/merlinsfx.acf"

Download and install

Prior to working with the Agent technology, you'll need to download the Microsoft Agent core components. These can be found at http://msdn.microsoft.com/msagent/agentdl.asp#core.

Follow the directions listed there to download the Agent core files, the Lernout & Hauspie TruVoice text-to-speech engine, and the Microsoft Command and Control Engine.

Working with Merlin

Once you've installed the three programs, you can begin setting up your Agent. First, Open Microsoft FrontPage 98 and create a new Web with the New FrontPage Web dialog box, as shown in Figure D.

Figure D: Create a new Web by selecting the One Page Web option button.

[ Figure D ]

Now, create a new Web page by clicking on the New Page button. Then, double-click on the new page to open it in the FrontPage Explorer. Once you've opened it, enter some text such as Welcome Merlin!

Adding the ActiveX controls

Add the Microsoft Agent ActiveX control to the page by selecting Insert | Advanced | ActiveX Control... in the FrontPage 98 Editor, as shown in
Figure E.

Figure E: Select ActiveX Control.

[ Figure E ]

This will bring up the ActiveX control dialog box. Select the Microsoft Agent Control 1.5 from the Pick a Control dropdown box. Now, enter the control name. For this example, type AgentControl, as shown in Figure F.

Figure F: In the Name field, type AgentControl.

[ Figure F ]

AgentControl is the name we'll reference in our VBScript to access the controls, properties, methods, and events. Click OK to save the control properties.

Next, we'll add the Text to Speech control. This control handles the conversion of the text into the character's voice. Again, select the Insert | Advanced | ActiveX Control menu option. This time, select the Microsoft Agent Lernout & Hauspie Wrapper Control, as in Figure G.

Figure G: Specify this control.

[ Figure G ]

Click the OK button to save and add the control to your Web page. Your Web page in Normal view should look something like Figure H.

Figure H: n Normal view, your Web page should look similar to this.

[ Figure H ]

Clicking on the HTML tab shows you the HTML added to our Web page that's needed to reference the controls. Notice in Figure I the two object ID tags that were added. One each for the Agent control and the Text to Speech control.

Figure I: Two object ID tags were added.

[ Figure I ]

Adding the VBScript

Finally, we need to add the VBScript that will allow us to load and control Merlin's actions. Open the Script dialog box by selecting Insert | Advanced | Script from the FrontPage Editor menu. Make sure VBScript is selected as the Language, as shown in Figure J.

Figure J: Select VBScript as the Language.

[ Figure J ]

Add the VBScript code in Listing A to the Script Text box, as shown in Figure J, and click the OK button.

Listing A: The VBScript for the Script Text box


Sub window_onload()
	Dim Merlin

	AgentControl.Connected = True
	AgentControl.Characters.Load "merlin",
	"http://agent.
		microsoft.com/characters/merlinsfx/
	merlinsfx.acf"
   	Set Merlin = AgentControl.Characters("merlin")
	Merlin.Get "State", "Showing, Speaking"
	Merlin.Get "Animation", "Greet, GreetReturn, 
	Acknowledge, 
		Announce, Congratulate, DoMagic1, 
			DoMagic2, Read"
	Merlin.Show
	Merlin.Get "State", "Hiding"
	Merlin.Play "Greet"
	Merlin.Speak "Hello. I am Merlin. I am the latest in 
		Microsoft 
		Animation Technology."
   	Merlin.Play "Announce"
	Merlin.Speak "And who might you be?"
	Merlin.Play "Acknowledge"
	Merlin.Play "Congratulate"
	Merlin.Speak "Congratulations. Well done!"
	Merlin.Play "DoMagic1"
	Merlin.Play "DoMagic2"
	Merlin.Play "Read"
	Merlin.Hide
end sub

Deciphering the VBScript

Let's walk through the code to see what it's doing and why it's necessary.

Table A: Important aspects of the VBScript
CodeDescription
Sub window_onload() Window_onload() is a subroutine that's executed as the window (Web page) is loaded into the browser. Because we want Merlin to appear as soon as the user opens our page, we can place our character control code here.
Dim Merlin We need to create a global variable to hold the character object.
AgentControl.Connected = True This opens a connection to the Microsoft Agent Server.
AgentControl.Characters.Load The LOAD method retrieves the character's data file from a remote URL. In this case, Microsoft's.
Set Merlin = AgentControl.Characters("Merlin") The SET statement assigns the Merlin variable to the character object Merlin. All references to the character from this point on are made to the variable Merlin.
Merlin.Get The GET method retrieves the specific animation data for the character. To avoid downloading every animation for a character, you may specify only the animations you intend to use. This is done asynchronously and only via the HTTP protocol. It isn't valid when using local or network stored character data files.
Merlin.Show A character isn't displayed until the SHOW method is executed.
Merlin.Play Here's where the fun begins. The Play method is used to control the character's actions. By following Play with the AnamationName you determine what animation is carried out. For a complete list of animations supported by Merlin, go to msdn.microsoft.com/msagent/Merlinanimationlist.asp.
Merlin.Speak The Speak method followed by text brings Merlin to life. He will speak the text as typed, even while performing animations.
Merlin.Hide The Hide method causes the character to hide.

On with the show

It's time to call Merlin forth! Click on the Preview tab in the FrontPage Editor, and then sit back and relax as Merlin does his thing. Your screen should resemble Figure K.

Figure K: Here's Merlin!

[ Figure K ]

Congratulations! You have just created your first Agent enabled Web page.

Doing it with Jscript

Just in case you'd prefer to work with Jscript, the code is listed in Listing B. Instead of declaring the procedure window_onLoad as in VBScript, the onLoad method is specified in the <BODY> tag to be the JScript function OnLoad() as shown in this example:


<BODY language=Javascript onLoad="OnLoad()">
Listing B: The JScript for the Script Text box

	Var Merlin

function OnLoad() {
	AgentControl.Connected = True
	AgentControl.Characters.Load 
	("merlin", http://agent.
		microsoft.com//characters//
	merlinsfx//merlinsfx.acf);
   	Merlin = AgentControl.Characters.Character
	("merlin")
	Merlin.Get ("State", "Showing, Speaking")
	Merlin.Get ("Animation", "Greet, GreetReturn, 
	Acknowledge,
		 Announce, Congratulate, DoMagic1,
	 DoMagic2, Read")
	Merlin.Show ();   NOTE: Jscript requires parens 
	unlike VBScript
	Merlin.Get ("State", "Hiding")
	Merlin.Play ("Greet");
	Merlin.Speak ("Hello. I am Merlin. I am the
	 latest in Microsoft 
		Animation Technology.");
   	Merlin.Play ("Announce");
	Merlin.Speak ("And who might you be?");
	Merlin.Play ("Acknowledge");
	Merlin.Play ("Congratulate");
	Merlin.Speak ("Congratulations. Well done!");
	Merlin.Play ("DoMagic1");
	Merlin.Play ("DoMagic2");
	Merlin.Play ("Read");
	Merlin.Hide ()
}

Summary

We've seen what Microsoft's Agent technology can do and how we can implement it on our Web sites. If you're interested in knowing more about this exciting technology, you can find information on it at http://msdn.microsoft.com/msagent/default.asp.

This CD and Web site will provide you with Microsoft Agent examples and the Agent Software Development Kit. Microsoft Press has also recently released a book on Developing for the Microsoft Agent. You can find it at mspress.microsoft.com/prod/books/1484.htm.

These tools will assist you with employing your own Agent at Your Command.