Class AIAgent<TInput, TOutput>Abstract

Base class for AI Agents in the Stratix framework.

An AI Agent is an aggregate root that encapsulates AI capabilities, manages its own state, memory, and execution context.

class CustomerSupportAgent extends AIAgent<SupportTicket, SupportResponse> {
readonly name = 'Customer Support Agent';
readonly description = 'Handles customer support tickets';
readonly capabilities = [AgentCapabilities.CUSTOMER_SUPPORT, 'ticket_routing'];
readonly model = {
provider: 'anthropic',
model: 'claude-3-sonnet',
temperature: 0.7,
maxTokens: 2000
};

async execute(ticket: SupportTicket): Promise<AgentResult<SupportResponse>> {
// Implementation
}
}

Type Parameters

  • TInput

    The type of input the agent accepts

  • TOutput

    The type of output the agent produces

Hierarchy (View Summary)

Accessors

  • get createdAt(): Date

    Gets the timestamp when this entity was created.

    Returns Date

  • get updatedAt(): Date

    Gets the timestamp when this entity was last updated.

    Returns Date

Constructors

Methods

  • Protected

    Main execution method for the agent. Must be implemented by concrete agent classes.

    This method is called internally by executeWithEvents() and should contain the core agent logic. Domain events are automatically recorded by the wrapper.

    Parameters

    • input: TInput

      The input data for the agent

    Returns Promise<AgentResult<TOutput>>

    A promise resolving to the agent result

  • Executes the agent with automatic domain event recording. This is the public method that should be called by orchestrators and clients.

    Records the following events:

    • AgentExecutionStarted: When execution begins
    • AgentExecutionCompleted: When execution succeeds
    • AgentExecutionFailed: When execution fails

    Parameters

    • input: TInput

      The input data for the agent

    Returns Promise<AgentResult<TOutput>>

    A promise resolving to the agent result

  • Optional hook called when an error occurs

    Parameters

    • error: Error

      The error that occurred

    Returns Promise<void>

  • Sets the execution timeout for this agent

    Parameters

    • ms: number

      Timeout in milliseconds

    Returns void

  • Stores a value in agent memory

    Parameters

    • key: string

      The key to store under

    • value: unknown

      The value to store

    • type: "short" | "long" = 'short'

      Memory type: 'short' for session, 'long' for persistent

    Returns Promise<void>

  • Retrieves a value from agent memory

    Parameters

    • key: string

      The key to retrieve

    Returns Promise<unknown>

    The stored value, or null if not found

  • Searches memory semantically

    Parameters

    • query: string

      The search query

    • limit: number = 5

      Maximum results to return

    Returns Promise<unknown[]>

    Array of relevant values

  • Removes a value from memory

    Parameters

    • type: "short" | "long" | "all" = 'short'

      Type of memory to clear

    Returns Promise<void>

  • Checks if this agent has a specific capability

    Parameters

    • capability: string

      The capability to check for

    Returns boolean

  • Gets agent metadata as a plain object

    Returns {
        id: string;
        name: string;
        description: string;
        version: string;
        capabilities: string[];
        model: ModelConfig;
    }

  • Protected

    Records a tool used event Should be called by subclasses when they use tools

    Parameters

    • toolName: string

      Name of the tool used

    • toolArguments: Record<string, unknown>

      Arguments passed to the tool

    • OptionaltoolResult: unknown

      Result from the tool execution

    Returns void

  • Protected

    Records a domain event that occurred within this aggregate. Events are stored internally and can be retrieved later for publishing.

    Parameters

    Returns void

    this.record({
    occurredAt: new Date(),
    userId: this.id.value,
    email: 'user@example.com'
    });
  • Retrieves and clears all domain events recorded by this aggregate. This is typically called after the aggregate is persisted, to publish the events.

    Returns DomainEvent[]

    An array of domain events

    await repository.save(order);
    const events = order.pullDomainEvents();
    await eventBus.publish(events);
  • Compares this entity with another for equality based on identity. Two entities are equal if they have the same ID and are of the same type.

    Parameters

    • other: Entity<"AIAgent">

      The other entity to compare with

    Returns boolean

    true if the entities are equal, false otherwise

Properties

name: string

Human-readable name of the agent

description: string

Description of what the agent does

version: AgentVersion
capabilities: string[]

Capabilities this agent has

LLM model configuration

_context?: AgentContext

Current execution context

_memory?: AgentMemory
retryConfig?: RetryConfig
timeoutMs?: number