AIML Docs

AIML Syntax

Learn about the core syntax features of AIML

AIML Syntax

AIML combines markdown with XML/JSX-style elements to create a powerful yet familiar syntax for building AI agents.

File Structure

An AIML file consists of these main components:

---
model: account/fireworks/model/deepseek-v3
otherSettings: value
---
 
{/* Comments can appear anywhere */}
 
System prompt text goes here, defining the agent's base behavior.
 
<element attribute="value">
    <child>Content</child>
</element>

Frontmatter

The frontmatter section defines file-level settings:

---
name: my-agent
 
# (optional) Default model settings for llm calls
model: account/fireworks/model/deepseek-v3
temperature: 0.7
maxTokens: 1000
---
PropTypeDefault
name
string
-
model?
string
account/fireworks/model/deepseek-v3
temperature?
number
0.7
maxTokens?
number
1000
topP?
number
0.9
topK?
number
100

System Prompts

Top level text is interpreted as a system prompt and a step in the workflow.

So this would be a system prompt and a step in the workflow.
 
<if condition={true}>
    this is a second step in the workflow.
</if>
 
And this is a third step in the workflow.

Comments

Comments use JSX-style syntax and are completely ignored but provide annotations for the developer within traces, in the editor and in the UI:

{/* Single-line comment */}
 
{/* 
  Multi-line
  comment
*/}

Elements

Elements are XML/JSX-style tags that define specific behaviors:

Basic Element Structure

<elementName attribute="value">
    <childElement>Content</childElement>
</elementName>

Dynamic Attributes

Attributes can be dynamic using JavaScript expressions:

<llm model={(state) => getModelForState(state)}>
    <prompt>
        {({userInput}) => processInput(userInput)}
    </prompt>
</llm>

Dynamic Attributes / Context Access

Anywhere in the file, you can access the context of the current step, input variables, output from the previous step, and the state of the workflow using function syntax:

Within a system prompt step we can have access to {({lastElement, userInput}) => 
    `Previous output: ${lastElement.output}
        Current input: ${userInput.message}`
}

Attributes likewise can be dynamic using the same syntax:

<llm model={(state) => state.datamodel.model}>
    ...
</llm>

Nested Elements

Elements can be nested to create complex behaviors:

<state>
    <llm>
        <if condition={({state}) => state.needsClarity}>
            <prompt>Please clarify your request.</prompt>
             <else>
                <prompt>Processing your request...</prompt>
            </else>
        </if>
       
    </llm>
</state>

State Management

AIML provides built-in state management:

<state initial={{step: 1}}>
    <llm>
        <instructions>
            {({state}) => `You are on step ${state.step}`}
        </instructions>
    </llm>
</state>

Control Flow

Control flow elements help manage the execution flow:

<if condition={({state}) => state.isReady}>
    <llm>
        <prompt>Ready to proceed</prompt>
    </llm>
    <else>
        <llm>
            <prompt>Please wait...</prompt>
        </llm>
    </else>
</if>

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:

Next Steps

On this page