Skip to main content
@major-tech/agents-client lets an app’s server code start agent runs, read their messages, send follow-ups, stop them, and answer their tool approvals. For when to use it and who a run acts as, see App triggers.

Add an agent to your app

Each agent your app calls gets a generated client in the app’s clients/ folder (src/clients/ if the app has a src directory). The client is bound to the agent’s id and reads the app’s credentials from the environment, so there is nothing to configure.
Ask for it: “Use the support-bot agent from this app.” The client is generated for you and the import line is added to your code.
Then import the client:
Always use the generated client. When you deploy, Major reads your code to find which agent ids the app uses and only allows those. An id it can’t see in the code, such as one read from an environment variable or built at runtime, isn’t allowed, and calls with it fail with AgentsAuthError.
To stop calling an agent, delete the code that uses it and remove its client.

Server code only

Use the client in Server Components, Server Actions, and Route Handlers, never in client components. It sends the app’s MAJOR_JWT_TOKEN, which must not reach the browser. The same credentials are injected while you build and after you deploy, so you can test the whole loop in the editor preview.

Start a run

run() returns { runId, status: "started" } as soon as the run is accepted. The agent runs in the background, so render a pending state and poll for results. Pass runId to every other method.

Read a run’s messages

Each page holds the newest limit messages (1-100), oldest first. role is user, assistant, or system. content depends on type (message, thinking, tool_use, tool_result, result, and system types), so render it defensively.

Send a follow-up, stop, and list runs

An app can only manage runs it started.

Answer tool approvals

If the agent has tools set to Ask (see Tool permissions), the run pauses when it wants to use one. Your app can show the pending call and let the user decide without leaving the page.
  • Show toolName and toolArgs so the user sees exactly what will run. Use description as a summary when it’s present.
  • An approval left unanswered is denied at its expiresAt time, and the run continues.
  • Poll listPendingApprovals when the user opens the run or on a sensible interval, not in a tight loop. The run is already paused.

Methods

All types are exported from @major-tech/agents-client.

Errors

Every error extends AgentsClientError, which carries httpStatus and requestId (include the request id when you contact support). Branch on the subclass rather than parsing messages:

Costs

Every run is a real agent session and uses credits. Start only the runs a page needs, and never start runs in a render loop or recursively.

If the agent should call your app back

Triggering an agent doesn’t let it call your app. If the agent should write results to the app or call its endpoints, add the app to the agent’s applications and publish the agent. Otherwise its requests to the app are rejected with HTTP 403. See Agents.