Skip to content

Commit c6a6781

Browse files
Update 2025-07-21-agents-queue-email-context-update.mdx
1 parent daf9d82 commit c6a6781

File tree

1 file changed

+34
-34
lines changed

1 file changed

+34
-34
lines changed

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

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ You can use `.queue()` to enqueue background work — ideal for tasks like proce
1616

1717
```ts
1818
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-
}
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+
}
2828
}
2929
```
3030

@@ -36,30 +36,30 @@ Want to build an AI agent that can receive and respond to emails automatically?
3636

3737
```ts
3838
export class EmailAgent extends Agent {
39-
async onEmail(email: AgentEmail) {
40-
const raw = await email.getRaw();
41-
const parsed = await PostalMime.parse(raw);
42-
43-
// create a response based on the email contents
44-
// and then send a reply
45-
46-
await this.replyToEmail(email, {
47-
fromName: "Email Agent",
48-
body: `Thanks for your email! You've sent us "${parsed.subject}". We'll process it shortly.`,
49-
});
50-
}
39+
async onEmail(email: AgentEmail) {
40+
const raw = await email.getRaw();
41+
const parsed = await PostalMime.parse(raw);
42+
43+
// create a response based on the email contents
44+
// and then send a reply
45+
46+
await this.replyToEmail(email, {
47+
fromName: "Email Agent",
48+
body: `Thanks for your email! You've sent us "${parsed.subject}". We'll process it shortly.`,
49+
});
50+
}
5151
}
5252
```
5353

5454
You route incoming mail like this:
5555

5656
```ts
5757
export default {
58-
async email(email, env) {
59-
await routeAgentEmail(email, env, {
60-
resolver: createAddressBasedEmailResolver("EmailAgent"),
61-
});
62-
},
58+
async email(email, env) {
59+
await routeAgentEmail(email, env, {
60+
resolver: createAddressBasedEmailResolver("EmailAgent"),
61+
});
62+
},
6363
};
6464
```
6565

@@ -71,14 +71,14 @@ Custom methods are now automatically wrapped with the agent's context, so callin
7171

7272
```ts
7373
export class MyAgent extends Agent {
74-
async suggestReply(message) {
75-
// getCurrentAgent() now correctly works, even when called inside an RPC method
76-
const { agent } = getCurrentAgent()!;
77-
return generateText({
78-
prompt: `Suggest a reply to: "${message}" from "${agent.name}"`,
79-
tools: [replyWithEmoji],
80-
});
81-
}
74+
async suggestReply(message) {
75+
// getCurrentAgent() now correctly works, even when called inside an RPC method
76+
const { agent } = getCurrentAgent()!;
77+
return generateText({
78+
prompt: `Suggest a reply to: "${message}" from "${agent.name}"`,
79+
tools: [replyWithEmoji],
80+
});
81+
}
8282
}
8383
```
8484

0 commit comments

Comments
 (0)