Creates a new Agent instance
Initializes an agent with the provided configuration data and optional URI. The agent represents an AI entity that can perform intelligent tasks.
Agent configuration data
Optionaluri: stringOptional URI path for the agent endpoint. Defaults to '/agent'
Get the chat functionality for this agent
This getter provides access to the agent's chat capabilities through the Chat class. It allows for chat completions and other chat-related operations specific to this agent.
A new Chat instance configured for this agent
Basic chat:
const response = await agent.chat.completions.create({
messages: [
{ role: 'user', content: 'Hello!' }
]
});
Advanced chat configuration:
const response = await agent.chat.completions.create({
messages: [
{ role: 'system', content: 'You are a helpful assistant.' },
{ role: 'user', content: 'What can you help me with?' }
],
temperature: 0.7,
max_tokens: 150,
stream: false
});
console.log('Response:', response.choices[0].message.content);
Get the image functionality for this agent
This getter provides access to the agent's image operations through the Image class. It allows for image uploads and other image-related operations specific to this agent.
A new Image instance configured for this agent
Get the tasks collection for this agent
This getter provides access to the agent's tasks collection, allowing you to manage tasks associated with this agent.
Tasks collection for managing agent tasks
Get the logs collection for this agent
This getter provides access to the agent's logs collection, allowing you to manage conversation logs and interaction history for this agent.
Logs collection for managing agent logs
Like or unlike this agent
Toggles the like status of this agent. If the agent is already liked, it will be unliked, and vice versa.
Promise that resolves to the updated agent instance
Fork this agent
Creates a copy of this agent that can be independently modified. Useful for creating variations of existing agents.
Optionaloptions: { generate_system_message?: boolean }Optional fork options
Optionalgenerate_system_message?: booleanWhether to generate a new system message
Promise resolving to the forked agent instance
Check if the entity is active
This method checks the active status of the entity. Most entities in the system can be active or inactive, which affects their availability and usability in the platform.
True if the entity is active, false otherwise
Convert model instance to interface data
This method serializes the model instance to a plain object that matches the interface type. This is useful for:
The model data as a plain object matching the interface type
Convert model instance to API payload
This method creates a payload suitable for API requests by:
A clean object suitable for API requests
Update model data with new values
This method updates the model's data and instance properties with new values. It performs a shallow merge of the updates with existing data, allowing for partial updates of the model's properties.
Object containing properties to update
const user = new User({
email: 'old@example.com',
firstName: 'John'
});
// Update multiple properties
user.update({
email: 'new@example.com',
lastName: 'Doe'
});
// Save changes to API
await user.save();
This method only updates the local model instance. To persist changes to the API, call save after updating.
Save the model instance to the API
This method persists the current state of the model to the API using a PUT request. It requires the model to have an ID (existing instance). For new instances, use the collection's create method instead.
The method:
Promise resolving to the updated model data
Delete the model instance from the API
This method permanently deletes the model instance from the API and clears the local data. This operation cannot be undone.
The method:
Promise that resolves when deletion is successful
Agent class for managing AI agent instances in the Mosaia SDK
This class represents an AI agent that can perform tasks, handle conversations, and execute workflows. Agents are the core AI entities in the platform, providing natural language understanding and task automation capabilities.
Features:
Remarks
Agents can be configured with different models, temperature settings, and system prompts to customize their behavior. They can also be assigned tools to extend their capabilities.
Example
Basic agent usage:
Example
Using chat capabilities: