@@ -16,15 +16,15 @@ You can use `.queue()` to enqueue background work — ideal for tasks like proce
1616
1717``` ts
1818class 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
3838export 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
5454You route incoming mail like this:
5555
5656``` ts
5757export 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
7373export 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