The Agents API allows you to manage and interact with AI agents that can use TPMJS tools.
GET /api/agents
Retrieve a list of your agents. Requires authentication.
curl -H "Authorization: Bearer YOUR_API_KEY" \
"https://tpmjs.com/api/agents"{
"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
}
]
}POST /api/agents
Create a new AI agent with specified configuration.
{
"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
}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();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.
{
"message": "What's the weather in San Francisco?",
"conversationId": "conv-123" // optional
}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);
}POST /api/agents/:uid/tools
Add a tool to an agent's available tools.
{
"toolId": "clx123abc"
}POST /api/agents/:uid/collections
Add all tools from a collection to an agent.
{
"collectionId": "clx456def"
}