/outputai:output-dev-agent-classfrom outputai
Documents the Agent class for multi-step tool loops, conversation history, streaming progress, and reusable LLM agents with structured output.
Ships in outputai. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
The Agent class uses an internal AI SDK ToolLoopAgent through composition with Output prompt files and the skills system. It does not inherit from ToolLoopAgent. Use it when you need multi-step tool execution, conversation history, or a reusable agent instance. For single-shot LLM calls without tools, generateText is simpler.
aiSdk.Output.object()messageStoreonChunkAgent and generateTextimport { Agent, aiSdk } from '@outputai/core/llm';
import type { MessageStore } from '@outputai/core/llm';
import { z } from '@outputai/core';
Agent comes from @outputai/core/llm. Use aiSdk.Output for structured output. Import z from @outputai/core (never from zod directly). MessageStore is the type for a pluggable getMessages / addMessages store; implement it yourself.
The prompt file is loaded and rendered at construction time. Variables and tools are fixed at construction. Skills and maxSteps come from the prompt file. The agent is ready to call generate(), generateWithStreaming(), or stream() immediately.
const agent = new Agent( {
prompt: 'writing_assistant@v1',
variables: {
content_type: input.contentType,
focus: input.focus,
content: input.content
},
output: aiSdk.Output.object( { schema: reviewSchema } )
} );
| Option | Type | Default | Description |
|---|---|---|---|
prompt | string | (required) | Prompt file name (e.g. 'writing_assistant@v1') |
promptDir | string | - | Override the stack-resolved prompt directory |
variables | PromptVariables | - | Template variables rendered at construction |
tools | AI SDK tools | - | Caller tools; merged with prompt YAML tools (load_skill last) |
stopWhen | function or function[] | - | Custom stop condition (overrides prompt maxSteps when tools exist) |
output | aiSdk.Output | - | Structured output spec (e.g. aiSdk.Output.object({ schema })) |
messageStore | MessageStore | - | Pluggable store for multi-turn history |
Run the agent and return when complete:
const result = await agent.generate();
console.log( result.text ); // Generated text
console.log( result.output ); // Structured output (when using aiSdk.Output.object)
console.log( result.usage ); // Token counts
The result has the same shape as generateText: text, result (alias for text), output, usage, finishReason, toolCalls, etc.
Extend the conversation with extra messages:
const result = await agent.generate( {
messages: [ { role: 'user', content: 'Focus on the introduction section.' } ]
} );
Messages are appended after the initial prompt messages (and any message-store history). You can also pass abortSignal and toolChoice.
Use generateWithStreaming() when you need progress callbacks and a complete result:
const result = await agent.generateWithStreaming( {
onChunk( { chunk } ) {
if ( chunk.type === 'text-delta' ) {
process.stdout.write( chunk.text );
}
}
} );
The method behaves like generate() while using streaming internally. It returns the complete response, rejects on stream errors, and automatically appends messages to the configured message store. It accepts the same messages, abortSignal, and toolChoice as generate(), plus onChunk. Prefer it over stream() in Temporal activity steps unless direct access to the stream result is required.
Use stream() when direct control over textStream or stream is required. It accepts the same messages, abortSignal, and toolChoice as generate(), plus onChunk, onEnd, and onError:
const stream = await agent.stream();
for await ( const chunk of stream.textStream ) {
process.stdout.write( chunk );
}
Like streamText, the stream result provides textStream and stream iterables, plus promise-based properties (text, usage, finishReason) that resolve on completion.
stream() appends messages to the message store in its wrapped onEnd when finishReason is not 'error'. See output-dev-llm-streaming for streaming and error-handling guidance.
Use aiSdk.Output.object() to get typed responses:
const reviewSchema = z.object( {
issues: z.array( z.string() ).describe( 'List of issues found' ),
suggestions: z.array( z.string() ).describe( 'Actionable suggestions' ),
score: z.number().describe( 'Quality score 0-100' ),
summary: z.string().describe( 'Brief overall assessment' )
} );
const agent = new Agent( {
prompt: 'writing_assistant@v1',
variables: { content_type: 'documentation', focus: 'clarity', content: markdownContent },
output: aiSdk.Output.object( { schema: reviewSchema } )
} );
const { output } = await agent.generate();
// output: { issues: string[], suggestions: string[], score: number, summary: string }
Use .describe() on schema fields instead of .min()/.max() for number constraints. Anthropic does not support minimum/maximum JSON Schema constraints in tool definitions.
By default, Agent is stateless. Each generate() call starts fresh with only the initial prompt messages. Pass a messageStore to maintain history across calls:
import { Agent } from '@outputai/core/llm';
import type { MessageStore } from '@outputai/core/llm';
const messages: Parameters<MessageStore['addMessages']>[0] = [];
const messageStore: MessageStore = {
getMessages: () => messages,
addMessages: incoming => {
messages.push( ...incoming );
}
};
const chatbot = new Agent( {
prompt: 'chatbot@v1',
messageStore
} );
const r1 = await chatbot.generate( {
messages: [ { role: 'user', content: 'Hello, tell me about Output.' } ]
} );
// r1.text: "Output is an AI framework for..."
const r2 = await chatbot.generate( {
messages: [ { role: 'user', content: 'How does it handle retries?' } ]
} );
// r2 sees the full history from r1
MessageStore is:
interface MessageStore {
getMessages(): ModelMessage[] | Promise<ModelMessage[]>;
addMessages( messages: ModelMessage[] ): void | Promise<void>;
}
ModelMessage is an AI SDK type available through the aiSdk namespace or as an import from ai. There is no built-in store. Implement the interface in memory for a single process, or with your database for durable history.
In workflow steps, construct a new Agent per invocation. Variables come from the step input:
import { step, z } from '@outputai/core';
import { Agent, aiSdk } from '@outputai/core/llm';
const reviewSchema = z.object( {
summary: z.string().describe( 'Brief assessment' ),
issues: z.array( z.string() ).describe( 'Problems found' ),
suggestions: z.array( z.string() ).describe( 'Improvements' ),
score: z.number().describe( 'Quality score 0-100' )
} );
export const reviewContent = step( {
name: 'reviewContent',
description: 'Review technical content using Agent with structured output',
inputSchema: z.object( {
content: z.string().describe( 'The content to review' ),
content_type: z.string().describe( 'Type of content' ),
focus: z.string().describe( 'Review focus areas' )
} ),
outputSchema: reviewSchema,
fn: async input => {
const agent = new Agent( {
prompt: 'writing_assistant@v1',
variables: input,
output: aiSdk.Output.object( { schema: reviewSchema } )
} );
const { output } = await agent.generate();
return output;
}
} );
This is the standard pattern. Each step invocation is independent, and Agent construction is cheap.
List skill paths in the prompt frontmatter. See output-dev-skill-file for the full skills guide.
generateText | Agent | |
|---|---|---|
| Best for | Single-shot LLM calls | Multi-step tool loops |
| Tools | Supported | Supported |
| Skills | Supported | Supported |
| Conversation history | Manual | Built-in with messageStore |
| Reusable instance | No (function call) | Yes (construct once, call many) |
| Structured output | aiSdk.Output.object() | aiSdk.Output.object() |
Start with generateText. Move to Agent when you need conversation state or a reusable instance with a fixed configuration.
import { generateText } from '@outputai/core/llm';
const { result } = await generateText( {
prompt: 'generate_summary@v1',
variables: {
company_name: input.name,
website_content: input.websiteContent
}
} );
Agent from @outputai/core/llm (not from ai directly)z from @outputai/core (never from zod)prompts/ folder{{ variable }} placeholders in the promptmaxSteps when skills or tools need a ceiling other than 10aiSdk.Output.object({ schema }) uses .describe() not .min()/.max() on numbersmessageStore is only used when multi-turn history is neededfn (not at module level) for workflow stepsgenerateWithStreaming() when callbacks are sufficientoutput-dev-skill-file - Creating skill files for agentsoutput-dev-llm-streaming - Streaming progress and Temporal-safe error handlingoutput-dev-prompt-file - Creating .prompt files used by agentsoutput-dev-step-function - Using agents in step functionsoutput-dev-types-file - Defining Zod schemas for structured outputoutput-dev-workflow-function - Orchestrating agent-powered stepsWhat SKILL.md sets; muted values are Claude Code's defaults
51 skills in this plugin
/output-build-workflowImplement an Output SDK workflow from a plan document. Use when the user asks to build, implement, or code a workflow from an existing plan, or after output-plan-workflow has produced a plan and the user is ready to build./output-credentials-editView, edit, and set encrypted credentials in an Output.ai project. Use when adding secrets, updating API keys, verifying credential values, or retrieving a specific credential./output-credentials-env-varsWire encrypted credentials to environment variables using the credential: convention. Use when setting up LLM provider keys (ANTHROPIC_API_KEY, OPENAI_API_KEY) or any env var that should come from encrypted credentials.npx claudepluginhub growthxai/output --plugin outputaiOther plugins' skills for the same job