Written by

Technical Graduate - DevRel at InterSystems
Article Gabriel Ing · 1 hr ago 4m read

An Introduction to AI Hub, Part 1: Agents in ObjectScript

For those of you that weren't at READY last week, you may have missed the exciting announcement that the Early Access Program for AI Hub is officially open. It was announced during an amazing demo from @Benjamin De Boe and @Jeff Fried, I recommend catching up with this demo when the recording is released!  I had the opportunity to play with AI Hub in advance, and thought I might share an introduction with the community.

Before getting into the details, here is a link for the documentation and here is a link to the EAP portal to download AI Hub, its currently available as standalone install kits or container images. 

Please note, this is a preview and there are likely to be significant changes before the official release, it is not designed for production use, and you may run into some issues - if you do, raise an issue on the Github page!

Agents

The most exciting feature, for me at least, has been the new ObjectScript agents SDK. You can now create agents and tools directly in ObjectScript, using an intuitive SDK.

Creating an Agent is simple you can give it a system prompt with the XData INSTRUCTIONS component, then just set the provider, model and tools:

Class Sample.Agent Extends %AI.Agent
{
    /// LLM Model
    Parameter MODEL = "gpt-5-nano";

    /// Toolsets that the agent can use
    Parameter TOOLSETS = "Sample.ToolSet";
    
    /// System Prompt
    XData INSTRUCTIONS [ MimeType = text/markdown ]
    {
    # Sample Assistant

    You are a helpful assistant with access to a set of tools to interact with a database of people.
    }

    Method %OnInit() As %Status
    {
        // Set provider with API key from environment variable
        Set key = $System.Util.GetEnviron("OPENAI_API_KEY")  // or whatever
        Set ..Provider = ##class(%AI.Provider).Create("openai", {"api_key": (key)})
        
        Return $$$OK
    }
}

Tools

Tools are even easier to create - its as simple as extending %AI.Tools, after that, all methods, class methods and queries become tools that agents can use. So we can do something like the following:

Class Sample.Tools Extends %AI.Tool [dependsOn=Sample.Person]
{

/// Tool to add a person to the database
Method AddPerson(name As %String, age As %Integer) As %Status{
   Set person = ##class(Sample.Person).%New()
   Set person.Name = name
   Set person.Age = age
   Set sc =  person.%Save()
   Quit sc
}

/// Tool query database for people younger than a specified age
Query GetPeopleYoungerThan(age As %Integer) As %SQLQuery(ROWSPEC = "Name:%String,Age:%Integer") [ SqlProc ]
{
   SELECT Name, Age From Sample.Person Where Age < :age
}

}

Tools can also be organised into toolsets, these are, as the name suggests, sets of tools that can be used to combine many tools from different classes, filter tools by regex matching, add policies and use MCP servers defined outside of IRIS.

In the example below we combine the tools we defined above, Sample.Tools, with a policy which logs tool calls to the terminal (%AI.Policy.ConsoleAudit) and a custom Python MCP server.

Class Sample.ToolSet Extends %AI.ToolSet [DependsOn=Sample.Tools]
{
    XData Definition
    {
        <ToolSet>
            <Description>Sample Toolset</Description>
            
            <Policies>
           <!--Policy to Log tool calls to Console-->
                <Audit Class="%AI.Policy.ConsoleAudit"/>
            </Policies>
            
            <!--ObjectScript Tools-->
            <Include Class="Sample.Tools"></Include>
            
            <!--Python MCP Server created with FastMCP-->
            <MCP Name="PythonServer"> 
                <Stdio Executable="/usr/irissys/bin/irispython" 
                Args="/home/irisowner/dev/src/Python/multiplication_mcp.py" />
            </MCP>
            
        </ToolSet>
    }    
}

Other ObjectScript features

There are a load more of cool features to create super powerful agents, including support for agent skills (%AI.Agent.Skill), delegation of tasks to subagents (%AI.Agent.SubAgent) and tools for creating knowledge bases with RAG (%AI.RAG). You can also create custom audit or authentication policies, to either log tool calls or decide whether they should be allowed.

One very cool feature is that tools and toolsets can be stateful, meaning they retain the state between tool calls. As such, a tool could be called multiple times, with the actions of the previous tool call being retained. For example, a file could be opened once and the contents 'remembered' the next time the tool is called. To use this, define tools with methods (instead of class methods) and save attributes as properties. There's a nice example of this in the documentation.

I've been working with AI hub for well over a month now, and am still overwhelmed by the amount of features, particularly at the advanced end, that I still need to explore.

Template

If you want to start playing around with AI Hub, I published a dev template to the Open Exchange which includes instructions for downloading and building the AI Hub container, and has a few pre-loaded sample classes (you might recognise them from this article). It even has some agent skills, in case you'd like your AI agent of choice to know what's in the documentation before you do!

It even creates an MCP server and has instructions on how to connect to it.

Next time

In my next article, I'll show how you can package your agent tools into an MCP server to connect directly to your data from any MCP client!