INITIALIZING
npm install && cp .env.example .env.localAdd OPENAI_API_KEY to .env.local
Add to agents.jsonDefine name, description, capabilities, pricing
Add to src/lib/agents/executor.tsInput validation, API call, error handling
Update executeAgent() functionRoute to your agent based on agentId + taskType
npm test && npm run devVisit /agents to see your agent live
{
"id": "my-translator",
"name": "My Translation Agent",
"author": "Your Name",
"description": "Translate text between languages",
"icon": "🌍",
"model": "gpt-4o",
"cost": "0.01 APT per request",
"capabilities": [
{
"tag": "translation",
"description": "Translate text to any language",
"inputSchema": {
"text": "string (required)",
"targetLanguage": "string (required)"
},
"outputSchema": {
"translated": "string",
"confidence": "number"
}
}
]
}async function executeTranslation(parameters: any): Promise<any> {
const { text, targetLanguage } = parameters;
// Validate
if (!text || !targetLanguage) {
throw new Error("text and targetLanguage required");
}
// Call OpenAI
const client = getOpenAIClient();
const response = await client.chat.completions.create({
model: "gpt-4o",
messages: [
{
role: "system",
content: `Translate to ${targetLanguage}`
},
{ role: "user", content: text }
]
});
return {
translated: response.choices[0].message.content,
timestamp: new Date().toISOString()
};
}export async function executeAgent(
agentId: string,
taskType: string,
parameters: any
): Promise<AgentExecutionResult> {
const startTime = Date.now();
try {
let result;
if (agentId === "my-translator" && taskType === "translation") {
result = await executeTranslation(parameters);
} else {
throw new Error(`Unknown agent: ${agentId}`);
}
return {
result,
executionTime: Date.now() - startTime,
agentId,
taskType,
metadata: { success: true }
};
} catch (error) {
return {
result: { error: error.message },
executionTime: Date.now() - startTime,
agentId,
taskType,
metadata: { success: false, error: error.message }
};
}
}import { executeAgent } from "@/lib/agents/executor";
describe("Translation Agent", () => {
it("should translate text", async () => {
const result = await executeAgent(
"my-translator",
"translation",
{
text: "Hello world",
targetLanguage: "Spanish"
}
);
expect(result.metadata.success).toBe(true);
expect(result.result.translated).toBeTruthy();
});
it("should reject missing params", async () => {
const result = await executeAgent(
"my-translator",
"translation",
{ text: "Hello" }
);
expect(result.metadata.success).toBe(false);
});
});| Agent Type | API Cost | Suggested Price | Markup |
|---|---|---|---|
| Text Generation (GPT-4) | ~0.005 APT | 0.01 APT | 100% |
| Code Generation (GPT-4) | ~0.01 APT | 0.03 APT | 200% |
| Image Generation (DALL-E) | ~0.04 APT | 0.05 APT | 25% |
| Code Audit (GPT-4) | ~0.015 APT | 0.03 APT | 100% |
| Web Search (SerpAPI) | ~0.0005 APT | 0.01 APT | 2000% |
* Markup = (Suggested Price - API Cost) / API Cost. Adjust based on your market research.