AIML Docs

What is AIML?

Learn what AIML is and how it works

AIML (AI Markup Language)

AIML is a declarative language for building AI/LLM Agents using MDX and an extended version of the SCXML (State Chart XML) standard. AIML makes it easy to create AI agents, simple to sophisticated, supporting complex conversation flows and code execution, tool integration, and full state management.

How does AIML work?

An AIML document is sent to an AIML proxy server, which is a normal HTTP server that can be deployed anywhere. The AIML proxy server processes the AIML document to create a state chart and execute the request.

What does AIML look like?

AIML is Markdown + MDX. No SDKs to install, no classes to import, no complex syntax to learn.

Document Order Execution

AIML prompts are executed sequentially from top to bottom, making it intuitive to build complex prompt pipelines. Each text section, and element (along with it's children) is processed in order, allowing you to create sophisticated workflows while maintaining readability.

Circular Logic

To create circular logic, AIML supports <state> elements. States, along with <transition> elements allow you to create loops, or to create more complex conditional logic by tying one or more states together.

<state name="Step1">
  <transition target="Step2" />
</state>
 
<state name="Step2">
  <transition cond={({lastElement}) => lastElement.outputType == 'tool-call'} target="Step3" />
  <transition target="respond" />
</state>
 
<state name="Step3">
  <transition target="respond" />
</state>
 
<final name="respond" />

This will create a conditional loop that can be visualized as a flow chart like this:

Start simple and iterate

You can progressively enhance AIML prompts by adding additional steps.

For example, here's a simple AIML prompt:

You are a helpful Weather Agent!
 
Respond to the users questions about the weather, but don't talk about anything else!

This creates an agent that responds with a simple message, but we want to have it respond with actual weather data. We can do this by adding tool call and response steps:

You are a helpful Weather Agent!
 
When the user asks about the weather, lookup information before responding.
 
<!-- Tool call step -->
<if cond={({lastElement}) => lastElement.outputType == 'tool-call'}>
  <toolcall tool="getWeather" params={
    location: ({lastElement}) => lastElement.output.location
  }>
    <script lang="python">
      import requests
      import json
 
      response = requests.get(f"https://api.openweathermap.org/data/2.5/weather?q={location}&appid=YOUR_API_KEY")
      return response.json()
    </script>
  </toolcall>
</if>
 
<!-- Response step-->
{({lastElement}) => lastElement.output.weather ? `Respond to the user's query based on the following real time weather data: ${lastElement.output.weather}` : `I didn't understand your question, please ask me about the weather in a specific location.`}
 
The user's query was: {({userInput}) => userInput.message} 

The above is interpreted by the AIML proxy as a 3 step agent flow:

This is a very basic example, with AIML you can create much more complex agents that include multi-turn, tool calling, code execution, loops, and more.

See the following for more complex examples:

On this page