You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/content/changelog/agents/2025-07-21-agents-queue-email-context-update.mdx
+18-20Lines changed: 18 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,18 +15,18 @@ The latest releases of [@cloudflare/agents] (https://github.com/cloudflare/agent
15
15
You can use .queue() to enqueue background work — ideal for tasks like processing user messages, sending notifications etc.
16
16
17
17
```ts
18
-
classMyAgentextendsAgent{
19
-
doSomethingExpensive(payload){
20
-
// a long running process that you want to run in the background
21
-
}
22
-
23
-
queueSomething(){
24
-
awaitthis.queue('doSomethingExpensive', somePayload); // this will NOT block further execution, and runs in the background
25
-
awaitthis.queue('doSomethingExpensive', someOtherPayload); // the callback will NOT run until the previous callback is complete
26
-
// ... call as many times as you want
27
-
}
28
-
}
18
+
classMyAgentextendsAgent {
19
+
doSomethingExpensive(payload) {
20
+
// a long running process that you want to run in the background
21
+
}
29
22
23
+
queueSomething() {
24
+
awaitthis.queue("doSomethingExpensive", somePayload); // this will NOT block further execution, and runs in the background
25
+
awaitthis.queue("doSomethingExpensive", someOtherPayload); // the callback will NOT run until the previous callback is complete
26
+
// ... call as many times as you want
27
+
}
28
+
}
29
+
```
30
30
31
31
Want to try it yourself? Just define a method like processMessage in your agent, and you’re ready to scale.
32
32
@@ -41,13 +41,12 @@ export class EmailAgent extends Agent {
41
41
const parsed =awaitPostalMime.parse(raw);
42
42
43
43
// create a response based on the email contents
44
-
// and then send a reply
45
-
46
-
await this.replyToEmail(email, {
44
+
// and then send a reply
45
+
46
+
awaitthis.replyToEmail(email, {
47
47
fromName: "Email Agent",
48
48
body: `Thanks for your email! You've sent us "${parsed.subject}". We'll process it shortly.`,
49
49
});
50
-
51
50
}
52
51
}
53
52
```
@@ -68,20 +67,19 @@ You can find a full example [here](https://github.com/cloudflare/agents/tree/mai
68
67
69
68
### Automatic context wrapping for custom methods
70
69
71
-
Custommethodsarenowautomaticallywrappedwiththeagent's context, so calling `getCurrentAgent()` should work regardless of where in an agent'slifecycleit's called. Previously this would not work on RPC calls, but not just works out of the box.
72
-
73
-
70
+
Custom methods are now automatically wrapped with the agent's context, so calling `getCurrentAgent()` should work regardless of where in an agent's lifecycle it's called. Previously this would not work on RPC calls, but not just works out of the box.
74
71
75
72
```ts
76
73
exportclassMyAgentextendsAgent {
77
74
async suggestReply(ctx, { message }) {
78
-
// getCurrentAgent() now correctly works, even when called inside an RPC method
79
-
const { agent } = getCurrentAgent()!;
75
+
// getCurrentAgent() now correctly works, even when called inside an RPC method
76
+
const { agent } =getCurrentAgent()!;
80
77
returngenerateText({
81
78
prompt: `Suggest a reply to: "${message}" from "${agent.name}"`,
0 commit comments