AgentGroup class for managing collaborative AI agent groups

This class represents a collection of AI agents that work together to handle complex tasks and workflows. Agent groups enable coordinated responses and shared knowledge across multiple specialized agents.

Features:

  • Group configuration management
  • Member agent coordination
  • Collaborative chat capabilities
  • Group branding/image management
  • Shared knowledge base

Agent groups are particularly useful for scenarios requiring multiple specialized agents to work together, such as:

  • Customer support teams with different expertise
  • Multi-step workflow automation
  • Complex problem-solving requiring diverse skills

Basic group setup:

import { AgentGroup } from 'mosaia-node-sdk';

// Create a support team group
const supportTeam = new AgentGroup({
name: 'Customer Support Team',
short_description: 'Collaborative support agents',
agents: ['billing-expert', 'tech-support', 'general-help']
});

// Add branding
const logo = new File(['...'], 'team-logo.png', { type: 'image/png' });
await supportTeam.image.upload(logo);

Using group chat:

// Engage with the agent group
const response = await supportTeam.chat.completions.create({
messages: [
{
role: 'user',
content: 'I have a billing question about my subscription.'
}
],
temperature: 0.7
});

console.log('Team response:', response.choices[0].message.content);

Hierarchy (View Summary)

Constructors

  • Creates a new AgentGroup instance

    Initializes an agent group with the provided configuration data and optional URI. The agent group represents a collection of AI agents that can work together.

    Parameters

    • data: Partial<AgentGroupInterface>

      Agent group configuration data

    • Optionaluri: string

      Optional URI path for the agent group endpoint. Defaults to '/group'

    Returns AgentGroup

    const agentGroup = new AgentGroup({
    name: 'Support Team',
    short_description: 'Customer support agents',
    agents: ['agent-1', 'agent-2']
    });

Accessors

  • get image(): Image

    Get the image functionality for this agent group

    This getter provides access to the agent group's image operations through the Image class. It allows for image uploads and other image-related operations specific to this agent group.

    Returns Image

    A new Image instance configured for this agent group

    const updatedGroup = await agentGroup.image.upload<AgentGroup, GetAgentGroupPayload>(file);
    
  • get chat(): Chat

    Get the chat functionality for this agent group

    This getter provides access to the group's collaborative chat capabilities through the Chat class. It enables coordinated responses from multiple agents within the group.

    Returns Chat

    A new Chat instance configured for this agent group

    Basic group chat:

    const response = await group.chat.completions.create({
    messages: [
    { role: 'user', content: 'I need help with a complex issue.' }
    ]
    });

    Advanced group chat with context:

    const response = await group.chat.completions.create({
    messages: [
    {
    role: 'system',
    content: 'You are a collaborative team of experts.'
    },
    {
    role: 'user',
    content: 'This problem requires both technical and billing expertise.'
    }
    ],
    temperature: 0.7,
    max_tokens: 200
    });

    console.log('Team response:', response.choices[0].message.content);

Methods

  • Like or unlike this agent group

    Toggles the like status of this agent group. If the group is already liked, it will be unliked, and vice versa.

    Returns Promise<AgentGroup>

    Promise that resolves to the updated agent group instance

    await agentGroup.like();
    console.log('Group liked:', agentGroup.liked);

    When API request fails

  • 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.

    Returns boolean

    True if the entity is active, false otherwise

    const user = new User(userData);
    if (user.isActive()) {
    // Perform operations with active user
    } else {
    console.log('User is inactive');
    }
  • 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:

    • Sending data to the API
    • Storing data in a database
    • Passing data between components
    • Debugging model state

    Returns AgentGroupInterface

    The model data as a plain object matching the interface type

    const user = new User({
    email: 'user@example.com',
    firstName: 'John'
    });

    const data = user.toJSON();
    console.log(data); // { email: '...', firstName: '...' }

    // Use with JSON.stringify
    const json = JSON.stringify(user);
  • Convert model instance to API payload

    This method creates a payload suitable for API requests by:

    • Converting the model to a plain object
    • Removing read-only fields (like 'id')
    • Ensuring proper data format for the API

    Returns Partial<AgentGroupInterface>

    A clean object suitable for API requests

    const user = new User({
    id: '123', // Will be removed from payload
    email: 'new@example.com',
    firstName: 'John'
    });

    const payload = user.toAPIPayload();
    // payload = { email: '...', firstName: '...' }
    // Note: 'id' is removed as it's read-only

    await apiClient.POST('/users', payload);
  • 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.

    Parameters

    Returns void

    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:

    1. Validates the model has an ID
    2. Sends current data to the API
    3. Updates local instance with API response

    Returns Promise<AgentGroupInterface>

    Promise resolving to the updated model data

    When model has no ID

    When API request fails

    const user = new User({
    id: '123',
    email: 'user@example.com'
    });

    // Update and save
    user.update({ firstName: 'John' });
    await user.save();

    Error handling:

    try {
    await user.save();
    } catch (error) {
    if (error.message.includes('ID is required')) {
    // Handle missing ID error
    } else {
    // Handle API errors
    }
    }
  • 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:

    1. Validates the model has an ID
    2. Sends DELETE request to the API
    3. Clears local instance data on success

    Returns Promise<void>

    Promise that resolves when deletion is successful

    When model has no ID

    When API request fails

    Basic deletion:

    const user = await users.get({}, 'user-id');
    if (user) {
    await user.delete();
    // User is now deleted and instance is cleared
    }

    Error handling:

    try {
    await user.delete();
    console.log('User deleted successfully');
    } catch (error) {
    if (error.message.includes('ID is required')) {
    console.error('Cannot delete - no ID');
    } else {
    console.error('Deletion failed:', error.message);
    }
    }