Quick Start
This quick start guide will walk you through creating a simple agent swarm using the Agent Swarm Protocol. By the end, you'll have a small swarm of agents working together to solve a task.
Overview
In this guide, we'll create:
- A simple conversational agent
- A research agent that can search for information
- A workflow that connects them together
Prerequisites
Ensure you have:
- Completed the installation of the ASP Orchestrator
- Set up your environment variables (especially API keys)
- Basic understanding of JavaScript/TypeScript
Step 1: Create Your First Agent
Let's create a simple conversational agent:
mkdir -p agents/conversational-agent
cd agents/conversational-agent
Create a manifest file:
// manifest.json
{
"name": "conversational-agent",
"version": "1.0.0",
"description": "A simple conversational agent",
"entryPoint": "index.js",
"capabilities": [
"conversation"
],
"requiredServices": [
"llm"
]
}
Now implement the agent:
// index.js
const { Agent } = require('@agent-swarm/agent-sdk');
// Initialize the agent
const agent = new Agent({
manifestPath: './manifest.json'
});
// Handle incoming messages
agent.on('message', async (message) => {
if (message.type === 'conversation.request') {
// Request LLM service from the orchestrator
const llmResponse = await agent.requestService('llm', {
prompt: message.content,
temperature: 0.7
});
// Send response back
agent.send({
type: 'conversation.response',
content: llmResponse.text,
requestId: message.id
});
}
});
// Connect to the orchestrator
agent.connect();
Step 2: Create a Research Agent
Let's create another agent that can search for information:
mkdir -p agents/research-agent
cd agents/research-agent
Create a manifest file:
// manifest.json
{
"name": "research-agent",
"version": "1.0.0",
"description": "An agent that can search for information",
"entryPoint": "index.js",
"capabilities": [
"search"
],
"requiredServices": [
"web-search",
"llm"
]
}
Implement the agent:
// index.js
const { Agent } = require('@agent-swarm/agent-sdk');
// Initialize the agent
const agent = new Agent({
manifestPath: './manifest.json'
});
// Handle incoming messages
agent.on('message', async (message) => {
if (message.type === 'search.request') {
// Perform web search
const searchResults = await agent.requestService('web-search', {
query: message.query,
numResults: 3
});
// Summarize results using LLM
const summary = await agent.requestService('llm', {
prompt: `Summarize these search results about "${message.query}": ${JSON.stringify(searchResults)}`,
temperature: 0.3
});
// Send response back
agent.send({
type: 'search.response',
content: summary.text,
sources: searchResults.map(r => r.url),
requestId: message.id
});
}
});
// Connect to the orchestrator
agent.connect();
Step 3: Create a Swarm Workflow
Now, let's create a workflow that orchestrates these agents:
// workflow.js
const { Orchestrator } = require('@agent-swarm/orchestrator');
const config = require('./asp-config.js');
const orchestrator = new Orchestrator(config);
// Define a swarm workflow
const swarmWorkflow = {
name: 'research-conversation',
description: 'A workflow that combines research and conversation',
agents: ['conversational-agent', 'research-agent'],
initialMessage: {
type: 'workflow.start',
content: 'I need information about Agent Swarm Protocol.'
},
steps: [
{
id: 'research',
agent: 'research-agent',
message: {
type: 'search.request',
query: '{{initialMessage.content}}'
}
},
{
id: 'conversation',
agent: 'conversational-agent',
message: {
type: 'conversation.request',
content: 'Based on the following information, provide a helpful response to the user: {{research.response.content}}'
},
dependsOn: ['research']
}
],
output: '{{conversation.response.content}}'
};
// Register the workflow
orchestrator.registerWorkflow(swarmWorkflow);
// Start the orchestrator
orchestrator.start().then(() => {
console.log(`ASP Orchestrator running on port ${config.port}`);
// Example of executing the workflow
orchestrator.executeWorkflow('research-conversation', {
initialMessage: {
content: 'Tell me about the benefits of Agent Swarm Protocol.'
}
}).then(result => {
console.log('Workflow result:', result);
});
});
Step 4: Run Your Agent Swarm
Start the orchestrator with your workflow:
node workflow.js
This will:
- Start the orchestrator
- Register and start your agents
- Execute the workflow
- Display the result
What's Happening?
- The workflow starts with a request about the Agent Swarm Protocol
- This request is sent to the research agent
- The research agent searches for information and summarizes it
- The summarized information is sent to the conversational agent
- The conversational agent creates a user-friendly response
- The final response is returned as the workflow output
Next Steps
Now that you've created your first agent swarm, you can:
- Add more agents with different capabilities
- Create more complex workflows
- Explore advanced agent features
- Learn about orchestrator services
- Understand agent communication patterns