Add to an existing agent
Add to an existing agent
Use your existing The helper returns
model and prompt with AgentMuxer tools:{ tools, close }. It does not choose a model or run the agent.Before you start
- Node.js 22.18 or later with ESM; see compatibility.
- An AgentMuxer application key and credits for paid calls.
- An OpenAI API key for the model.
This example asks the agent to spend up to $0.10 on one tool call. Model charges are separate. Set an application spending limit if you need a hard cap; the prompt alone doesn’t enforce one.This example cannot collect payment confirmation. Configure your account for unattended purchases before running it. This setting also affects your personal agents.
1
Install
In a new directory, create an ESM project and install the integration:
2
Set your keys
Set both keys in your terminal:No browser sign-in is needed. Keep both keys on your server and out of source control.
3
Create your agent
Save this as
agent.ts:agent.ts
4
Run
- Three TypeScript release changes.
- Sources for the summary.
- The actual tool cost, or the reason it could not complete the purchase.
prompt. Include the spending you allow.Stream the result
Inagent.ts, replace the agent.generate() call and console.log(result.text) with:
try block. The existing finally closes the connection after you consume the stream. For an HTTP response stream, attach cleanup to completion, error, and cancellation; do not close the connection when you merely return the stream.
Connection options and approvals
The helper acceptsinitializationOptions and onUncaughtError and disables automatic MCP tool-call retries. Configure model behavior and tool permissions in your AI SDK agent. See the SDK reference.
In SDK 0.1.0, the helper does not expose a flow for resuming AgentMuxer purchase-confirmation requests. Use unattended purchases as described above or a client with confirmation support. Application spending limits still apply.
Applications and keys
Manage credentials and spending limits.
Run in production
Handle deployment, failures, and tracing.