Skip to content

Commit b638243

Browse files
committed
Added agents readme
1 parent 6f4f5d3 commit b638243

File tree

1 file changed

+90
-0
lines changed

1 file changed

+90
-0
lines changed

building-effective-agents/README.md

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
## Building Effective Agents with Trigger.dev
2+
3+
This Node.js project shows 5 different patterns for building effective agents with Trigger.dev.
4+
5+
- Prompt chaining
6+
- Routing
7+
- Parallelization
8+
- Orchestrator-workers
9+
- Evaluator-optimizer
10+
11+
All of these examples focus on performing specific tasks, rather than do-it-all agents.
12+
13+
## About the project
14+
15+
- This is a basic Node.js project, so it doesn't include any UI.
16+
- Each of the different AI agent patterns is implemented as a [Trigger.dev](https://cloud.trigger.dev) task.
17+
- The [AI SDK](https://sdk.vercel.ai/docs/introduction) is used to work with OpenAI models.
18+
19+
## AI agent patterns in this project
20+
21+
### Prompt chaining
22+
23+
Breaking down a task into a series of steps, guided through a pre-determined sequence.
24+
25+
#### Example: Prompt chaining
26+
27+
1. Generate marketing copy on a subject you provide. (LLM call 1)
28+
2. Check the word count fits a target range. (Gate)
29+
3. Take the output and translate it into a target language. (LLM call 2)
30+
31+
View the Trigger.dev prompt chaining task code: [src/trigger/trigger/translate-copy.ts](./src/trigger/trigger/translate-copy.ts).
32+
33+
### Routing
34+
35+
You can think of routing as an AI traffic controller. Instead of forcing one LLM to handle everything, you first figure out what type of task you're dealing with, then send it to the right specialist.
36+
37+
#### Example: Routing
38+
39+
1. User asks a question.
40+
2. Determine if the question is simple or complex.
41+
3. Use the appropriate model to answer the question.
42+
4. Return the answer, model used, and reasoning.
43+
44+
View the Trigger.dev routing task code: [src/trigger/trigger/routing-questions.ts](./src/trigger/trigger/routing-questions.ts).
45+
46+
### Parallelization
47+
48+
Sometimes you need to do multiple things at once – that's where parallelization comes in. Rather than working through tasks one by one, you split them up and run them simultaneously. This is where batch.triggerByTaskAndWait shines, allowing you to execute multiple tasks in parallel and efficiently coordinate their responses.
49+
50+
#### Example: Parallelization
51+
52+
This example responds to customer questions by simultaneously generating a response and checking for inappropriate content.
53+
54+
3 tasks handle this:
55+
56+
1. The first generates a response to the user's question.
57+
2. The second task checks for innapropriate content.
58+
3. The third, main task coordinates the responses by using batch.`triggerByTaskAndWait` to run the two tasks in parallel. If the content is inappropriate, this task returns a message saying it can't process the request, otherwise it returns the generated response.
59+
60+
View the Trigger.dev parallelization task code: [src/trigger/trigger/parallelize-tasks.ts](./src/trigger/trigger/parallelize-tasks.ts).
61+
62+
### Orchestrator-workers
63+
64+
This pattern is like having a project manager (the orchestrator) who breaks down a big job into smaller tasks and assigns them to specialists (the workers). The orchestrator keeps track of everything and puts all the pieces back together at the end. Using batch.triggerByTaskAndWait, it efficiently coordinates multiple tasks while maintaining clear control over the entire workflow.
65+
66+
#### Example: Orchestrator-workers
67+
68+
1. Extracts distinct factual claims from a news article.
69+
2. Verifies each claim by considering recent news sources and official statements.
70+
3. Analyzes the historical context of each claim in the context of past announcements and technological feasibility.
71+
4. Returns the claims, verifications, and historical analyses.
72+
73+
View the Trigger.dev orchestrator-workers task code: [src/trigger/trigger/orchestrator-workers.ts](./src/trigger/trigger/orchestrator-workers.ts).
74+
75+
### Evaluator-optimizer
76+
77+
Here's where you add quality control to your AI system. The evaluator checks the output, and if it's not quite right, the optimizer suggests improvements. Think of it as having a friendly editor who reviews your work and helps make it better.
78+
79+
#### Example: Evaluator-optimizer
80+
81+
1. Generates a translation of the text.
82+
2. Evaluates the translation.
83+
3. If the translation is good, returns the final result.
84+
4. If the translation is not good, recursively calls the task with the translation and feedback.
85+
86+
View the Trigger.dev evaluator-optimizer task code: [src/trigger/trigger/evaluator-optimizer.ts](./src/trigger/trigger/evaluator-optimizer.ts).
87+
88+
## Blog post
89+
90+
Read the blog post: [Building Effective Agents with Trigger.dev](https://trigger.dev/blog/ai-agents-with-trigger).

0 commit comments

Comments
 (0)