Agents API

The Agents API allows you to manage and interact with AI agents that can use TPMJS tools.

List Agents

GET /api/agents

Retrieve a list of your agents. Requires authentication.

Example Request

curl -H "Authorization: Bearer YOUR_API_KEY" \
  "https://tpmjs.com/api/agents"

Example Response

{
  "success": true,
  "data": [
    {
      "id": "clx123abc",
      "uid": "my-assistant",
      "name": "My Assistant",
      "description": "A helpful AI assistant",
      "provider": "ANTHROPIC",
      "modelId": "claude-3-5-sonnet-20241022",
      "isPublic": true,
      "likeCount": 15
    }
  ]
}

Create Agent

POST /api/agents

Create a new AI agent with specified configuration.

Request Body

{
  "name": "My Assistant",
  "description": "A helpful AI assistant",
  "uid": "my-assistant",
  "provider": "ANTHROPIC",
  "modelId": "claude-3-5-sonnet-20241022",
  "systemPrompt": "You are a helpful assistant...",
  "temperature": 0.7,
  "isPublic": true
}

TypeScript Example

const response = await fetch('/api/agents', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer YOUR_API_KEY'
  },
  body: JSON.stringify({
    name: 'My Assistant',
    uid: 'my-assistant',
    provider: 'ANTHROPIC',
    modelId: 'claude-3-5-sonnet-20241022'
  })
});

const { data: agent } = await response.json();

Chat with Agent

POST /api/agents/:uid/chat

Send a message to an agent and receive a streaming response. The agent can use any tools attached to it.

Request Body

{
  "message": "What's the weather in San Francisco?",
  "conversationId": "conv-123" // optional
}

TypeScript Example

const response = await fetch('/api/agents/my-assistant/chat', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    message: 'What is the weather in San Francisco?'
  })
});

// Handle SSE stream
const reader = response.body.getReader();
const decoder = new TextDecoder();

while (true) {
  const { done, value } = await reader.read();
  if (done) break;

  const text = decoder.decode(value);
  console.log(text);
}

Add Tool to Agent

POST /api/agents/:uid/tools

Add a tool to an agent's available tools.

Request Body

{
  "toolId": "clx123abc"
}

Add Collection to Agent

POST /api/agents/:uid/collections

Add all tools from a collection to an agent.

Request Body

{
  "collectionId": "clx456def"
}