Abstract
Runs the agent with the given input and returns the output.
The input (user prompt) to process
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: "..." }
Streams the agent's response for the given input. Useful for real-time UI updates or processing long responses chunk by chunk.
The input (user prompt) to process
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
}
Base class for creating AI agents with standardized input/output handling, tool management, and model integration.