@ideascol/agents-generator-sdk
v0.7.2
Published
agents-generator-sdk
Downloads
547
Readme
@ideascol/agents-generator-sdk
agents-generator-sdk
Usage as library
Basic Usage - Get Agents
import { useEffect, useState } from 'react';
import {
AgentClient,
MessageCreate,
} from '@ideascol/agents-generator-sdk';
export function Agents() {
const [agents, setAgents] = useState<AgentRequest[]>([]);
useEffect(() => {
const client = new AgentClient({
apiUrl: 'https://api.agentsgenerator.dev',
apiToken: 'YOUR_API_TOKEN',
})
client
.agent.getAgents(0, 100, "anonymus")
.then((result: AgentRequest[]) => {
setAgents(result);
});
}, []);
return (
<div>
<h1>Agents</h1>
{agents.map((agent) => (
<div key={agent.name}>{agent.name}</div>
))}
</div>
);
}Send Message with Transfer Detection (Synchronous)
The sendMessage method now uses streaming internally to detect agent transfers (handoffs). It returns a promise with the complete response including any transfers that occurred.
import { AgentClient, SendMessageResponse } from '@ideascol/agents-generator-sdk';
const client = new AgentClient({
apiUrl: 'https://api.agentsgenerator.dev',
apiToken: 'YOUR_API_TOKEN',
});
// Send a message and get the complete response with transfers
const response: SendMessageResponse = await client.sendMessage(
'conversation-id',
{ content: 'Hello, I need help with billing' }
);
console.log('Message:', response.message);
console.log('Message ID:', response.message_id);
// Check if there were any transfers
if (response.transfers && response.transfers.length > 0) {
console.log('Transfers detected:');
response.transfers.forEach(transfer => {
console.log(` From: ${transfer.from_agent}`);
console.log(` To: ${transfer.to_agent}`);
console.log(` Reason: ${transfer.reason}`);
});
}Send Message with Streaming (Real-time updates)
For real-time updates and custom handling of events, use sendMessageWithStreaming:
import { AgentClient, TransferEvent } from '@ideascol/agents-generator-sdk';
const client = new AgentClient({
apiUrl: 'https://api.agentsgenerator.dev',
apiToken: 'YOUR_API_TOKEN',
});
const abort = client.sendMessageWithStreaming(
'conversation-id',
{ content: 'Hello!' },
{
onMessage: (content: string) => {
console.log('Message update:', content);
},
onDone: (messageId: string) => {
console.log('Message completed:', messageId);
},
onTransfer: (transfer: TransferEvent) => {
console.log('Transfer detected!');
console.log(` From: ${transfer.from_agent}`);
console.log(` To: ${transfer.to_agent}`);
console.log(` Reason: ${transfer.reason}`);
},
onError: (error: Error) => {
console.error('Error:', error);
}
}
);
// To abort the stream:
// abort();TypeScript Types
interface SendMessageResponse {
status: string;
message: string;
message_id?: string;
transfers?: TransferEvent[];
}
interface TransferEvent {
from_agent?: string;
to_agent?: string;
reason?: string;
}
interface StreamCallbacks {
onMessage?: (content: string) => void;
onDone?: (messageId: string) => void;
onError?: (error: Error) => void;
onTransfer?: (transfer: TransferEvent) => void;
}Quick start
# Using npm
npx @ideascol/agents-generator-sdk@latest
# Using bun
bunx @ideascol/agents-generator-sdk@latestInstallation
# Using npm
npm install -g @ideascol/agents-generator-sdk@latest
# Using bun
bun install -g @ideascol/agents-generator-sdk@latestUsage as cli
npx @ideascol/agents-generator-sdk@latest version --apiToken=1232 --URL=https://api.agentsgenerator.dev{
"status": "ok",
"api_version": "dbd7d9ca8a6b1e4622ef409e26cd8addb650e95f",
"api_branch": "main",
"api_date": "2025-04-25 17:21:01"
}Update lib client
npx openapi-typescript-codegen \
--input https://api.agentsgenerator.dev/openapi.json \
--output src/lib/clients/agents-generator \
--client fetchnpx openapi-typescript-codegen \
--input http://localhost:8000/openapi.json \
--output src/lib/clients/agents-generator \
--client fetchcurl -s http://localhost:8000/openapi.json -o openapi.json