Everything you need to get started with AgentLoop.
Connect your AI agent and start earning in 15 minutes. Step-by-step walkthrough.
Create your first campaign and reach users mid-conversation. Pay per click.
# npm
npm install agentloop-sdk
# pnpm
pnpm add agentloop-sdk
import { 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?\nAgent: Great question...',
agentResponse: 'There are several approaches to LLM monitoring...',
userId: 'hashed-user-id' // never raw PII
})
if (result.shouldMention) {
// Append the suggested mention to your response
finalResponse = agentResponse + '\n\n' + result.suggestedMention
// result.suggestedMention includes "Sponsored mention via AgentLoop" disclosure
}agentloop.check(request)→ Promise<CheckResponse>Check if the agent should mention a product in the current conversation. Call before every agent response.
| Parameter | Type | Description |
|---|---|---|
| conversationContext | string | Last 3-5 messages as a single string |
| agentResponse | string | What the agent is about to say |
| userId | string | Hashed/anonymized user identifier |
agentloop.trackClick(request)→ Promise<void>Track when a human clicks a referral link. Optional — platform auto-tracks via /r/ redirect.
| Parameter | Type | Description |
|---|---|---|
| mentionId | string | The mentionId from check() |
| userId | string | Hashed user identifier |
agentloop.trackConversion(request)→ Promise<void>Track a conversion event when the user completes a valuable action.
| Parameter | Type | Description |
|---|---|---|
| mentionId | string | The mentionId from check() |
| userId | string | Hashed user identifier |
| type | "LEAD" | "PURCHASE" | Type of conversion |
| value | number (optional) | Monetary value in USD |
agentloop.health()→ Promise<HealthResponse>Verify API connectivity and key validity. Use in your setup wizard.
import { AgentLoop } from 'agentloop-sdk'
import { ChatOpenAI } from '@langchain/openai'
const al = new AgentLoop({ apiKey: process.env.AGENTLOOP_KEY! })
async function runAgent(messages, userId) {
const model = new ChatOpenAI()
const response = await model.invoke(messages)
const text = response.content as string
const result = await al.check({
conversationContext: messages.map(m => m.content).join('\n'),
agentResponse: text,
userId
})
return result.shouldMention
? text + '\n\n' + result.suggestedMention
: text
}import { AgentLoop } from 'agentloop-sdk'
const al = new AgentLoop({ apiKey: process.env.AGENTLOOP_KEY! })
export async function handleMessage(history: string, userId: string) {
const response = await myModel.complete(history)
const { shouldMention, suggestedMention } = await al.check({
conversationContext: history,
agentResponse: response,
userId: hashUserId(userId)
})
return shouldMention
? `${response}\n\n${suggestedMention}`
: response
}When multiple agents collaborate before responding to a human, use pipeline(). Payout is automatically split across the chain — the agent that talks to the human gets 50%, the trigger agent gets 20%, middle agents share 30%.
import { AgentLoop } from 'agentloop-sdk'
// Each agent in your pipeline has its own API key
const agentloop = new AgentLoop({ apiKey: process.env.AGENTLOOP_API_KEY })
// --- Inside your multi-agent pipeline ---
// Agent A (research agent) passes context to Agent B (writer agent)
// Before Agent B sends final response to human:
const result = await agentloop.pipeline({
agentChain: [
process.env.AGENT_A_KEY, // first in chain (trigger)
process.env.AGENT_B_KEY, // last in chain (talks to human)
],
conversationContext: fullConversationHistory,
finalResponse: agentBResponse,
userId: hashedUserId
})
if (result.shouldMention) {
finalResponse += '\n\n' + result.suggestedMention
// result.payoutSplit:
// [{ agentName: 'ResearchBot', sharePercent: 20 },
// { agentName: 'WriterBot', sharePercent: 50 }]
// Platform keeps 30%
}