text stringlengths 0 59.1k |
|---|
const supervisorAgent = new Agent({ |
name: "Supervisor", |
instructions: `You are a GitHub repository analyzer. When given a GitHub repository URL or owner/repo format, you will: |
1. Extract the owner/repo name. |
2. Use the StarsFetcher agent to get the repository's star count. |
3. Use the ContributorsFetcher agent to get the repository's contributors. |
4. Pass the collected data (stars, contributors) to the RepoAnalyzer agent. |
5. Return the analysis provided by the RepoAnalyzer. |
Example input: https://github.com/vercel/ai-sdk or vercel/ai-sdk |
`, |
llm: new VercelAIProvider(), |
model: openai("gpt-4o-mini"), |
subAgents: [starsFetcherAgent, contributorsFetcherAgent, analyzerAgent], // Assign sub-agents |
}); |
// 5. Initialize the VoltAgent with the agent hierarchy |
new VoltAgent({ |
agents: { |
// We only expose the supervisor externally. |
// The supervisor will internally call the other agents. |
supervisor: supervisorAgent, |
}, |
}); |
console.log("GitHub Repo Analyzer Agent system started."); |
``` |
**Explanation:** |
1. **Imports:** We import necessary components from VoltAgent and AI SDK libraries. |
2. **Mock Tools:** For simplicity, we've added mock versions of the tools directly in this file. In a real app, you'd import actual tool implementations. |
3. **`starsFetcherAgent`:** Defined with a name, description, LLM configuration, and the `mockFetchRepoStarsTool`. Its job is solely to use this tool when asked. |
4. **`contributorsFetcherAgent`:** Similar to the stars fetcher, but configured with the `mockFetchRepoContributorsTool`. |
5. **`analyzerAgent`:** This agent doesn't need tools. Its purpose is to receive data (stars and contributors) and use its LLM capabilities to generate an analysis based on its description. |
6. **`supervisorAgent`:** This is the main coordinator. |
- Its `description` clearly outlines the steps it needs to take. |
- Crucially, it includes the other three agents in its `subAgents` array. This tells the supervisor it can delegate tasks to these specific agents. |
7. **`new VoltAgent(...)`:** This initializes the VoltAgent system. We register the `supervisorAgent` under the key `supervisor`. This means when we interact with our application, we'll be talking directly to the supervisor. |
## Step 5: Run Your Agent System |
Now, let's run the agent. Go back to your terminal (make sure you're in the `github-repo-analyzer` directory) and run the development command: |
<Tabs> |
<TabItem value="npm" label="npm" default> |
```bash |
npm run dev |
``` |
</TabItem> |
<TabItem value="yarn" label="yarn"> |
```bash |
yarn dev |
``` |
</TabItem> |
<TabItem value="pnpm" label="pnpm"> |
```bash |
pnpm dev |
``` |
</TabItem> |
</Tabs> |
You should see the VoltAgent server startup message: |
```bash |
ββββββββββββββββββββββββββββββββββββββββββββββββββ |
VOLTAGENT SERVER STARTED SUCCESSFULLY |
ββββββββββββββββββββββββββββββββββββββββββββββββββ |
β HTTP Server: http://localhost:3141 |
Test your agents with VoltOps Console: https://console.voltagent.dev |
ββββββββββββββββββββββββββββββββββββββββββββββββββ |
``` |
## Step 6: Interact with Your Agent |
1. **Open the Console:** Go to [`https://console.voltagent.dev`](https://console.voltagent.dev). |
2. **Find Your Agent:** Look for the agent named `supervisor` (or whatever name you gave it in the `new VoltAgent` call). |
3. **Open Agent Details:** Click on the `supervisor` agent. |
4. **Start Chatting:** Click the chat icon. |
5. **Send a Message:** Try sending a message like: |
`Analyze the repo voltagent/voltagent` |
or |
`Tell me about https://github.com/voltagent/voltagent` |
 |
The supervisor agent will now follow its instructions: |
- It will likely first call the `StarsFetcher` to get the (mock) star count. |
- Then, it will call the `ContributorsFetcher` for the (mock) contributor list. |
- Finally, it will pass this information to the `RepoAnalyzer` and return the analysis to you in the chat. |
You can observe this multi-step process happening in the VoltAgent VoltOps Platform! |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.