Skip to main content

Overview

The general agent is the primary AI assistant for students, capable of web search, code execution, Canvas LMS integration, and memory management.

System Prompt Structure

The system prompt is built dynamically for each request:
export function buildSystemPrompt(ctx: AgentContext): string {
  return `You are a general assistant and coordinator for students at ${ctx.schoolName}.

🔍 YOUR CAPABILITIES:
- **Web search**: Search for current information beyond your knowledge cutoff
- **Code execution**: Run Python code for calculations, data processing, and analysis
- **Programmatic tool calling**: Chain multiple tool calls efficiently within code
- **Document processing**: Create and edit PowerPoint, Word, Excel, and PDF files
- **Canvas LMS search**: Search student's course content, assignments, and materials
- **Memory**: Remember important information about the user across conversations

🎯 CURRENT CONTEXT:
- **Date/Time**: ${ctx.currentDateTime} (${ctx.timezone})
- **School**: ${ctx.schoolName}
- **User**: ${ctx.fullName}
...`;
}

AgentContext Interface

The context object passed to all agent functions:
AgentContext
interface

Tool Configuration

Tools are configured with provider-specific options:
export function getGeneralAgentTools(ctx: AgentContext): Record<string, any> {
  return {
    // Code execution with programmatic tool calling
    code_execution: anthropic.tools.codeExecution_20250825(),

    // Memory tool with filesystem-like interface
    memory: anthropic.tools.memory_20250818({
      execute: async (action) => {
        return await executeMemoryCommand(ctx.userId, action);
      },
    }),

    // Location-aware web search
    web_search: anthropic.tools.webSearch_20250305({
      userLocation: {
        type: "approximate",
        city: ctx.city,
        country: ctx.country,
        region: ctx.region,
        timezone: ctx.timezone,
      },
    }),

    web_fetch: anthropic.tools.webFetch_20250910(),

    // Canvas LMS tools
    searchContent: searchContentTool,
    getClassAssignments: getClassAssignmentsTool,

    // Todo management
    getTodos: getTodosTool,
    createTodo: createTodoTool,
    updateTodo: updateTodoTool,
    deleteTodo: deleteTodoTool,

    // Study tools
    createStudySet: createStudySetTool,
  };
}

Programmatic Tool Calling Pattern

The agent is instructed to use Python for complex workflows:
import json
import asyncio

# Fetch all assignments
result = await getClassAssignments({})
assignments = json.loads(result)

# Filter and process
overdue = [a for a in assignments if is_overdue(a['due_at'])]
print(f"Found {len(overdue)} overdue assignments")
Web search automatically uses the user’s location:
web_search: anthropic.tools.webSearch_20250305({
  userLocation: {
    type: "approximate",
    city: ctx.city,        // e.g., "Boston"
    country: ctx.country,  // e.g., "USA"
    region: ctx.region,    // e.g., "Massachusetts"
    timezone: ctx.timezone // e.g., "America/New_York"
  }
})
This enables queries like “best coffee shops near me” to return location-relevant results.

Style Guidelines

From the system prompt:
  • Default style is natural, chatty, and playful, not formal
  • Keep tone topic-appropriate and matched to the user
  • Brief responses for casual conversation
  • Use emojis and casual punctuation if user does
  • Only in prose (not in section headers)
  • Don’t use Markdown sections/lists in casual chat unless asked
  • Use h1 (#) for section headers, not bold
  • Format structured responses with Markdown
  • Use LaTeX for math: $$x^2 + y^2 = z^2$$
  • Refer to classes by friendly name only (IDs are internal)
  • Convert technical formats (snake_case, UUIDs, paths) to plain language
  • Keep content appropriate for ages 13-18
  • Never say “I don’t have access to the internet” - use web_search!
  • Use tools proactively without asking permission
  • Check memory first to avoid asking redundant questions
  • Proactively save important facts to memory
  • Convert developer formats to plain language before answering

Skills Available

Documentation loaded into the code execution container:

canvas-assignments

Canvas assignment data structure, fields, date handling, common patterns

todo-management

Todo data structure, views, date types, Canvas linking, CRUD operations

User Classes Context

The agent receives a formatted list of the user’s classes:
ctx.classes.map((course) => `- ${course.name} (ID: ${course.id})`).join("\n")
Example output:
📚 USER'S CLASSES:
- Calculus I (ID: 12345)
- Introduction to Psychology (ID: 67890)
- English Composition (ID: 11111)

Implementation Reference

// apps/web/src/ai/agents/general.ts
export interface AgentContext {
  userId: string;
  fullName: string;
  schoolName: string;
  classes: CanvasCourse[];
  currentDateTime: string;
  timezone: string;
  chatId: string;
  country?: string;
  city?: string;
  region?: string;
}

export function buildSystemPrompt(ctx: AgentContext): string {
  // Full system prompt with capabilities, tools, and guidelines
}

export function getGeneralAgentTools(ctx: AgentContext): Record<string, any> {
  // Tool configuration with provider options
}

Next Steps

Available Tools

Explore all Canvas, Todo, and Study tools

Memory System

Learn about persistent user memory

Build docs developers (and LLMs) love