|
| 1 | +/** |
| 2 | + * Example of a very simple flow that analyzes the health of a Github project. |
| 3 | + * |
| 4 | + * To run this example, you will need to have `FIRECRAWL_API_KEY` configured in your environment. |
| 5 | + */ |
| 6 | + |
| 7 | +import { createAISDKTools } from '@agentic/ai-sdk' |
| 8 | +import { FirecrawlClient } from '@agentic/firecrawl' |
1 | 9 | import { openai } from '@ai-sdk/openai'
|
2 |
| -import { tool } from 'ai' |
3 | 10 | import { agent, execute } from 'flows-ai'
|
4 |
| -import z from 'zod' |
5 |
| - |
6 |
| -import { githubProjectHealthAnalysisFlow } from './flows' |
7 |
| - |
8 |
| -const communicationAgent = agent({ |
9 |
| - model: openai('gpt-4o'), |
10 |
| - system: ` |
11 |
| - You are a communication agent. |
12 |
| - You need to send a message to the given receipient. |
| 11 | +import { forEach, sequence } from 'flows-ai/flows' |
| 12 | +import { z } from 'zod' |
13 | 13 |
|
14 |
| - For project maintainers, you send emails to: "opensource@callstack.com". |
15 |
| - `, |
16 |
| - tools: { |
17 |
| - sendEmail: tool({ |
18 |
| - parameters: z.object({ |
19 |
| - message: z.string().describe('The message to send'), |
20 |
| - to: z.string().describe('The email address to send the message to'), |
21 |
| - }), |
22 |
| - execute: async ({ message, to }) => { |
23 |
| - return `Email sent: ${message} to ${to}` |
24 |
| - }, |
| 14 | +/** |
| 15 | + * First, we define the flow. |
| 16 | + */ |
| 17 | +const githubProjectHealthAnalysisFlow = sequence([ |
| 18 | + { |
| 19 | + agent: 'githubAgent', |
| 20 | + name: 'getIssues', |
| 21 | + input: 'Get top 10 open issues with most "thumbs down" reactions', |
| 22 | + }, |
| 23 | + forEach({ |
| 24 | + item: z.object({ |
| 25 | + title: z.string().describe('The issue title'), |
| 26 | + url: z.string().describe('The URL of the issue'), |
25 | 27 | }),
|
| 28 | + input: sequence([ |
| 29 | + { |
| 30 | + agent: 'githubAgent', |
| 31 | + input: 'Analyze the issue carefuly and extract the root cause', |
| 32 | + }, |
| 33 | + ]), |
| 34 | + }), |
| 35 | + { |
| 36 | + agent: 'githubAgent', |
| 37 | + input: 'Extract common patterns (if any) amongst all open issues, based on provided summaries.', |
26 | 38 | },
|
27 |
| -}) |
| 39 | +]) |
| 40 | + |
| 41 | +const firecrawl = new FirecrawlClient() |
28 | 42 |
|
29 | 43 | /**
|
30 |
| - * This agent takes a Github project name as input and task to perform. |
| 44 | + * Next, we define the agent. It's a simple agent that has access to the Github via Firecrawl. |
31 | 45 | */
|
32 | 46 | const githubAgent = agent({
|
33 | 47 | model: openai('gpt-4o-mini'),
|
34 | 48 | system: `
|
35 | 49 | You are a Github agent.
|
36 | 50 | You are given a Github project name and an instruction to perform.
|
37 |
| - You will scrape the data from Github and return the result. |
| 51 | + You can scrape the data from Github and return the result. |
38 | 52 | `,
|
39 |
| - tools: { |
40 |
| - scrapeTool: tool({ |
41 |
| - parameters: z.object({ |
42 |
| - url: z.string().describe('The url to scrape'), |
43 |
| - }), |
44 |
| - execute: async () => { |
45 |
| - return `<html><div>Open issues: 10000</div>, Top 3 issues: <ul><li>Issue 1</li><li>Issue 2</li><li>Issue 3</li></ul></html>` |
46 |
| - }, |
47 |
| - }), |
48 |
| - }, |
| 53 | + tools: createAISDKTools(firecrawl), |
49 | 54 | })
|
50 | 55 |
|
51 | 56 | /**
|
52 |
| - * This agent takes simple text as input |
| 57 | + * Finally, we execute the flow for "facebook/react-native" project. |
53 | 58 | */
|
54 |
| -const userInputAgent = agent({ |
55 |
| - model: openai('gpt-4o-mini'), |
56 |
| - system: 'You are given a prompt and you need to return the user input.', |
57 |
| - tools: { |
58 |
| - askQuestion: tool({ |
59 |
| - parameters: z.object({ |
60 |
| - message: z.string().describe('The question to ask the user'), |
61 |
| - }), |
62 |
| - execute: async ({ message }) => { |
63 |
| - const { text } = await import('@clack/prompts') |
64 |
| - return text({ |
65 |
| - message, |
66 |
| - }) |
67 |
| - }, |
68 |
| - }), |
69 |
| - }, |
70 |
| -}) |
71 |
| - |
72 | 59 | const response = await execute(githubProjectHealthAnalysisFlow, {
|
73 | 60 | agents: {
|
74 |
| - userInputAgent, |
75 | 61 | githubAgent,
|
76 |
| - communicationAgent, |
77 | 62 | },
|
| 63 | + input: 'facebook/react-native', |
78 | 64 | onFlowStart: (flow) => {
|
79 |
| - console.log('Flow started', flow.agent.name) |
80 |
| - if (flow.agent.name) { |
81 |
| - console.log('Executing', flow.agent.name) |
82 |
| - } |
| 65 | + console.log('Executing', flow.agent.name) |
83 | 66 | },
|
84 | 67 | })
|
85 | 68 |
|
86 |
| -console.log('Received response', response) |
| 69 | +console.log(response) |
0 commit comments