Important
Please note this is prerelease software, and any APIs and functionality described in this document is subject to change without prior notice before the initial GA release of the AI Hub.
This document describes comprehensive examples demonstrating the InterSystems AI Hub framework in ObjectScript. Please see the User Guide and, for some examples, the Advanced Features Guide for a broader description of the functionalities.
objectscript/
└── cls/
└── Sample/
├── AI/
│ ├── Agent/ # Sample agent subclasses
│ ├── Examples/ # Complete usage examples
│ ├── Orders/ # Additional usage examples
│ ├── Policies/ # Sample policy implementations
│ ├── Proglang/ # Programming language advisor example
│ ├── Skill/ # Sample skill definitions
│ ├── Tools/ # Sample tool implementations
│ └── ToolSet/ # Sample toolset definitions
└── MCP/
└── Service/ # Sample MCP service implementations
Simple examples showing fundamental AI interactions without tools.
Examples:
SimpleQA()- Basic question and answerConversation()- Multi-turn conversation with contextMultiProvider()- Using different AI providers (OpenAI, Anthropic, etc.)
Usage:
Do ##class(Sample.AI.Examples.BasicUsage).SimpleQA()Demonstrates how agents use tools to perform tasks.
Examples:
BMIExample()- Using the BMI calculator toolFileSystemExample()- File system operationsSQLExample()- Database queriesMultiToolExample()- Using multiple tools together
Usage:
Do ##class(Sample.AI.Examples.ToolUsage).BMIExample()Shows how to work with images and other media types.
Examples:
Run()- Analyze a satellite weather imageSimpleExample()- Compare with text-only request
Usage:
Do ##class(Sample.AI.Examples.MultiModal).Run()Demonstrates security and governance with policies.
Examples:
AuthorizationExample()- Restrict file access to specific pathsAuditExample()- Log all tool executionsCombinedPoliciesExample()- Use both authorization and audit
Usage:
Do ##class(Sample.AI.Examples.PolicyEnforcement).AuthorizationExample()Demonstrates retrieval-augmented generation: build a knowledge base, index documents, and let agents retrieve relevant context before answering.
Examples:
FastEmbedDemo()— Local AllMiniLML6V2 embeddings + IRIS SQL store (no embedding API key)OpenAIEmbedDemo()— OpenAI text-embedding-3-small + promoted metadata fieldsReindexDemo()— Atomic document replacement withReindexDocument()
Usage:
// Local embeddings, no API key for embedding
Do ##class(Sample.AI.Examples.RAGUsage).FastEmbedDemo()
// OpenAI embeddings (requires OPENAI_API_KEY)
Do ##class(Sample.AI.Examples.RAGUsage).OpenAIEmbedDemo()
// Re-indexing a changed document
Do ##class(Sample.AI.Examples.RAGUsage).ReindexDemo()XML-based toolset definition showing advanced features:
- Local inline tools
- Included tools from other classes
- Policy composition
- MCP server integration (local stdio and remote HTTP)
Usage:
Set toolset = ##class(Sample.AI.Examples.AdvancedToolSet).%New()
Do agent.ToolManager.AddTool(toolset)A self-contained multi-agent example with a persistent IRIS SQL data model. Demonstrates agent subclassing, tool design, and a realistic domain scenario.
Classes:
Sample.AI.Proglang.Tools- Tools for querying programming language dataSample.AI.Proglang.Professor- Agent that recommends languagesSample.AI.Proglang.Creator- Agent that generates new language definitionsSample.AI.Proglang.Filter- Agent that validates/filters language dataSample.AI.Proglang.Setup- Populates the sample database
Usage:
Do ##class(Sample.AI.Proglang.Setup).Run() // populate sample data
Set agent = ##class(Sample.AI.Proglang.Professor).%New()Interactive agent that connects to the MCP server-everything reference server
via stdio, demonstrating the full agent + MCP tool lifecycle.
Usage:
Set sc = ##class(Sample.AI.Agent.EverythingAgent).Demo() // interactive
Set sc = ##class(Sample.AI.Agent.EverythingAgent).DemoFixed() // automatedCalculate Body Mass Index given height and weight.
Methods:
CalculateBMI(heightM, weightKg)- Returns BMI value and category
Safe file and directory operations.
Methods:
ReadDirectory(path)- List files in a directoryReadFile(path)- Read file contents
Properties:
BaseDirectory- Root directory for operationsMaxFileSize- Maximum file size to read (default 1MB)
RLM-oriented toolset for large-context exploration via explicit tool workflow:
inspect_context()search_context(query, limit)store_note(note)summarize_notes()finalize(result)
Authorization policy that restricts file access to allowed paths.
Properties:
AllowedPath- List of allowed path prefixesStrict- If true, deny access to non-allowed paths
Usage:
Set policy = ##class(Sample.AI.Policies.PathSanitizerPolicy).%New()
Do policy.AllowedPath.Insert("/tmp")
Do policy.AllowedPath.Insert("/data")
Set policy.Strict = 1
Do agent.ToolManager.SetAuthPolicy(policy)- InterSystems IRIS installation with AI Hub included
- API keys for providers (set as environment variables):
OPENAI_API_KEYfor OpenAIANTHROPIC_API_KEYfor Anthropic- Others as needed
Do $system.OBJ.Import("path/to/examples/objectscript/cls", "ck")// Basic example
Do ##class(Sample.AI.Examples.BasicUsage).SimpleQA()
// Tool example
Do ##class(Sample.AI.Examples.ToolUsage).BMIExample()
// Multi-modal example
Do ##class(Sample.AI.Examples.MultiModal).Run()
// Policy example
Do ##class(Sample.AI.Examples.PolicyEnforcement).AuthorizationExample()Sample.AI.RLMAgent extends %AI.Agent and packages the RLM toolset + loop behavior.
Set settings = {"api_key":$SYSTEM.Util.GetEnviron("OPENAI_API_KEY")}
Set provider = ##class(%AI.Provider).Create("openai", settings)
Set agent = ##class(Sample.AI.RLMAgent).%New(provider)
Set agent.Model = "gpt-4o"
Set context = "Encounter timeline... Medication changes... Claims notes..."
Set result = agent.RunRLM("Summarize top 3 interoperability risks.", context, 6)
Write result.%ToJSON(), !Start with BasicUsage.SimpleQA() to understand the fundamentals.
Progress to ToolUsage examples to see how agents use tools.
- Multi-modal:
MultiModal.Run() - Policies:
PolicyEnforcementexamples - ToolSets:
AdvancedToolSet
- Local embeddings:
RAGUsage.FastEmbedDemo() - OpenAI embeddings + filtered search:
RAGUsage.OpenAIEmbedDemo() - Updating documents:
RAGUsage.ReindexDemo()
Use the sample tools and policies as templates for your own:
- Extend
%AI.Toolfor custom tools - Extend
%AI.Policy.Authorizationfor auth policies - Extend
%AI.Policy.Auditfor audit policies - Extend
%AI.ToolSetfor XML-based tool collections - Extend
%AI.RAG.Embeddingfor custom embedding providers
For issues or questions, file an issue against this repository.