In ResponseCX, an Agent is an autonomous conversational AI that can interact with your customers. You can customize its name, personality, and instructions to fit your business needs. Agents can be used in chat sessions to provide support, answer questions, and guide users.
Here’s how to create an agent using our SDKs with proper error handling:
Copy
Ask AI
import { StateSetClient } from 'stateset-node';import winston from 'winston';// Configure loggerconst logger = winston.createLogger({ level: 'info', format: winston.format.json(), transports: [new winston.transports.Console()]});// Initialize the clientconst client = new StateSetClient({ apiKey: process.env.STATESET_API_KEY});async function createAgent() { try { const agent = await client.agents.create({ name: "My SDK Agent", description: "This agent was created via the SDK.", type: "Conversational AI Agent", role: "E-commerce Assistant", instructions: "You are a friendly and helpful assistant for an online store.", goal: "Help customers find products and answer questions about their orders.", voice_model: "Asteria", }); logger.info('Agent created successfully', { agentId: agent.id, name: agent.name }); return agent; } catch (error) { logger.error('Failed to create agent', { error: error.message, stack: error.stack }); throw error; }}// Usageconst agent = await createAgent();
Copy
Ask AI
import { StateSetClient } from 'stateset-node';import winston from 'winston';// Configure loggerconst logger = winston.createLogger({ level: 'info', format: winston.format.json(), transports: [new winston.transports.Console()]});// Initialize the clientconst client = new StateSetClient({ apiKey: process.env.STATESET_API_KEY});async function createAgent() { try { const agent = await client.agents.create({ name: "My SDK Agent", description: "This agent was created via the SDK.", type: "Conversational AI Agent", role: "E-commerce Assistant", instructions: "You are a friendly and helpful assistant for an online store.", goal: "Help customers find products and answer questions about their orders.", voice_model: "Asteria", }); logger.info('Agent created successfully', { agentId: agent.id, name: agent.name }); return agent; } catch (error) { logger.error('Failed to create agent', { error: error.message, stack: error.stack }); throw error; }}// Usageconst agent = await createAgent();
Copy
Ask AI
import osimport loggingfrom stateset import StateSetClient# Configure logginglogging.basicConfig(level=logging.INFO)logger = logging.getLogger(__name__)# Initialize the clientclient = StateSetClient(api_key=os.getenv('STATESET_API_KEY'))def create_agent(): try: agent = client.agents.create( name="My SDK Agent", description="This agent was created via the SDK.", type="Conversational AI Agent", role="E-commerce Assistant", instructions="You are a friendly and helpful assistant for an online store.", goal="Help customers find products and answer questions about their orders.", voice_model="Asteria" ) logger.info(f'Agent created successfully: {agent.id} - {agent.name}') return agent except Exception as error: logger.error(f'Failed to create agent: {str(error)}') raise# Usageagent = create_agent()
Copy
Ask AI
require 'stateset'require 'logger'# Configure logginglogger = Logger.new(STDOUT)logger.level = Logger::INFO# Configure clientStateset.configure do |config| config.api_key = ENV['STATESET_API_KEY']enddef create_agent agent = Stateset::Agent.create( name: "My SDK Agent", description: "This agent was created via the SDK.", type: "Conversational AI Agent", role: "E-commerce Assistant", instructions: "You are a friendly and helpful assistant for an online store.", goal: "Help customers find products and answer questions about their orders.", voice_model: "Asteria" ) logger.info "Agent created successfully: #{agent.id} - #{agent.name}" agentrescue => error logger.error "Failed to create agent: #{error.message}" raiseend# Usageagent = create_agent
Copy
Ask AI
<?phprequire_once 'vendor/autoload.php';use Stateset\StateSetClient;use Monolog\Logger;use Monolog\Handler\StreamHandler;// Configure logging$logger = new Logger('stateset');$logger->pushHandler(new StreamHandler('php://stdout', Logger::INFO));// Initialize the client$client = new StateSetClient([ 'api_key' => $_ENV['STATESET_API_KEY']]);function createAgent($client, $logger) { try { $agent = $client->agents->create([ 'name' => 'My SDK Agent', 'description' => 'This agent was created via the SDK.', 'type' => 'Conversational AI Agent', 'role' => 'E-commerce Assistant', 'instructions' => 'You are a friendly and helpful assistant for an online store.', 'goal' => 'Help customers find products and answer questions about their orders.', 'voice_model' => 'Asteria' ]); $logger->info('Agent created successfully', [ 'agent_id' => $agent['id'], 'name' => $agent['name'] ]); return $agent; } catch (Exception $error) { $logger->error('Failed to create agent', [ 'error' => $error->getMessage() ]); throw $error; }}// Usage$agent = createAgent($client, $logger);?>
Copy
Ask AI
# Create an agent using cURLcurl -X POST "https://api.stateset.com/v1/agents" \ -H "Authorization: Bearer $STATESET_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "name": "My SDK Agent", "description": "This agent was created via the SDK.", "type": "Conversational AI Agent", "role": "E-commerce Assistant", "instructions": "You are a friendly and helpful assistant for an online store.", "goal": "Help customers find products and answer questions about their orders.", "voice_model": "Asteria" }' | jq '.'# Save the response to get the agent IDAGENT_ID=$(curl -s -X POST "https://api.stateset.com/v1/agents" \ -H "Authorization: Bearer $STATESET_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "name": "My SDK Agent", "description": "This agent was created via the SDK.", "type": "Conversational AI Agent", "role": "E-commerce Assistant", "instructions": "You are a friendly and helpful assistant for an online store.", "goal": "Help customers find products and answer questions about their orders.", "voice_model": "Asteria" }' | jq -r '.id')echo "Agent created with ID: $AGENT_ID"
Agent Properties:
name (string, required): The name of the agent.
description (string): A short description of the agent.
type (string): The type of agent.
role (string): The role you want the agent to adopt (e.g., “Customer Support Agent”).
instructions (string): Specific instructions for the agent on how to behave. This is where you define its personality and operational guidelines.
goal (string): The primary objective for the agent in conversations.
voice_model (string): The voice model for text-to-speech.
const goodInstructions = `You are a friendly customer support agent for Acme Store.- Always greet customers warmly- Ask clarifying questions before providing solutions- Never share customer personal information- Escalate to human support for refund requests over $100`;const poorInstructions = "Help customers";