Skip to content

Commit

Permalink
feat: add organization flow with slack message
Browse files Browse the repository at this point in the history
  • Loading branch information
grabbou committed Jan 26, 2025
1 parent 75e2019 commit e197cb0
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 5 deletions.
Binary file modified bun.lockb
Binary file not shown.
5 changes: 5 additions & 0 deletions example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,8 @@ These examples use OpenAI and FireCrawl APIs. You need to have the following env

- `bun run-organization-analysis.ts callstackincubator` - Analyzing an entire GitHub organization
- `bun run-project-analysis.ts facebook/react-native` - Analyzing a single GitHub project
- `bun run-organization-analysis-with-slack-message.ts callstackincubator` - Analyzing an entire GitHub organization and sending the report to Slack

> [!NOTE]
> In order to run Slack example, you need to have `SLACK_API_TOKEN` environment variable set.
> You will also need to have `SLACK_CHANNEL_ID` environment variable set.
13 changes: 13 additions & 0 deletions example/agents.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { createAISDKTools } from '@agentic/ai-sdk'
import { FirecrawlClient } from '@agentic/firecrawl'
import { SlackClient } from '@agentic/slack'
import { openai } from '@ai-sdk/openai'
import { agent } from 'flows-ai'

const firecrawl = new FirecrawlClient()
const slack = new SlackClient()

export const githubAgent = agent({
model: openai('gpt-4o'),
Expand All @@ -25,6 +27,17 @@ export const npmAgent = agent({
tools: createAISDKTools(firecrawl),
})

export const slackAgent = agent({
model: openai('gpt-4o'),
system: `
You are a Slack agent.
You can send messages to Slack.
Your messages should be concise and to the point.
You always start with a friendly greeting in a casual, developer-friendly tone.
`,
tools: createAISDKTools(slack),
})

export const analysisAgent = agent({
model: openai('gpt-4o'),
system: `
Expand Down
3 changes: 2 additions & 1 deletion example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
},
"dependencies": {
"@agentic/ai-sdk": "^7.2.0",
"@agentic/firecrawl": "^7.2.0"
"@agentic/firecrawl": "^7.2.0",
"@agentic/slack": "^7.2.0"
}
}
48 changes: 48 additions & 0 deletions example/run-organization-analysis-with-slack-message.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { execute } from 'flows-ai'
import { sequence } from 'flows-ai/flows'

import { githubAgent, slackAgent } from './agents'
import { githubProjectHealthAnalysisFlow } from './flows'

const projectName = process.argv[2]

if (!projectName) {
throw new Error(
'Please provide a project name, e.g.: bun run-project-analysis.ts facebook/react-native'
)
}

if (!process.env['SLACK_API_TOKEN']) {
throw new Error('Please set SLACK_API_TOKEN environment variable.')
}

const channelId = process.env['SLACK_CHANNEL_ID']
if (!channelId) {
throw new Error('Please set SLACK_CHANNEL_ID environment variable.')
}

/**
* In this example, we run already defined `githubProjectHealthAnalysisFlow`,
* and then, we send the report to Slack.
*/
const response = await execute(
sequence([
githubProjectHealthAnalysisFlow,
{
agent: 'slackAgent',
input: `Send the report to the channel "${channelId}"`,
},
]),
{
agents: {
githubAgent,
slackAgent,
},
input: projectName,
onFlowStart: (flow) => {
console.log('Executing', flow.agent.name)
},
}
)

console.log(response)
3 changes: 1 addition & 2 deletions example/run-organization-analysis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ import { organizationAnalysisFlow } from './flows'
const orgName = process.argv[2]

if (!orgName) {
console.error(
throw new Error(
'Please provide an organization name, e.g.: bun run-organization-analysis.ts callstackincubator'
)
process.exit(1)
}

/**
Expand Down
3 changes: 1 addition & 2 deletions example/run-project-analysis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ import { githubProjectHealthAnalysisFlow } from './flows'
const projectName = process.argv[2]

if (!projectName) {
console.error(
throw new Error(
'Please provide a project name, e.g.: bun run-project-analysis.ts facebook/react-native'
)
process.exit(1)
}

/**
Expand Down

0 comments on commit e197cb0

Please sign in to comment.