Quickstart
This guide shows how to use Magnitude with Steel to create an AI browser agent that visits the Steel leaderboard Github repo, extracts the details behind the latest commit, and if associated with a pull request, it will summarize the details.
Scroll to the bottom to see a full example!
Requirements
-
Anthropic API Key
-
Steel API Key
-
Node.js 20+
Step 1: Project Setup
Create a new TypeScript project and basic script:
mkdir steel-magnitude && \cd steel-magnitude && \npm init -y && \npm install -D typescript @types/node ts-node && \npx tsc --init && \npm pkg set scripts.start="ts-node index.ts" && \touch index.ts .env
Step 2: Install Dependencies
$npm install steel-sdk magnitude-core zod dotenv
Step 3: Environment Variables
Create a .env
file with your API keys:
1STEEL_API_KEY=your-steel-api-key-here2ANTHROPIC_API_KEY=your-anthropic-api-key-here
Step 4: Initialize Steel & Magnitude
Set up Steel, load env vars, and prepare to start the Magnitude agent.
1import * as dotenv from "dotenv";2import { Steel } from "steel-sdk";3import { startBrowserAgent } from "magnitude-core";4import { z } from "zod";56dotenv.config();78const STEEL_API_KEY = process.env.STEEL_API_KEY || "your-steel-api-key-here";9const ANTHROPIC_API_KEY = process.env.ANTHROPIC_API_KEY || "your-anthropic-api-key-here";1011const client = new Steel({ steelAPIKey: STEEL_API_KEY });12
Step 5: Create a Steel Session & Start the Agent
Create a Steel session, then connect Magnitude via CDP. Turn on narrate
for easy debugging.
1async function main() {2console.log("🚀 Steel + Magnitude Node Starter");3console.log("=".repeat(60));45if (STEEL_API_KEY === "your-steel-api-key-here") {6console.warn("⚠️ Please set STEEL_API_KEY in your .env");7console.warn(" Get one at https://app.steel.dev/settings/api-keys");8return;9}1011if (ANTHROPIC_API_KEY === "your-anthropic-api-key-here") {12console.warn("⚠️ Please set ANTHROPIC_API_KEY in your .env");13console.warn(" Get one at https://console.anthropic.com/");14return;15}1617let session: any;18let agent: any;1920try {21console.log("\nCreating Steel session...");22session = await client.sessions.create({23// Optional knobs:24// useProxy: true,25// proxyUrl: 'http://user:pass@host:port',26// solveCaptcha: true,27// sessionTimeout: 1800000, // ms28// userAgent: 'custom-ua'29});3031console.log(`Steel session created!`);32console.log(`View session at: ${session.sessionViewerUrl}`);3334agent = await startBrowserAgent({35url: "https://github.com/steel-dev/leaderboard",36narrate: true,37llm: {38provider: "anthropic",39options: {40model: "claude-3-7-sonnet-latest",41apiKey: process.env.ANTHROPIC_API_KEY,42},43},44browser: {45cdp: `${session.websocketUrl}&apiKey=${STEEL_API_KEY}`,46},47});4849console.log("Connected to browser via Magnitude");
Use Magnitude’s agent.extract
to pull structured data (user behind commit + commit itself) using a Zod schema.
1console.log("Looking for commits");23const mostRecentCommitter = await agent.extract(4"Find the user with the most recent commit",5z.object({6user: z.string(),7commit: z.string(),8})9);1011console.log("\n\x1b[1;92mMost recent committer:\x1b[0m");12console.log(`${mostRecentCommitter.user} has the most recent commit`);13
Step 7: Perform Natural-Language Actions
Use agent.act
to summarize the pull request (if there’s a pull request behind the commit).
1console.log("\nLooking for pull request behind the most recent commit\x1b[0m");23try {4await agent.act(5"Find the pull request behind the most recent commit if there is one"6);7console.log("Found pull request!");89const pullRequest = await agent.extract(10"What was added in this pull request?",11z.object({12summary: z.string(),13})14);15console.log("Pull request found!");16console.log(`${pullRequest.summary}`);17} catch (error) {18console.log("No pull request found or accessible");19}2021await new Promise((resolve) => setTimeout(resolve, 2000));2223console.log("\nAutomation completed successfully!");
Step 8: Clean Up
Stop the agent and release the Steel session.
1} catch (error) {2console.error("Error during automation:", error);3} finally {4if (agent) {5console.log("Stopping Magnitude agent...");6try {7await agent.stop();8} catch (error) {9console.error("Error stopping agent:", error);10}11}1213if (session) {14console.log("Releasing Steel session...");15try {16await client.sessions.release(session.id);17console.log("Steel session released successfully");18} catch (error) {19console.error("Error releasing session:", error);20}21}22}23}2425main().catch((error) => {26console.error("Unhandled error:", error);27process.exit(1);28});
Run It
You’ll see a session viewer URL in your console, open it to watch the automation live.
Full Example
Complete index.ts
you can paste and run:
1/*2* AI-powered browser automation using Magnitude with Steel browsers.3* https://github.com/steel-dev/steel-cookbook/tree/main/examples/steel-magnitude-starter4*/56import * as dotenv from "dotenv";7import { Steel } from "steel-sdk";8import { z } from "zod";9import { startBrowserAgent } from "magnitude-core";1011dotenv.config();1213// Replace with your own API keys14const STEEL_API_KEY = process.env.STEEL_API_KEY || "your-steel-api-key-here";15const ANTHROPIC_API_KEY = process.env.ANTHROPIC_API_KEY || "your-anthropic-api-key-here";1617// Initialize Steel client with the API key from environment variables18const client = new Steel({ steelAPIKey: STEEL_API_KEY });1920async function main() {21console.log("🚀 Steel + Magnitude Node Starter");22console.log("=".repeat(60));2324if (STEEL_API_KEY === "your-steel-api-key-here") {25console.warn("⚠️ WARNING: Please replace 'your-steel-api-key-here' with your actual Steel API key");26console.warn(" Get your API key at: https://app.steel.dev/settings/api-keys");27return;28}2930if (ANTHROPIC_API_KEY === "your-anthropic-api-key-here") {31console.warn("⚠️ WARNING: Please replace 'your-anthropic-api-key-here' with your actual Anthropic API key");32console.warn(" Get your API key at: https://console.anthropic.com/");33return;34}3536let session: any;37let agent: any;3839try {40console.log("\nCreating Steel session...");41session = await client.sessions.create({42// Optional knobs:43// useProxy: true,44// proxyUrl: 'http://user:pass@host:port',45// solveCaptcha: true,46// sessionTimeout: 1800000, // ms47// userAgent: 'custom-ua'48});4950console.log(`Steel session created!`);51console.log(`View session at: ${session.sessionViewerUrl}`);5253agent = await startBrowserAgent({54url: "https://github.com/steel-dev/leaderboard",55narrate: true,56llm: {57provider: "anthropic",58options: {59model: "claude-3-7-sonnet-latest",60apiKey: process.env.ANTHROPIC_API_KEY,61},62},63browser: {64cdp: `${session.websocketUrl}&apiKey=${STEEL_API_KEY}`,65},66});6768console.log("Connected to browser via Magnitude");69console.log("Looking for commits");7071const mostRecentCommitter = await agent.extract(72"Find the user with the most recent commit",73z.object({74user: z.string(),75commit: z.string(),76})77);7879console.log("Most recent committer:");80console.log(`${mostRecentCommitter.user} has the most recent commit`);8182console.log("\nLooking for pull request behind the most recent commit\x1b[0m");8384try {85await agent.act(86"Find the pull request behind the most recent commit if there is one"87);88console.log("Found pull request!");8990const pullRequest = await agent.extract(91"What was added in this pull request?",92z.object({93summary: z.string(),94})95);96console.log("Pull request found!");97console.log(`${pullRequest.summary}`);98} catch (error) {99console.log("No pull request found or accessible");100}101102await new Promise((resolve) => setTimeout(resolve, 2000));103104console.log("\nAutomation completed successfully!");105} catch (error) {106console.error("Error during automation:", error);107} finally {108if (agent) {109console.log("Stopping Magnitude agent...");110try {111await agent.stop();112} catch (error) {113console.error("Error stopping agent:", error);114}115}116117if (session) {118console.log("Releasing Steel session...");119try {120await client.sessions.release(session.id);121console.log("Steel session released successfully");122} catch (error) {123console.error("Error releasing session:", error);124}125}126}127}128129main().catch((error) => {130console.error("Unhandled error:", error);131process.exit(1);132});133
Next Steps
-
Magnitude Documentation: https://docs.magnitude.run/getting-started/introduction
-
Session Lifecycles: https://docs.steel.dev/overview/sessions-api/session-lifecycle
-
Steel Sessions API: https://docs.steel.dev/overview/sessions-api/overview
-
Steel Node SDK: https://github.com/steel-dev/steel-node
-
This Example on Github: https://github.com/steel-dev/steel-cookbook/tree/main/examples/steel-magnitude-starter