For the complete documentation index, see llms.txt. This page is also available as Markdown.

Class-Based Agents

Build reusable, encapsulated agents by extending the AiAgent class instead of configuring everything inline with the aiAgent() BIF.

For simple workflows, aiAgent() is perfect. For larger applications, teams often prefer encapsulated agent classes that bundle tools, memory, model settings, and conventions in one reusable component.

This page shows how to create agents by extending bxModules.bxai.models.runnables.AiAgent.

Why Use Class-Based Agents?

Use class-based agents when you want:

  • Encapsulation: Keep behavior, tools, and defaults in one class

  • Reusability: Instantiate the same agent across modules and apps

  • Testability: Unit-test agent setup methods independently

  • Consistency: Standardize model params, guardrails, and instructions

  • Composition: Build specialized agent families via inheritance

Minimal Class-Based Agent

// agents/SupportAgent.bx
class extends="bxModules.bxai.models.runnables.AiAgent" {

    function init() {
        super.init(
            name        : "SupportAgent",
            description : "Customer support specialist",
            instructions: "Resolve support issues clearly and politely"
        )

        return this
    }

}

Usage:

Encapsulated Agent with Model, Memory, and Tools

Registering Class-Based Agents at Application Startup

This pattern keeps agent lifecycle management in one place:

Resolve and run:

Base Class + Specialized Agents

You can define a common base agent and extend it:

Sub-Agents Inside an Encapsulated Agent

Class-based agents also work well for delegation:

Testing Pattern

Keep setup deterministic and verify config in tests:

When to Use aiAgent() vs Class-Based

Approach
Best For

aiAgent() BIF

Quick scripts, prototypes, and inline composition

Class-based (extends="...AiAgent")

Reusable domain agents, large apps, shared conventions

Last updated