Documentation Index
Fetch the complete documentation index at: https://docs.stackone.com/llms.txt
Use this file to discover all available pages before exploring further.
StackOne tools work with Vercel AI SDK to build AI applications using React, Next.js, and other frameworks.
Overview
- Streaming responses with real-time tool execution
- React hooks for building AI UIs
- Multi-step tool calls with automatic handling
- Framework compatibility with Next.js, React, Vue, and more
import { openai } from '@ai-sdk/openai';
import { generateText } from 'ai';
import { StackOneToolSet } from '@stackone/ai';
async function createAgentForAccount(accountId: string) {
/**
* Create agent with tools for a specific account.
*
* In production, accountId comes from:
* - User/tenant context
* - Authentication middleware
* - Database lookup
*/
const toolset = new StackOneToolSet();
// Fetch tools dynamically for this account
const tools = await toolset.fetchTools({
accountIds: [accountId]
});
// Convert to Vercel AI SDK format
const aiSdkTools = await tools.toAISDK();
const { text } = await generateText({
model: openai('gpt-5.4'),
tools: aiSdkTools,
prompt: 'Get employee details for id: c28xIQaWQ6MzM5MzczMDA2NzMzMzkwNzIwNA',
maxSteps: 3,
});
return text;
}
// Use the agent
// Get account ID from your app's auth context or StackOne dashboard
const accountId = 'your-account-id';
const result = await createAgentForAccount(accountId);
Load tools based on available integrations:
import { StackOneToolSet } from '@stackone/ai';
const toolset = new StackOneToolSet();
// Load all tools for specific accounts (most common)
const tools = await toolset.fetchTools({
accountIds: ["account-123"]
});
// Optional: Filter by operation type for security
const tools = await toolset.fetchTools({
accountIds: ["account-123"],
actions: ["*_list_*", "*_get_*"] // Only list and get operations (read-only)
});
// Convert to Vercel AI SDK format
const aiSdkTools = await tools.toAISDK();
Streaming Responses
Build real-time AI applications with streaming:
import { streamText } from 'ai';
import { openai } from '@ai-sdk/openai';
async function streamingAgent(accountId: string, prompt: string) {
const toolset = new StackOneToolSet();
const tools = await toolset.fetchTools({ accountIds: [accountId] });
const aiSdkTools = await tools.toAISDK();
const result = await streamText({
model: openai('gpt-5.4'),
tools: aiSdkTools,
prompt,
maxSteps: 5,
});
// Stream to client
for await (const chunk of result.textStream) {
process.stdout.write(chunk);
}
}
Multi-Tenant Support
Handle multiple customer accounts:
async function getAgentForUser(userId: string) {
// Get user's account IDs from your database
const accountIds = await db.getUserAccountIds(userId);
const toolset = new StackOneToolSet();
const tools = await toolset.fetchTools({ accountIds });
return await tools.toAISDK();
}
// Usage in API endpoint
app.post('/api/chat', async (req, res) => {
const { message, userId } = req.body;
const tools = await getAgentForUser(userId);
const result = await generateText({
model: openai('gpt-5.4'),
tools,
prompt: message,
});
res.json({ response: result.text });
});
Best Practices
Account ID from Context
// Get from user/tenant context
const accountId = req.user.stackoneAccountId;
const accountId = await getAccountForTenant(tenantId);
Error Handling
import { StackOneError } from '@stackone/ai';
try {
const result = await generateText({ model, tools, prompt });
} catch (error) {
if (error instanceof StackOneError) {
console.error('StackOne error:', error.message);
// Handle gracefully
}
}
// Only expose read operations (optional - for security)
const tools = await toolset.fetchTools({
accountIds: [accountId],
actions: ["*_list_*", "*_get_*"] // Only list and get
});
// Or exclude dangerous operations
const tools = await toolset.fetchTools({
accountIds: [accountId],
actions: ["!*_delete_*"] // Everything except deletes
});
Example
Agent-Driven Search
Let the LLM discover tools on its own using tool_search + tool_execute:
const toolset = new StackOneToolSet({
search: { method: 'semantic', topK: 3 },
accountId: 'your-account-id',
});
const tools = toolset.getTools({ accountIds: ['your-account-id'] });
// LLM receives only 2 tools - it searches and executes autonomously
const { text } = await generateText({
model: openai('gpt-5.4'),
tools: await tools.toAISDK(),
prompt: 'List my upcoming Calendly events for the next week.',
stopWhen: stepCountIs(10),
});
See Tool Search for more details.
Next Steps