Skip to content

Commit 1ab5595

Browse files
committed
chore: better example
1 parent 2e21129 commit 1ab5595

File tree

7 files changed

+187
-69
lines changed

7 files changed

+187
-69
lines changed

example/README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Examples
2+
3+
This directory contains examples of using flows-ai in practice.
4+
5+
## Prerequisites
6+
7+
These examples use OpenAI and FireCrawl APIs. You need to have the following environment variables set:
8+
- `OPENAI_API_KEY` - Your OpenAI API key
9+
- `FIRECRAWL_API_KEY` - Your FireCrawl API key for GitHub and NPM data access
10+
11+
## Structure
12+
13+
- `flows.ts` - All flows are defined here
14+
- `agents.ts` - All agents are defined here
15+
16+
## Running the examples
17+
18+
- `bun run-organization-analysis.ts callstackincubator` - Analyzing an entire GitHub organization
19+
- `bun run-project-analysis.ts facebook/react-native` - Analyzing a single GitHub project

example/agents.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { createAISDKTools } from '@agentic/ai-sdk'
2+
import { FirecrawlClient } from '@agentic/firecrawl'
3+
import { openai } from '@ai-sdk/openai'
4+
import { agent } from 'flows-ai'
5+
6+
const firecrawl = new FirecrawlClient()
7+
8+
export const githubAgent = agent({
9+
model: openai('gpt-4o'),
10+
system: `
11+
You are a Github analysis agent.
12+
You can access Github repositories and extract meaningful insights about projects.
13+
Focus on providing clear, structured data about repositories, issues, and project health.
14+
`,
15+
tools: createAISDKTools(firecrawl),
16+
})
17+
18+
export const npmAgent = agent({
19+
model: openai('gpt-4o'),
20+
system: `
21+
You are an NPM registry analysis agent.
22+
You can access NPM registry data and provide package statistics.
23+
Focus on download counts and package popularity metrics.
24+
`,
25+
tools: createAISDKTools(firecrawl),
26+
})
27+
28+
export const analysisAgent = agent({
29+
model: openai('gpt-4o'),
30+
system: `
31+
You are a data analysis agent.
32+
You combine and analyze data from multiple sources to create meaningful summaries.
33+
Focus on identifying patterns, trends, and key insights.
34+
`,
35+
tools: createAISDKTools(firecrawl),
36+
})

example/flows.ts

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import { forEach, parallel, sequence } from 'flows-ai/flows'
2+
import { z } from 'zod'
3+
4+
/**
5+
* Flow for analyzing a single GitHub project's health
6+
*/
7+
export const githubProjectHealthAnalysisFlow = sequence([
8+
{
9+
agent: 'githubAgent',
10+
name: 'getIssues',
11+
input:
12+
'Get top 10 open issues with most "thumbs down" reactions. Each issue should have a title and a URL.',
13+
},
14+
forEach({
15+
item: z.object({
16+
title: z.string().describe('The issue title'),
17+
url: z.string().describe('The URL of the issue'),
18+
}),
19+
input: sequence([
20+
{
21+
agent: 'githubAgent',
22+
input: 'Analyze the issue carefuly and extract the root cause',
23+
},
24+
]),
25+
}),
26+
{
27+
agent: 'githubAgent',
28+
input: 'Extract common patterns (if any) amongst all open issues, based on provided summaries.',
29+
},
30+
])
31+
32+
/**
33+
* Flow for analyzing an entire GitHub organization
34+
*/
35+
export const organizationAnalysisFlow = sequence([
36+
{
37+
agent: 'githubAgent',
38+
input:
39+
'Get the top 5 repositories by stars from this organization. Return array of objects with repository URL.',
40+
},
41+
forEach({
42+
item: z.object({
43+
url: z.string().describe('The repository URL'),
44+
}),
45+
input: sequence([
46+
parallel([
47+
{
48+
agent: 'githubAgent',
49+
input:
50+
'Analyze open issues and provide a summary including: total count, most common labels, and top 3 most discussed issues.',
51+
},
52+
{
53+
agent: 'npmAgent',
54+
input: 'Get weekly download count for this package from NPM registry.',
55+
},
56+
]),
57+
{
58+
agent: 'analysisAgent',
59+
input: 'Create a summary combining GitHub stats and NPM data for this project.',
60+
},
61+
]),
62+
}),
63+
{
64+
agent: 'analysisAgent',
65+
input:
66+
'Create an organization-wide summary analyzing patterns and insights across all projects.',
67+
},
68+
])

example/github.ts

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

example/run-organization-analysis.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { execute } from 'flows-ai'
2+
3+
import { analysisAgent, githubAgent, npmAgent } from './agents'
4+
import { organizationAnalysisFlow } from './flows'
5+
6+
const orgName = process.argv[2]
7+
8+
if (!orgName) {
9+
console.error(
10+
'Please provide an organization name, e.g.: bun run-organization-analysis.ts callstackincubator'
11+
)
12+
process.exit(1)
13+
}
14+
15+
/**
16+
* Example of running an organization analysis
17+
*/
18+
const response = await execute(organizationAnalysisFlow, {
19+
agents: {
20+
githubAgent,
21+
npmAgent,
22+
analysisAgent,
23+
},
24+
input: orgName,
25+
onFlowStart: (flow) => {
26+
console.log('Executing', flow.agent.name)
27+
},
28+
onFlowFinish: (flow, response) => {
29+
console.log('Flow finished', flow.agent.name, response)
30+
},
31+
})
32+
33+
console.log(response)

example/run-project-analysis.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { execute } from 'flows-ai'
2+
3+
import { githubAgent } from './agents'
4+
import { githubProjectHealthAnalysisFlow } from './flows'
5+
6+
const projectName = process.argv[2]
7+
8+
if (!projectName) {
9+
console.error(
10+
'Please provide a project name, e.g.: bun run-project-analysis.ts facebook/react-native'
11+
)
12+
process.exit(1)
13+
}
14+
15+
/**
16+
* Example of running a project health analysis
17+
*/
18+
const response = await execute(githubProjectHealthAnalysisFlow, {
19+
agents: {
20+
githubAgent,
21+
},
22+
input: projectName,
23+
onFlowStart: (flow) => {
24+
console.log('Executing', flow.agent.name)
25+
},
26+
})
27+
28+
console.log(response)

packages/flows-ai/src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ export type FlowDefinition = {
4444
* or an array of objects (nested flow definitions).
4545
*/
4646
input: FlowDefinition | FlowDefinition[] | string
47+
/**
48+
* Structured output for the flow.
49+
*/
4750
/**
4851
* Optional name of the flow.
4952
*/

0 commit comments

Comments
 (0)