Skip to content

Creating an agent

Updated

An agent starts as an AI Agent entity with one component it cannot do without: the AI Model, which decides what answers for it. You then give it a personality with an AI Persona and a way to be talked to, such as a dialog panel. This page builds a working agent in the editor, documents the AI Model and AI Persona, and shows how a script creates and adjusts agents at run time.

  • An agent is an entity with components. If entities, components and getComponent are new to you, read Components first.
  • Scripts hear an agent through a Signal Emitter on it, and compare events with EventType. See Scripting.
  • The AI agents overview explains turns, prompts and the conversation.
  1. Add an AI Agent. Create an AI Agent entity (ent-ai-agent) and place it where visitors will meet it, for example beside a statue. It comes with a Transform, an AI Model using the application’s default model, and an AI Flow.

  2. Choose the model. Leave the AI Model on its default, or pick another provider and model id in its inspector. See AI Model.

  3. Give it a persona. Add an AI Persona. Set name to what visitors should call it, and instructions to how it should behave: You are the friendly guide of this gallery. Answer in two or three sentences.

  4. Give it a dialog. Add an AI Dialog so visitors can type to it. It shows at all times by default; see Dialog and captions to open it only when the player walks up.

  5. Let scripts hear it. Add a Signal Emitter with a signal such as guide:ai.

  6. Try it. Enter play, walk up to the agent and type a message. The reply streams into the panel. To make it speak, add AI Text To Speech and turn on the dialog’s autoSpeak (see Speech).

An AI Agent entity also accepts a Signal Emitter, an Enable On Signal, a Don’t Unload, an Animation Timeline and an Animation Graph, and a Persistable for lasting memory (see Translation and memory).

The AI Model (comp-ai-model, AIModelComponent) names the model that answers for the agent. Every agent has exactly one, and it cannot be removed. It is also where a script finds the agent’s conversation, and the component that sends every AIAgent::… event to the agent’s Signal Emitters.

Prop Type Default Description
provider string 'Remote' Which service answers. 'Remote' is the model service the application provides; the inspector lists the other providers.
model string the provider’s default model The model id at that provider. It must not be empty. Any id the provider knows is accepted, including your own fine-tuned ones.
reasoningEffort 'none', 'minimal', 'low', 'medium', 'high', 'xhigh' or 'max' the model’s default How much the model reasons before answering. More effort gives more careful answers more slowly. Absent for models that do not reason.
  • Reasoning effort. For a model the built-in catalog knows, an omitted effort takes the model’s default, and setting an effort the model does not support with setProps throws. Check the model’s supported efforts first (see the last example on this page).
  • Changes take effect from the next turn.
Member What it does
getConversation() The agent’s shared conversation, or undefined in the editor, while the agent is inactive or its AI Model is off, or when the application offers no AI. See Scripting AI.
AIModelComponent.modelCatalog Static. Suggested model definitions by provider: { id, name?, reasoningEfforts, defaultReasoningEffort? }. Suggestions, not an allow-list.
AIModelComponent.supportedModels Static. The same model ids, as plain strings, by provider.
AIModelComponent.getModelDefinition(provider, model) Static. The catalog definition of that exact model, or undefined when the catalog does not know it.

The private Context methods of the AI Model (listContexts, createContext, setContext, getContext, clearContext, getGlobalContext) are covered in Translation and memory.

The AI Persona (comp-ai-persona, AIPersonaComponent) gives the agent a name and standing instructions. It is optional: without it, or while it is switched off, the agent still answers, it simply sends no instructions and takes its display name from the entity.

Prop Type Default Description
name string '' The display name, shown in the dialog header and in agent lists. At most 50 characters. Empty uses the entity’s name.
instructions string '' Standing instructions sent to the model with every turn: who the agent is, how it speaks, what it must not do. At most 4000 characters.
Member What it does
AIPersonaComponent.displayName(entity) Static. The name the runtime shows for that agent: its enabled Persona’s name, else the entity’s name, else Agent.

Editing the persona, or switching it on or off, applies from the next turn. A line of text under the name that should never reach the model belongs in the dialog’s subtitle instead.

The AI Flow (comp-ai-flow) is an editor view that draws how the agent’s AI components connect. A new agent has one. It does nothing in play, and removing or disabling it changes nothing about how the agent answers.

AgentInfo.jx
#pragma lifecycle(startup)
function startup() {
const guide = findEntity('Guide');
if (!guide) return log('No agent named Guide.');
const model = guide.getComponent(AIModelComponent);
log('Name shown to visitors:', AIPersonaComponent.displayName(guide));
log('Answered by:', model.props.provider, model.props.model);
const persona = guide.getComponent(AIPersonaComponent);
if (!persona || !persona.enabled) log('This agent has no active persona.');
}
  • AIPersonaComponent.displayName(guide) resolves the name exactly as the dialog does, so you never have to repeat the fallback rules.
  • model.props holds the AI Model’s current props. Reading props never contacts a model.
  • getComponent returns undefined for a component the entity lacks, and enabled tells whether a present one is switched on.
GuideMood.jx
#pragma lifecycle(startup)
// Scene: an AI Agent named "Guide" with an AI Persona.
// Other scripts emit 'museum/closing' a few minutes before closing time.
const DAY = 'You are the friendly guide of this gallery. Answer in two or three sentences.';
const CLOSING = DAY + ' The museum closes in five minutes: mention it kindly and point to the exit.';
function startup() {
const persona = findEntity('Guide').getComponent(AIPersonaComponent);
persona.setProps({ instructions: DAY });
on('museum/closing', () => {
persona.setProps({ instructions: CLOSING });
log('The guide now mentions closing time.');
});
}
  • The instructions are plain strings, so you can build them from constants and game state.
  • setProps changes only the props you pass. The new instructions apply from the next turn; a reply being written finishes with the old ones.
SpawnHelper.jx
#pragma lifecycle(startup)
// Scene: nothing special. The script builds a helper agent in front of the spawn point.
async function startup() {
const helper = new AIAgentEntity();
helper.name = 'Helper';
helper.position.set(0, 1.6, -2);
helper.addComponent(new AIPersonaComponent({
name: 'Helper',
instructions: 'You help new players learn the controls. Keep answers under 40 words.',
}));
helper.addComponent(new AIDialogComponent({ presentation: 'always', billboard: true }));
helper.addComponent(new SignalEmitterComponent({ signal: 'helper:ai' }));
scene.add(helper);
on('helper:ai', (event) => {
if (event.eventType === EventType.AIAgent.Response) log('Helper:', event.data.text);
});
}
  • new AIAgentEntity() already holds its AI Model, so the script only adds the capabilities it wants.
  • Each component takes its props in its constructor. The Signal Emitter’s signal is the name the listener uses.
  • scene.add(helper) puts the agent in the current scene; until then it is not live.
CarefulGuide.jx
#pragma lifecycle(startup)
// Scene: an AI Agent named "Guide". Players emit 'guide/detail' with true or false
// from a settings switch to choose quick or detailed answers.
let model;
function setEffort(effort) {
const { provider, model: id } = model.props;
const definition = AIModelComponent.getModelDefinition(provider, id);
if (definition && !definition.reasoningEfforts.includes(effort)) {
log(`${id} does not support "${effort}" reasoning; keeping its default.`);
return;
}
model.setProps({ reasoningEffort: effort });
}
function startup() {
model = findEntity('Guide').getComponent(AIModelComponent);
on('guide/detail', (detailed) => setEffort(detailed ? 'medium' : 'low'));
}
  • getModelDefinition reads the static catalog. It never loads a model or starts a conversation.
  • Checking reasoningEfforts first avoids the error setProps throws for an effort the model does not support.
  • A model the catalog does not know returns undefined; the script then lets setProps decide.
  • Using the conversation in the editor. getConversation() returns undefined while you edit. Check for it before calling send.
  • Forgetting the Signal Emitter. Without one on the agent, no AIAgent::… event reaches any script. Add it to the agent itself, not to another entity.
  • Putting display text in the instructions. Instructions go to the model on every turn. A tagline for the panel belongs in the dialog’s subtitle.
  • Very long instructions. Instructions past 4000 characters make the agent report an error. Move task-specific detail into a Skill, which the model loads only when it needs it.
  • Setting an unsupported reasoning effort. setProps({ reasoningEffort }) throws for an effort the model does not offer. Check getModelDefinition first.