Skip to content

Assistants ​

Overview ​

Assistants in LlmTornado are AI agents that can use tools, access files, and maintain persistent conversation threads. They provide a higher-level abstraction for building complex AI applications with state management, tool calling, and file search capabilities. Assistants are perfect for building chatbots, virtual assistants, and automated workflows.

Quick Start ​

csharp
using LlmTornado;
using LlmTornado.Assistants;
using LlmTornado.Chat.Models;

TornadoApi api = new TornadoApi("your-api-key");

// Create an assistant
HttpCallResult<Assistant> result = await api.Assistants.CreateAssistantAsync(
    new CreateAssistantRequest(
        ChatModel.OpenAi.Gpt4.O241120,
        "My Assistant",
        "A helpful coding assistant",
        "You are a helpful assistant that helps with programming questions."));

Console.WriteLine($"Assistant created with ID: {result.Data.Id}");

Prerequisites ​

  • The LlmTornado package installed
  • A valid API key with assistants access
  • Understanding of Chat Basics
  • Familiarity with Threads for conversations

Basic Usage ​

Create a Simple Assistant ​

csharp
HttpCallResult<Assistant> response = await api.Assistants.CreateAssistantAsync(
    new CreateAssistantRequest(
        ChatModel.OpenAi.Gpt4.O241120, 
        "Customer Support Bot",
        "Helps with customer inquiries",
        "You are a friendly customer support assistant."));

Assistant assistant = response.Data;
Console.WriteLine($"Created assistant: {assistant.Name}");

List All Assistants ​

csharp
HttpCallResult<ListResponse<Assistant>> response = 
    await api.Assistants.ListAssistantsAsync();

foreach (Assistant assistant in response.Data.Items)
{
    Console.WriteLine($"{assistant.Id}: {assistant.Name}");
}

Retrieve an Assistant ​

csharp
HttpCallResult<Assistant> response = 
    await api.Assistants.GetAssistantAsync("assistant_id_here");

Assistant assistant = response.Data;
Console.WriteLine($"Name: {assistant.Name}");
Console.WriteLine($"Model: {assistant.Model}");
Console.WriteLine($"Instructions: {assistant.Instructions}");

Update an Assistant ​

csharp
HttpCallResult<Assistant> response = await api.Assistants.ModifyAssistantAsync(
    "assistant_id",
    new ModifyAssistantRequest
    {
        Name = "Updated Assistant Name",
        Instructions = "New instructions for the assistant"
    });

Delete an Assistant ​

csharp
HttpCallResult<bool> result = await api.Assistants.DeleteAssistantAsync("assistant_id");
Console.WriteLine($"Deleted: {result.Data}");

Advanced Usage ​

Assistant with Function Tools ​

Create an assistant that can call functions:

csharp
HttpCallResult<Assistant> response = await api.Assistants.CreateAssistantAsync(
    new CreateAssistantRequest(
        null,
        "Weather Assistant",
        "Provides weather information",
        "You are a helpful assistant with the ability to check weather.")
    {
        Tools = new List<AssistantTool>
        {
            new AssistantToolFunction(new ToolFunctionConfig(
                "get_weather",
                "Get current temperature for a given city",
                new
                {
                    type = "object",
                    properties = new
                    {
                        location = new
                        {
                            type = "string",
                            description = "City and Country"
                        }
                    },
                    required = new List<string> {"location"},
                    additionalProperties = false
                }
            ))
        }
    });

Console.WriteLine($"Function-enabled assistant: {response.Data.Id}");

Create an assistant with file search capabilities:

csharp
// First, upload a file
HttpCallResult<TornadoFile> fileResult = await api.Files.Upload(
    "knowledge_base.pdf", 
    FilePurpose.Assistants);

// Create vector store with the file
HttpCallResult<VectorStore> vectorStore = await api.VectorStores.Create(
    new CreateVectorStoreRequest
    {
        Name = "Knowledge Base",
        FileIds = new List<string> { fileResult.Data.Id }
    });

// Create assistant with file search
HttpCallResult<Assistant> response = await api.Assistants.CreateAssistantAsync(
    new CreateAssistantRequest(
        ChatModel.OpenAi.Gpt4.O241120,
        "Knowledge Assistant",
        "Answers questions from documents",
        "You help users find information in uploaded documents.")
    {
        Tools = new List<AssistantTool>
        {
            new AssistantToolFileSearch()
        },
        ToolResources = new ToolResources
        {
            FileSearch = new FileSearchToolResources
            {
                VectorStoreIds = new List<string> { vectorStore.Data.Id }
            }
        }
    });

Assistant with Code Interpreter ​

Enable code execution capabilities:

csharp
HttpCallResult<Assistant> response = await api.Assistants.CreateAssistantAsync(
    new CreateAssistantRequest(
        ChatModel.OpenAi.Gpt4.O241120,
        "Data Analyst",
        "Analyzes data and creates visualizations",
        "You are a data analyst that can write and execute Python code.")
    {
        Tools = new List<AssistantTool>
        {
            new AssistantToolCodeInterpreter()
        }
    });

Best Practices ​

  1. Clear Instructions - Provide detailed system instructions
  2. Tool Selection - Only enable tools the assistant needs
  3. Resource Management - Clean up unused assistants
  4. Metadata Usage - Tag assistants with identifying metadata
  5. Version Control - Track assistant configurations

Common Issues ​

Assistant Not Responding ​

  • Solution: Check if the model is available and instructions are clear
  • Prevention: Test with simple queries first

Tool Calls Failing ​

  • Solution: Verify tool definitions and function implementations
  • Prevention: Validate tool schemas before deployment

File Search Not Working ​

  • Solution: Ensure files are uploaded and vector store is attached
  • Prevention: Verify file formats and content

API Reference ​

CreateAssistantRequest ​

  • ChatModel Model - Model to use
  • string Name - Assistant name
  • string Description - Short description
  • string Instructions - System instructions
  • List<AssistantTool> Tools - Available tools
  • ToolResources ToolResources - Tool-specific resources

Assistant ​

  • string Id - Unique identifier
  • string Name - Assistant name
  • string Model - Model being used
  • string Instructions - System instructions
  • List<AssistantTool> Tools - Configured tools
  • Dictionary<string, string> Metadata - Custom metadata

AssistantTool Types ​

  • AssistantToolFunction - Custom function calling
  • AssistantToolFileSearch - Document search
  • AssistantToolCodeInterpreter - Code execution