Skillful Agents Quick Start Guide
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
Adding Your First Agent
You have two ways to add a Skillful Agent to your scene:
Method 1: Adding Through Code
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
Method 2: Using the Unity Inspector
Create an empty GameObject in your scene
Add the SkillfulAgent component through the Inspector
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
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
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
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:
Integrating with your game's UI system
Adding the Smart NPC component for voice capabilities
Creating more complex conversation flows
Implementing agent state management
Last updated