Class Agent<TInput, TOutput>Abstract

Base class for creating AI agents with standardized input/output handling, tool management, and model integration.

Type Parameters

  • TInput = any

    The type of input the agent accepts

  • TOutput = any

    The type of output the agent produces

Constructors

Methods

Constructors

Methods

  • Runs the agent with the given input and returns the output.

    Parameters

    • input: TInput

      The input (user prompt) to process

    Returns Promise<TOutput>

    Promise resolving to the processed output

    // Simple text input/output
    const agent = new SimpleAgent();
    const response = await agent.run("What is TypeScript?");
    console.log(response); // "TypeScript is a typed superset of JavaScript..."

    // Structured input/output
    const greetingAgent = new GreetingAgent();
    const response = await greetingAgent.run({
    userName: "Alice",
    userMood: "happy",
    dayOfWeek: "Saturday"
    });
    console.log(response); // { greeting: "Hello Alice!", moodResponse: "..." }

    If input validation fails or processing errors occur

  • Streams the agent's response for the given input. Useful for real-time UI updates or processing long responses chunk by chunk.

    Parameters

    • input: TInput

      The input (user prompt) to process

    Returns Promise<StreamResult<TOutput>>

    Promise resolving to an enhanced stream result containing the output stream

    // Simple text streaming
    const agent = new SimpleAgent();
    const { stream } = await agent.stream("What is TypeScript?");
    for await (const chunk of stream) {
    process.stdout.write(chunk); // Chunks: "Type" ... "Script" ... "is a" ...
    }

    // Structured output streaming
    const greetingAgent = new GreetingAgent();
    const { stream } = await greetingAgent.stream({
    userName: "Alice",
    userMood: "happy"
    });
    for await (const chunk of stream) {
    console.log(chunk); // Partial objects that build up the complete response
    }

    If input validation fails or processing errors occur

MMNEPVFCICPMFPCPTTAAATR