Table of Contents

Method Think

Namespace
GrindFest
Assembly
GrindFest.dll

Think(string, bool)

Uses LLM to think with conversation memory. Returns a task that resolves to the result when ready.

public Task<string> Think(string prompt, bool stripThinkingProcess = true)

Parameters

prompt string

The prompt to send to the LLM

stripThinkingProcess bool

Whether to automatically remove <think>...</think> tags from the response. Default is true.

Returns

Task<string>

A task that resolves to the result string when ready

Examples

Basic usage with ContinueOnMainThread for Unity API calls:

void Update()
{
    if (Input.GetKeyDown(KeyCode.F1))
    {
        Think("Tell me a joke about skeletons").ContinueOnMainThread(result => {
            Say(result);
        });
    }
}

Conversation memory in action:

// First call - AI learns about the situation
Think("I'm in a dangerous dungeon with low health").ContinueOnMainThread(response => {
    Say(response); // AI might say "You should be careful and look for healing"
});

// Later call - AI remembers the previous context
Think("I found a health potion, what should I do?").ContinueOnMainThread(response => {
    Say(response); // AI will remember you have low health and suggest drinking it
});

// Reset conversation when changing strategy
ClearThoughts();
Think("I'm fully healed now, time for combat!").ContinueOnMainThread(response => {
    Say(response); // Fresh start without the low health context
});

Remarks

You need to connect LLM in the settings.

This method maintains conversation history, allowing the AI to remember previous interactions. Each call adds to the conversation context, enabling more coherent multi-turn conversations. Use ClearThoughts() to reset conversation history when needed.

Important: Always use ContinueOnMainThread() instead of ContinueWith() when you need to call Unity APIs like Say(), Debug.Log(), or other Unity methods in the continuation. This ensures the continuation runs on Unity's main thread.

Think<T>(string, Dictionary<string, string[]>)

Uses LLM to get structured responses based on a C# class schema with conversation memory. The AI will return data that matches the structure of the specified type.

public Task<T> Think<T>(string prompt, Dictionary<string, string[]> dynamicEnums = null) where T : class

Parameters

prompt string

The prompt to send to the LLM

dynamicEnums Dictionary<string, string[]>

Optional dictionary mapping property names to their allowed enum values for runtime constraints

Returns

Task<T>

A task that resolves to an instance of T, or null if parsing failed

Type Parameters

T

The type to structure the response as (must be a class with public properties)

Examples

Basic usage with static enum constraints:

// Define a response structure with enum
public enum BattleAction { Attack, Defend, Flee, Heal }

public class BattleDecision 
{
    [JsonDescription("Your thinking process behind the decision")]
    [JsonRequired]
    public string ThinkingProcess; // AI works much better if it can explain what it's doing
    [JsonRequired]
    public BattleAction Action;    // Enum automatically constrains values
    public string Target;          // Enemy name to target
}

// Use it in your bot
var decision = await Think<BattleDecision>("What should I do in this battle?");
if (decision != null)
{
    Say($"I will {decision.Action} because {decision.ThinkingProcess}");
    if (decision.Target != null) Say($"Targeting: {decision.Target}");
}

Advanced usage with dynamic enum constraints:

// Dynamic enum based on actual nearby enemies
var enemies = FindNearestEnemies().Select(e => e.name).ToArray();
var dynamicEnums = new Dictionary<string, string[]> 
{
    ["Target"] = enemies.Length > 0 ? enemies : new[] { "None" }
};

var decision = await Think<BattleDecision>("Choose your target", dynamicEnums); // AI can only choose from actual enemy names present

Conversation memory with structured responses:

// First structured decision - AI learns about the battle
var decision1 = await Think<BattleDecision>("We're facing 3 orcs, what should I do?");
// AI might decide to Attack with reasoning about the threat level

// Follow-up decision - AI remembers the context
var decision2 = await Think<BattleDecision>("One orc is dead, two remain. What now?");
// AI will remember there were originally 3 orcs and adjust strategy accordingly

// Clear context for new battle
ClearThoughts();
var decision3 = await Think<BattleDecision>("New battle started, what should I do?");
// Fresh decision without previous battle context

Remarks

This method maintains conversation history, allowing the AI to remember previous structured interactions. Each call adds to the conversation context, enabling more coherent decision-making over time. Use ClearThoughts() to reset conversation history when needed.