Skip to content

Commit 2e731a4

Browse files
committed
chore: add few more examples
1 parent 60d4425 commit 2e731a4

File tree

6 files changed

+81
-11
lines changed

6 files changed

+81
-11
lines changed

example/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ In order to run Slack example, you need to have `SLACK_API_TOKEN` and `SLACK_CHA
2626
- `bun run-organization-analysis.ts callstackincubator` - Analyzing an entire GitHub organization
2727
- `bun run-project-analysis.ts facebook/react-native` - Analyzing a single GitHub project
2828
- `bun run-organization-analysis-with-slack-message.ts callstackincubator` - Analyzing an entire GitHub organization and sending the report to Slack
29+
- `bun run-newsletter-analysis.ts` - Summarizing the "This Week in React" newsletter content and sending it to Slack
2930

3031
## Cloudflare Worker
3132

example/agents.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ export const slackAgent = agent({
4949
system: `
5050
You are a Slack agent.
5151
You can send messages to Slack.
52-
Your messages should be concise and to the point.
5352
You always start with a friendly greeting in a casual, developer-friendly tone.
5453
`,
5554
tools: createAISDKTools(slack),
@@ -63,3 +62,13 @@ export const analysisAgent = agent({
6362
Focus on identifying patterns, trends, and key insights.
6463
`,
6564
})
65+
66+
export const contentAgent = agent({
67+
model: openai('gpt-4o'),
68+
system: `
69+
You are a content analysis agent.
70+
You can analyze web content and extract information from it.
71+
Your summaries are clear, focused, and highlight what's most relevant for developers.
72+
`,
73+
tools: createAISDKTools(firecrawl),
74+
})

example/flows.ts

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { forEach, parallel, sequence } from 'flows-ai/flows'
1+
import s from 'dedent'
2+
import { forEach, oneOf, parallel, sequence } from 'flows-ai/flows'
23
import { z } from 'zod'
34

45
/**
@@ -77,3 +78,48 @@ export const organizationAnalysisWithSlackMessageFlow = sequence([
7778
input: `Send the report to the channel "${process.env['SLACK_CHANNEL_ID']}"`,
7879
},
7980
])
81+
82+
/**
83+
* Flow for analyzing newsletter content and creating summaries
84+
*/
85+
export const newsletterSummaryFlow = sequence([
86+
{
87+
agent: 'contentAgent',
88+
input: s`
89+
Extract all links from the provided newsletter URL.
90+
For each link, determine if it is an article (📜) or release (📦).
91+
Return first 5 links with URL whose type is either "article" or "release".
92+
Skip any links that point to "x.com" or "twitter.com".
93+
`,
94+
},
95+
forEach({
96+
item: z.object({
97+
url: z.string().describe('The URL of the content'),
98+
type: z.enum(['article', 'release']).describe('The type of content'),
99+
}),
100+
input: oneOf([
101+
{
102+
when: 'It is an article',
103+
input: {
104+
agent: 'contentAgent',
105+
input: 'Create a bullet-point summary of the key points from this article.',
106+
},
107+
},
108+
{
109+
when: 'It is a release',
110+
input: {
111+
agent: 'contentAgent',
112+
input:
113+
'Analyze the release notes, identify any breaking changes, and highlight the most important new feature.',
114+
},
115+
},
116+
]),
117+
}),
118+
{
119+
agent: 'slackAgent',
120+
input: s`
121+
Send all summaries to the channel "${process.env['SLACK_CHANNEL_ID']}".
122+
The message must start with the newsletter issue number.
123+
`,
124+
},
125+
])

example/run-newsletter-analysis.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { execute } from 'flows-ai'
2+
3+
import { contentAgent, slackAgent } from './agents'
4+
import { newsletterSummaryFlow } from './flows'
5+
6+
/**
7+
* Summarize the newsletter content and send it to Slack
8+
*/
9+
const response = await execute(newsletterSummaryFlow, {
10+
agents: {
11+
contentAgent,
12+
slackAgent,
13+
},
14+
input: 'https://thisweekinreact.com/newsletter/218',
15+
onFlowStart: (flow) => {
16+
console.log('Executing', flow.agent.name)
17+
},
18+
onFlowFinish(flow, result) {
19+
console.log('Finished', flow.agent.name, result)
20+
},
21+
})
22+
23+
console.log(response)

example/run-organization-analysis-with-slack-message.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ if (!projectName) {
1111
)
1212
}
1313

14-
if (!process.env['SLACK_API_TOKEN']) {
15-
throw new Error('Please set SLACK_API_TOKEN environment variable.')
16-
}
17-
1814
const channelId = process.env['SLACK_CHANNEL_ID']
1915
if (!channelId) {
2016
throw new Error('Please set SLACK_CHANNEL_ID environment variable.')

packages/flows-ai/src/index.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -168,11 +168,6 @@ export const makeOneOfAgent: AgentFactory<OneOfFlowDefinition> =
168168
.describe('The index of the condition that is met, or -1 if no condition was met.'),
169169
}),
170170
})
171-
console.log(s`
172-
Here is the context: ${JSON.stringify(context)}
173-
Here is the array of conditions: ${JSON.stringify(conditions)}
174-
`)
175-
console.log(condition.object)
176171
const index = condition.object.index
177172
if (index === -1) {
178173
throw new Error('No condition was satisfied')

0 commit comments

Comments
 (0)