Skip to content

SMJAI/agentloop-sdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

agentloop-sdk

Official SDK for the AgentLoop Agentic Marketing Network.

Your agent talks anyway. Now it earns too.

Installation

npm install agentloop-sdk
# or
pnpm add agentloop-sdk
# or
yarn add agentloop-sdk

Quick Start

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?',
  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
}

API Reference

new AgentLoop(config)

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

agentloop.check(request)CheckResponse

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
// }

agentloop.trackClick({ mentionId, userId })

Track when a human clicks a referral link. (Optional — the platform also auto-tracks via the /r/ redirect.)

agentloop.trackConversion({ mentionId, userId, type, value })

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
})

agentloop.health()HealthResponse

Check API connectivity. Useful for setup verification.

Framework Examples

LangChain

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
}

Custom Agent (Node.js)

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
}

Guarantees

  • 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

Disclosure

All AI-generated mentions include "Sponsored mention via AgentLoop" per FTC guidelines.

Support

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors