Skip to content

Commit 8f805fa

Browse files
committed
fixed trailing
1 parent a6563a0 commit 8f805fa

File tree

1 file changed

+18
-20
lines changed

1 file changed

+18
-20
lines changed

src/content/changelog/agents/2025-07-21-agents-queue-email-context-update.mdx

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,18 @@ The latest releases of [@cloudflare/agents] (https://github.com/cloudflare/agent
1515
You can use .queue() to enqueue background work — ideal for tasks like processing user messages, sending notifications etc.
1616

1717
```ts
18-
class MyAgent extends Agent{
19-
doSomethingExpensive(payload){
20-
// a long running process that you want to run in the background
21-
}
22-
23-
queueSomething(){
24-
await this.queue('doSomethingExpensive', somePayload); // this will NOT block further execution, and runs in the background
25-
await this.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+
class MyAgent extends Agent {
19+
doSomethingExpensive(payload) {
20+
// a long running process that you want to run in the background
21+
}
2922

23+
queueSomething() {
24+
await this.queue("doSomethingExpensive", somePayload); // this will NOT block further execution, and runs in the background
25+
await this.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+
```
3030

3131
Want to try it yourself? Just define a method like processMessage in your agent, and you’re ready to scale.
3232

@@ -41,13 +41,12 @@ export class EmailAgent extends Agent {
4141
const parsed = await PostalMime.parse(raw);
4242

4343
// 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+
await this.replyToEmail(email, {
4747
fromName: "Email Agent",
4848
body: `Thanks for your email! You've sent us "${parsed.subject}". We'll process it shortly.`,
4949
});
50-
5150
}
5251
}
5352
```
@@ -68,20 +67,19 @@ You can find a full example [here](https://github.com/cloudflare/agents/tree/mai
6867

6968
### Automatic context wrapping for custom methods
7069

71-
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.
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.
7471

7572
```ts
7673
export class MyAgent extends Agent {
7774
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()!;
8077
return generateText({
8178
prompt: `Suggest a reply to: "${message}" from "${agent.name}"`,
8279
tools: [replyWithEmoji],
8380
});
8481
}
8582
}
83+
```
8684

8785
Try it out and tell us what you build!

0 commit comments

Comments
 (0)