The Basics
Magma is a TypeScript framework that makes building AI agents simple and intuitive. No complex chains or confusing abstractions - just write the logic you want your agent to have in standard Class form.
Key Features
- Simple: Build production-ready agents in minutes
- Flexible: Use any major AI provider (OpenAI, Anthropic, Google, Groq)
- Powerful: Add tools, middleware, jobs, and hooks as needed
- Observable: Full visibility into your agent’s behavior
Your First Agent
Creating a basic agent is as simple as:
Choosing a Provider
You can choose a provider in the constructor of your agent. You can also change the provider config at any time using the setProviderConfig
method. Just make sure you have your environment variables set up for the providers you choose.
Magma handles the differences between providers for you, so your types don’t need to change at all!
Using System Prompts
System prompts are a good way to give your agent a bit of context on how to behave. You can use the getSystemPrompts
method to define the system prompts for your agent.
Managing State
Because Magma Agents are class-based, you can manage state in your agent by simply adding properties to the class. These properties are available to all methods in your agent.
The Setup Method
Sometimes you’ll need to initialize your agent in a way that isn’t possible in the constructor. The setup
method is called when the agent is instantiated, and it can be asynchronous. It is a good place to initialize values for your agent, fetch starting data, etc.
Agent Structure
Magma uses decorators to make the development experience as smooth as possible, and to keep the code clean and readable.
There are four types of decorators you can use:
- Tools: Functions your agent can call to read/write external data, perform tasks, etc.
- Middleware: Add functions that run before and after your agent’s main function and tool executions
- Hooks: Exposing webooks into your agent, allowing your agent to respond to events from external systems
- Jobs: Run tasks on a schedule on your agent
A big part of the magic of Magma is the ability to deploy your agent to the cloud and have it run in a completely scalable and managed environment.
To do this, your project needs to have a few things:
- A
.ts
file with adefault export
that is a class that extendsMagmaAgent
(as shown in the Your First Agent section) - A valid
package.json
file with the magma framework installed, and your agent’s entrypoint in themain
field. Example:"main": "myAgent.ts"
.env
file with the necessary environment variables for your agent, including your AI provider’s API key, etc.
You can easily get started with a proper project configuration by using the magma init
command, as covered in the Quickstart section.