Skip to content

Commit c56b592

Browse files
committed
chore: throttle requests in example to prepare for more requests
1 parent 894cee7 commit c56b592

File tree

5 files changed

+30
-8
lines changed

5 files changed

+30
-8
lines changed

bun.lockb

32 Bytes
Binary file not shown.

example/README.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,22 @@ These examples use OpenAI and FireCrawl APIs. You need to have the following env
88
- `OPENAI_API_KEY` - Your OpenAI API key
99
- `FIRECRAWL_API_KEY` - Your FireCrawl API key for GitHub and NPM data access
1010

11+
In order to run Slack example, you need to have `SLACK_API_TOKEN` and `SLACK_CHANNEL_ID` environment variables set.
12+
13+
> [!NOTE]
14+
> FireCrawl requests are throttled to 10 requests per minute, as per the Free Plan, to avoid rate limiting.
15+
1116
## Structure
1217

1318
- `flows.ts` - All flows are defined here
1419
- `agents.ts` - All agents are defined here
1520

21+
> [!NOTE]
22+
> We're using [`Agentic`](https://github.com/agentic/agentic) to create agents.
23+
1624
## Running the examples
1725

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

22-
> [!NOTE]
23-
> In order to run Slack example, you need to have `SLACK_API_TOKEN` environment variable set.
24-
> You will also need to have `SLACK_CHANNEL_ID` environment variable set.

example/agents.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,27 @@
11
import { createAISDKTools } from '@agentic/ai-sdk'
2+
import { throttleKy } from '@agentic/core'
23
import { FirecrawlClient } from '@agentic/firecrawl'
34
import { SlackClient } from '@agentic/slack'
45
import { openai } from '@ai-sdk/openai'
56
import { agent } from 'flows-ai'
7+
import ky from 'ky'
8+
import pThrottle from 'p-throttle'
9+
10+
/**
11+
* Let's throttle the Firecrawl client to 10 requests per minute,
12+
* as per the Firecrawl Free Plan.
13+
*/
14+
const firecrawl = new FirecrawlClient({
15+
ky: throttleKy(
16+
ky,
17+
pThrottle({
18+
limit: 1,
19+
interval: 6000,
20+
strict: true,
21+
})
22+
),
23+
})
624

7-
const firecrawl = new FirecrawlClient()
825
const slack = new SlackClient()
926

1027
export const githubAgent = agent({

example/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@
1414
},
1515
"dependencies": {
1616
"@agentic/ai-sdk": "^7.2.0",
17+
"@agentic/core": "^7.2.0",
1718
"@agentic/firecrawl": "^7.2.0",
18-
"@agentic/slack": "^7.2.0"
19+
"@agentic/slack": "^7.2.0",
20+
"ky": "^1.7.4",
21+
"p-throttle": "^6.2.0"
1922
}
2023
}

example/run-organization-analysis.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@ const response = await execute(organizationAnalysisFlow, {
2424
onFlowStart: (flow) => {
2525
console.log('Executing', flow.agent.name)
2626
},
27-
onFlowFinish: (flow, response) => {
28-
console.log('Flow finished', flow.agent.name, response)
29-
},
3027
})
3128

3229
console.log(response)

0 commit comments

Comments
 (0)