This is the official Inferable AI SDK for Typescript.
npm install inferable
yarn add inferable
pnpm add inferable
import { Inferable } from "inferable";
const inferable = new Inferable({
// Get yours at https://app.inferable.ai
apiSecret: ""
// Optional, if self-hosting (https://docs.inferable.ai/pages/self-hosting)
// baseUrl: "http://localhost:4000",
});
Register a tool which is available for your agents to use.
ℹ️ This example demonstrates Node.js. Tools can also be written in Go or .NET.
inferable.tools.register({
name: "greet",
func: async (input) => {
return `Hello, ${input.name}! My name is ${os.hostname()}.`;
},
schema: {
input: z.object({
name: z.string(),
}),
},
});
inferable.tools.listen();
Workflows are a way to orchestrate agents. They are durable, distributed, and run on the machine that they are registered on.
ℹ️ Workflow definitions can currently only be written in Node.js.
const workflow = inferable.workflows.create({
name: "greeting",
inputSchema: z.object({
executionId: z.string(),
userName: z.string(),
}),
});
workflow.version(1).define(async (ctx, input) => {
const greetingAgent = ctx.agent({
name: "greeter",
tools: ["greet"],
systemPrompt: helpers.structuredPrompt({
facts: ["You are a friendly greeter"],
goals: ["Return a greeting to the user"]
}),
resultSchema: z.object({
greeting: z.string(),
}),
});
const result = await greetingAgent.trigger({
data: {
name: input.userName,
}
});
console.log(result.result.greeting);
// ... or chain this to anther ctx.agent()
});
workflow.listen();
Tgger the workflow from your application code or via a HTTP request.
await inferable.workflows.trigger('greeting', {
executionId: `123`,
userName: "Alice",
});
curl -XPOST https://api.inferable.ai/clusters/$CLUSTER_ID/workflows/greeting/executions \
-d '{"executionId": "123", "userName": "Alice"}' \
-H "Authorization: Bearer $API_SECRET"
- Inferable documentation contains all the information you need to get started with Inferable.
For support or questions, please create an issue in the repository.
Contributions to the Inferable NodeJs Client are welcome. Please ensure that your code adheres to the existing style and includes appropriate tests.