Skip to content

Latest commit

 

History

History
53 lines (39 loc) · 1.47 KB

File metadata and controls

53 lines (39 loc) · 1.47 KB

Reflex

Reflex is an AI SDK library that replaces your tool list with smarter selection and execution. Instead of loading all tools into context, your agent picks the right ones on-demand. It can also chain tool calls by writing code—handling loops, conditionals, and error recovery without round-trips to the model.

Based on Anthropic's advanced tool use patterns.

Install

npm install reflex-ai

Usage

import { createReflexTools } from "reflex-ai";
import { generateText } from "ai";

const { toolSearch, toolExecute } = createReflexTools({
  tools: {
    readNotionDoc,
    sendSlackMessage,
    // ... your AI SDK tools
  },
  model: optionalSelectorModel, // used for smart tool matching
});

const result = await generateText({
  model: yourModel,
  tools: { toolSearch, toolExecute },
  prompt: "...",
});

Tools

toolSearch

Finds relevant tools by query. Uses simple string matching by default, or semantic matching if you provide a model.

toolExecute

Runs JavaScript in a sandbox with your tools exposed as async functions. Lets the agent orchestrate multiple calls, loop over data, and combine results in one shot.

// Example: batch operation in a single execution
const users = await getUsers();
const results = [];
for (const user of users) {
  results.push(await sendEmail({ to: user.email, subject: "Hello" }));
}
return results;