Official SDK for the AgentLoop Agentic Marketing Network.
Your agent talks anyway. Now it earns too.
npm install agentloop-sdk
# or
pnpm add agentloop-sdk
# or
yarn add agentloop-sdkimport { AgentLoop } from 'agentloop-sdk'
const agentloop = new AgentLoop({
apiKey: 'al_live_your_key_here'
})
// Call before every agent response
const result = await agentloop.check({
conversationContext: 'User: How do I monitor my LLM in production?',
agentResponse: 'Great question! There are several approaches to LLM monitoring...',
userId: 'hashed-user-id' // anonymized, never raw PII
})
if (result.shouldMention) {
// Append the suggested mention to your response
const fullResponse = myAgentResponse + '\n\n' + result.suggestedMention
}| Option | Type | Default | Description |
|---|---|---|---|
apiKey |
string |
required | Your API key from the AgentLoop dashboard |
baseUrl |
string |
https://agentloop.life |
Custom API base URL |
timeout |
number |
200 |
Request timeout in milliseconds |
maxRetries |
number |
3 |
Max retry attempts with exponential backoff |
debug |
boolean |
true in dev |
Enable verbose logging |
Call before every agent response. Returns a recommendation.
const result = await agentloop.check({
conversationContext: string, // last 3-5 messages
agentResponse: string, // what the agent is about to say
userId: string // hashed anonymous user id
})
// Returns:
// {
// shouldMention: boolean,
// product?: { name, description, referralUrl },
// suggestedMention?: string,
// mentionId?: string,
// confidence?: number // 0-100
// }Track when a human clicks a referral link. (Optional — the platform also auto-tracks via the /r/ redirect.)
Track a conversion event manually.
await agentloop.trackConversion({
mentionId: result.mentionId!,
userId: 'hashed-user-id',
type: 'LEAD', // or 'PURCHASE'
value: 49.99 // optional, in USD
})Check API connectivity. Useful for setup verification.
import { AgentLoop } from 'agentloop-sdk'
import { ChatOpenAI } from '@langchain/openai'
const agentloop = new AgentLoop({ apiKey: process.env.AGENTLOOP_API_KEY! })
async function respondToUser(messages: any[], userId: string) {
const model = new ChatOpenAI()
const response = await model.invoke(messages)
const agentText = response.content as string
const mention = await agentloop.check({
conversationContext: messages.map(m => `${m.role}: ${m.content}`).join('\n'),
agentResponse: agentText,
userId,
})
if (mention.shouldMention) {
return agentText + '\n\n' + mention.suggestedMention
}
return agentText
}import { AgentLoop } from 'agentloop-sdk'
const agentloop = new AgentLoop({ apiKey: process.env.AGENTLOOP_API_KEY! })
export async function handleMessage(conversationHistory: string, userId: string) {
const agentResponse = await myAIModel.complete(conversationHistory)
const result = await agentloop.check({
conversationContext: conversationHistory,
agentResponse,
userId: hashUserId(userId),
})
return result.shouldMention
? `${agentResponse}\n\n${result.suggestedMention}`
: agentResponse
}- Never breaks your agent — all errors are caught and fail silently
- Fast — 200ms timeout with exponential backoff retry
- No duplicate mentions — in-memory cache prevents the same context from triggering twice
- Privacy-first — never log or store raw user data; use hashed IDs only
All AI-generated mentions include "Sponsored mention via AgentLoop" per FTC guidelines.
- Docs: https://agentloop.life/docs
- Dashboard: https://agentloop.life/dashboard/agent