> For the complete documentation index, see [llms.txt](https://docs.gaming.skillfulai.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.gaming.skillfulai.io/unity-gaming-sdk/services/skillful-agents/quick-start.md).

# Quick Start

## `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:

```csharp
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\ <br>

   <figure><img src="/files/suiqOR4A3R06zj6smlnh" alt=""><figcaption></figcaption></figure>
3. Create a new script to interact with it:

```csharp
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:

```csharp
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:

```csharp
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:

```csharp
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

{% hint style="info" %}
The Smart NPC service can be coupled with Skillful Agents to provide your characters with natural, like-like voices, including your very own!
{% endhint %}
