Build a dependable agentic platform with Mastra

  • Home
  • / Build a dependable agentic platform with Mastra
Build a dependable agentic platform with Mastra

An agentic platform has to stay up under load, stay sane on cost, and keep your data where you put it. Most teams pick a solid framework and quietly fail on one of the other two.

There are 2 sides to this problem, beyond business fit: The technology providing the agentic tooling, and the provider supporting it. One of the most promising agentic toolkits we've seen recently is Mastra - a TypeScript/NodeJS framework that provides a wealth of primitives for an agent-first stack while being entirely free and open source. It's also incredibly simple: both its documentation and readability are strong points for us and for that reason we'd recommend it over many other toolkits. LangGraph is a decent alternative, too.

The other side you'll have probably seen coming: Use Infersec as your AI provider. We're a secure, privacy-focused AI routing and load balancing platform that allows you to use your own hardware as the power source. We provide you the software to connect your systems (laptops, workstations, mini PCs, rack servers) to our routing layer (either hosted or self-hosted) so you can provide your sensitive agentic systems with an OpenAI/Anthropic-compatible endpoint for tools like Mastra to connect to.

What do you get in a framework like Mastra?

Such toolkits provide a bunch of primitives with some way to coordinate the calls and workflows inherent in agentic pipelines. Mastra provides common items like agents, workflows, tool calling and memory management, but includes more advanced tools like workspaces, evals/judges/scorers and browser integration, among others. You use these primitives to structure your agentic work in a reusable manner, where an agent can be called by your own application and return a strict structure (or free-form text), or even by another agent via a tool call.

Throw in Mastra's Studio and you have a heads-up display of how your agents are running, the work they're doing, what they're calling etc. - it's a brilliant toolkit and it only gets more impressive the more you read.

Closing the loop with Infersec

Now imagine that you've got your agentic workflows configured, and you want to get them running with that spare Mac Mini you have sitting in the corner. Login to Infersec, configure a model, engine and inference source, run the software/installation on the Mac Mini, expose the inference endpoint and plug that into Mastra. You now have a secure agentic loop ready for sensitive data and operations running using your own hardware. It's your own sovereign AI platform.

Infersec setup in Mastra

First, create the model in TypeScript:

export const createInfersecModel = ({
    apiKey,
    apiUrl,
    endpointId
}: {
    apiKey: string;
    apiUrl: string;
    endpointId: string;
}) => ({
    apiKey,
    id: "infersec/default" as const,
    url: `${apiUrl}/api/inferencing/${endpointId}/oai/v1`
});

And then attach that to an agent:

export const researcher = new Agent({
    id: "researcher",
    instructions: `You are a meticulous web research assistant.`,
    model: createInfersecModel({ apiKey: "", apiUrl: "", endpointId: "" }),
    name: "Infersec Researcher"
});

That's it. You're ready to call that agent - it'll fire off OpenAI-formatted requests to your own personal Infersec API endpoint.

Where to go from here

Consider signing up for early access, or take a look around our site and explore features like our self-hosted platform. Trying our platform first, using the hosted option is probably the easiest to get started with, and you can transfer to the self-hosted option by simply changing the endpoint URL you use.

If you want to dig in to how a full setup using Mastra and Infersec might look, check out our Mastra web research example.

Cover image generated with AI.