SkillfulAI
  • Skillful AI
    • Welcome
    • About us
    • Ecosystem
  • Web SDK
    • Overview
    • Getting Started
      • Installation
      • Quick Start
      • Authentication
    • SDK Reference
    • Templates
      • Telegram Bot Template
      • Express Server Template
        • API Reference
      • Discord Bot Template
        • ProActive Mode
      • Kick Stream Bot
        • Getting Started
          • Installation
          • Quick Start
        • Create Commands
        • Advanced Configurations
  • Unity Gaming SDK
    • Overview
    • Getting Started
      • Installation
      • Authentication
    • Services
      • Skillful Agents
        • Overview
        • Quick Start
        • Service Reference
      • Smart NPCs
        • Overview
        • Quick Start
        • Service Reference
      • Skillful Inference
        • Overview
        • Quick Start
        • Service Reference
          • Question Answering
          • Sentence Similarity
          • Speech Recognition
          • Text Classification
          • Text Generation
          • Text Summary
          • Text-To-Image
          • Zero Shot Classification
          • Translation (Localization)
    • Audio Recorder
    • Additional Utilities
Powered by GitBook
On this page
  • Skillful Agents Quick Start Guide
  • Adding Your First Agent
  • Building Interactive Conversations
  • Handling Multiple Agents
  • Adding Basic Error Handling
  • Next Steps

Skillful Agents Quick Start Guide

Let's get your first Skillful Agent up and running in Unity. This guide assumes you have the SDK imported and your API key configured.

Adding Your First Agent

You have two ways to add a Skillful Agent to your scene:

Method 1: Adding Through Code

Create a new script (e.g., ExampleAgent.cs) and add this basic implementation:

using SkillfulAI.Agents;
using UnityEngine;

public class ExampleAgent : MonoBehaviour
{
    private void Start()
    {
        // Add the Skillful Agent component to this GameObject
        SkillfulAgent agent = gameObject.AddComponent<SkillfulAgent>();
        
        // Select your agent by its dashboard name
        agent.SelectAgentByName("YourAgentNameHere");
        
        // Send your first message
        agent.SendMessage("Hello, who are you?", response => {
            // Log the AI's response
            Debug.Log(response.text);
        });
    }
}

Method 2: Using the Unity Inspector

  1. Create an empty GameObject in your scene

  2. Add the SkillfulAgent component through the Inspector

  3. Create a new script to interact with it:

using SkillfulAI.Agents;
using UnityEngine;

public class ExampleAgent : MonoBehaviour
{
    private SkillfulAgent agent;

    private void Start()
    {
        // Get the reference to the existing SkillfulAgent component
        agent = GetComponent<SkillfulAgent>();

        agent.SendMessage("Hello, who are you?", response => {
            // Log the AI's response
            Debug.Log(response.text);
        });
    }
}

Building Interactive Conversations

Let's create a more engaging conversation system:

public class InteractiveAgent : MonoBehaviour
{
    private SkillfulAgent agent;
    private bool conversationStarted = false;

    void Start()
    {
        // Setup the agent
        agent = gameObject.AddComponent<SkillfulAgent>();
        agent.SelectAgentByName("YourAgentNameHere");
    }

    void Update()
    {
        // Start conversation when player presses Space
        if (Input.GetKeyDown(KeyCode.Space) && !conversationStarted)
        {
            StartConversation();
        }
    }

    void StartConversation()
    {
        conversationStarted = true;
        agent.SendMessage("Hello! Can you tell me about yourself?", HandleResponse);
    }

    void HandleResponse(string response)
    {
        // Display the response (implement your UI logic here)
        Debug.Log($"Agent says: {response}");
        
        // You could trigger animations, update UI, or continue the conversation here
    }

    void ClearConversation() 
    {
        // You can start a new conversation by clearing the history
        agent.ClearConversation();
    }
}

Handling Multiple Agents

Here's how to work with multiple agents in your scene:

public class MultiAgentManager : MonoBehaviour
{
    private SkillfulAgent questAgent;
    private SkillfulAgent tutorialAgent;

    void Start()
    {
        // Setup quest agent
        questAgent = gameObject.AddComponent<SkillfulAgent>();
        questAgent.SelectAgentByName("QuestGiver");

        // Setup tutorial agent
        GameObject tutorialObj = new GameObject("TutorialAgent");
        tutorialAgent = tutorialObj.AddComponent<SkillfulAgent>();
        tutorialAgent.SelectAgentByName("TutorialGuide");
    }

    public void AskForQuest()
    {
        questAgent.SendMessage("What quests do you have available?", response => {
            Debug.Log($"Quest Agent: {response}");
        });
    }

    public void RequestTutorial()
    {
        tutorialAgent.SendMessage("Can you explain the basic controls?", response => {
            Debug.Log($"Tutorial Agent: {response}");
        });
    }
}

Adding Basic Error Handling

Ensure your agent interactions are robust:

public class SafeAgent : MonoBehaviour
{
    private SkillfulAgent agent;
    
    void Start()
    {
        agent = gameObject.AddComponent<SkillfulAgent>();
        
        if (TrySelectAgent("YourAgentNameHere"))
        {
            SendWelcomeMessage();
        }
    }
    
    bool TrySelectAgent(string agentName)
    {
        try
        {
            agent.SelectAgentByName(agentName);
            return true;
        }
        catch (System.Exception e)
        {
            Debug.LogError($"Failed to select agent: {e.Message}");
            return false;
        }
    }
    
    void SendWelcomeMessage()
    {
        agent.SendMessage("Hello!", response => {
            if (response.StartsWith("Error:"))
            {
                Debug.LogWarning($"Response error: {response}");
                return;
            }
            Debug.Log($"Agent response: {response}");
        });
    }
}

Next Steps

Now that you have your agent working, consider:

  1. Integrating with your game's UI system

  2. Adding the Smart NPC component for voice capabilities

  3. Creating more complex conversation flows

  4. Implementing agent state management

The Smart NPC service can be coupled with Skillful Agents to provide your characters with natural, like-like voices, including your very own!

PreviousOverviewNextService Reference

Last updated 1 month ago