Create an Account

Visit stateset.com to create an account and access the StateSet Cloud platform.

Set up your API Key

Configure your API key as an environment variable for enhanced security and streamlined usage:

export STATESET_API_KEY=`<your-api-key-here>`

Install the StateSet SDK

Install the StateSet SDK for your preferred programming language:

npm install stateset-node --save

Create a New agents


import StateSet from "stateset-node";

const stateset = new StateSet({ apiKey: process.env.STATESET_API_KEY });

async function createAgent() {

  try {

    const agent = await stateset.agents.create({
      name: "My Agent",
      description: "My Agent Description",
    });

    console.log("Agent created:", agent);
  } catch (error) {
    console.error("Error creating agent:", error);
  }
}

createAgent();

Create a New Rule


import StateSet from "stateset-node";

const stateset = new StateSet({ apiKey: process.env.STATESET_API_KEY });

async function createRule() {

  try {

    const rule = await stateset.rules.create({
      name: "Always Respond Politely",
      description: "Always respond politely",
      agentId: "my-agent-id",
    });

    console.log("Rule created:", rule);
  } catch (error) {

    console.error("Error creating rule:", error);
  }
}

createRule();

Create a New Attribute


import StateSet from "stateset-node";

async function createAttribute() {

  try {

    const stateset = new StateSet({ apiKey: process.env.STATESET_API_KEY });

const attribute = await stateset.attributes.create({
  name: "Confident",
  description: "We assert the superiority of our product based on its unique properties and its research support. This authoritative stance is balanced with an approachable and informative manner.",
  value: 15,
  agentId: "my-agent-id",
});

console.log("Attribute created:", attribute);

  } catch (error) {
    console.error("Error creating attribute:", error);
  }
}

createAttribute();

Make Your First API Call

Here’s an example of how to use the StateSet SDK to create a new response:


import StateSet from "stateset-sdk";

const stateset = new StateSet({ apiKey: process.env.STATESET_API_KEY });

async function createResponse() {

  try {

    const response = await stateset.response.chat.completions.create({
    messages: [
      {
        role: "user",
        content: "Explain the importance of fast language models",
      },
    ],
    model: "llama3-8b-8192",
    });

    console.log("Response created:", response);

  } catch (error) {
    console.error("Error creating response:", error);
  }
}

createResponse();

Next Steps

Explore the StateSet ReSponse Dashboard to manage your responses

  • Check out the full API documentation for more advanced features
  • Join the StateSet community forum for support and to share ideas
  • Try integrating StateSet with your existing e-commerce or CRM systems