Skip to content

Commit 46d24c2

Browse files
committed
feat: make github example more real-life
1 parent 8e240a5 commit 46d24c2

File tree

4 files changed

+47
-104
lines changed

4 files changed

+47
-104
lines changed

bun.lockb

3.54 KB
Binary file not shown.

example/flows.ts

Lines changed: 0 additions & 44 deletions
This file was deleted.

example/github.ts

Lines changed: 43 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,69 @@
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'
19
import { openai } from '@ai-sdk/openai'
2-
import { tool } from 'ai'
310
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'
1313

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'),
2527
}),
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.',
2638
},
27-
})
39+
])
40+
41+
const firecrawl = new FirecrawlClient()
2842

2943
/**
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.
3145
*/
3246
const githubAgent = agent({
3347
model: openai('gpt-4o-mini'),
3448
system: `
3549
You are a Github agent.
3650
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.
3852
`,
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),
4954
})
5055

5156
/**
52-
* This agent takes simple text as input
57+
* Finally, we execute the flow for "facebook/react-native" project.
5358
*/
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-
7259
const response = await execute(githubProjectHealthAnalysisFlow, {
7360
agents: {
74-
userInputAgent,
7561
githubAgent,
76-
communicationAgent,
7762
},
63+
input: 'facebook/react-native',
7864
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)
8366
},
8467
})
8568

86-
console.log('Received response', response)
69+
console.log(response)

example/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,9 @@
1111
"type": "git",
1212
"url": "git+https://github.com/callstackincubator/workflows-ai.git",
1313
"directory": "example"
14+
},
15+
"dependencies": {
16+
"@agentic/ai-sdk": "^7.2.0",
17+
"@agentic/firecrawl": "^7.2.0"
1418
}
1519
}

0 commit comments

Comments
 (0)