Use the Blaxel SDK to develop and run a custom agent in TypeScript.
bl create-agent-app
.
index.ts
. While you typically wonβt need to modify this file, you can add specific logic there if needed. Your main work will focus on the agent.ts
file. Blaxelβs development paradigm lets you leverage its hosting capabilities without modifying your agentβs core logic.
BL_SERVER_HOST
(for the host) and BL_SERVER_PORT
(for the port). These two environment variables are required for the host+port combo.
FRAMEWORK_NAME
specified in the import.
Available frameworks :
langgraph
llamaindex
vercel
mastra
my-model
in a LlamaIndex agent:
langgraph
(LangChain/LangGraph), llamaindex
(LlamaIndex), vercel
(Vercel AI) and mastra
(Mastra).
You can develop agents by mixing tools defined locally in your agents, and tools defined as remote servers. Using separated tools prevents monolithic designs which make maintenance easier in the long run. Letβs look at a practical example combining remote and local tools. The code below uses two tools:
blaxel-search
: A remote tool server on Blaxel providing web search functionality (learn how to create your own MCP servers here)weather
: A local tool that accepts a city parameter and returns a mock weather response (always βsunnyβ)blAgent().run()
rather than combining all functionality into a single codebase.
blaxel.toml
file at the root of your directory.
Read the file structure section down below for more details.
bl serve
and bl deploy
commands.
scripts
are not required. With TypeScript, all 4 of them are used.
start
: start the server locally through the TypeScript command, to avoid having to build the project when developing.build
: build the project. It is done automatically when deploying.prod
: start the server remotely from the dist folder, the project needs to be have been built before.dev
: same as start, but with hotreload. Itβs useful when developing locally, each file change is reflected immediately.type
so Blaxel knows which kind of entity to deploy. Others are not mandatory but allow you to customize the deployment.
name
, workspace
, and type
fields are optional and serve as default values. Any bl command run in the folder will use these defaults rather than prompting you for input.agents
, functions
, and models
fields are also optional. They specify which resources to deploy with the agent. These resources are preloaded during build, eliminating runtime dependencies on the Blaxel control plane and dramatically improving performance.[env]
section defines environment variables that the agent can access via the SDK. Note that these are NOT secrets.[runtime]
section allows to override agent deployment parameters: timeout (in s) or memory (in MB) to allocate.[[triggers]]
and [triggers.configuration]
sections defines ways to send requests to the agent. You can create both synchronous and asynchronous trigger endpoints. You can also make them either private (default) or public.
A private synchronous HTTP endpoint is always created by default, even if you donβt define any trigger here.BL_SERVER_HOST
& BL_SERVER_PORT
. Blaxel automatically injects these variables during deployment.
For example, if your current server code looks something like this: