Building an Agent from Scratch
A step-by-step guide to create a minimal Inferable application using Node.js and TypeScript
While this guide uses NodeJS. The same steps and concepts are applicable for the other SDKs.
Prerequisites
Make sure you have Node.js installed and have set up your as an environment variable (INFERABLE_API_SECRET
).
You can get your API secret by running:
Creating a minimal Inferable application
Install dependencies
Install the necessary packages. We use zod
to define the schema of our functions, and dotenv
to load the environment variables from the .env
file.
Initialize the Inferable client
Create a new file called index.ts
and add the following code to initialize the :
Register a function
Now, let’s add a that returns system information of the running machine:
Start the service
Finally, let’s start the :
Run the project
To run this example, save the file as app.ts
and execute it using tsx
. -r dotenv/config
is used to load the environment variables from the .env
file.
Construct a run
Now that you have the service running and your functions registered, you can interact with it in three different ways:
Let’s create a run.ts
file:
- It will take a question as an argument and return the answer.
- It will return the result of the function as an object containing
answer
.
To execute this example, save the file as run.ts
and execute it in another terminal. (Make sure the service is running in the first terminal.)
Note that we didn’t explicity specify the function to use in the run. Inferable will automatically infer the function to use based on the context of the question. You can also specify the function to use in the run via the run.attachedFunctions
field.
What happened?
The that comes out of the box with Inferable uses an LLM to plan, select the best function, execute it, and then use the result to plan again.
This is an illustration of how the Re-Act loop would have worked in this instance:
Finishing up
That’s it! You’ve created a minimal Inferable application.
The complete working example of this guide is available here.
If you need help at any point, join our Community Slack and join the #support channel.
Related Pages
Was this page helpful?