Docs SDK

SDK

JS agents are plain ES modules with a single default export: the run function. No build step required.

Minimal agent

export default {
  async run(input, ctx) {
    const { text } = input;
    const result = await ctx.llm.run(`Summarise this: ${text}`);
    return { summary: result.text };
  }
};

Context object (ctx)

ctx.llm

const result = await ctx.llm.run(prompt, {
  model:       'default',   // use the user's configured model
  max_tokens:  1000,
  temperature: 0.7,
});
// result.text — response string
// result.tokens — { input, output }

ctx.vault

const apiKey = await ctx.vault.get('OPENAI_API_KEY');
// Returns the secret value within the sandbox only.
// The raw string never leaves the isolate boundary.

ctx.http (ELEVATED only)

const res = await ctx.http.fetch('https://api.example.com/data', {
  method:  'GET',
  headers: { Authorization: `Bearer ${apiKey}` },
});
const data = await res.json();

ctx.log

ctx.log('Processing step 1...');
ctx.log({ level: 'warn', message: 'Rate limit approaching' });

Error handling

Throw any error to fail the run. FaynOS catches it, records the error in the run log, and marks the run as failed. The error message is shown in Agent Studio.

if (!input.text) throw new Error('text is required');
Uncaught promise rejections are also caught and treated as run failures.

Packaging as FPK

Once your agent is working, package it using the FPK format and submit it to the store. See FPK Format for the full schema.