Skip to content

Commit ca349c2

Browse files
simplify examples
Co-authored-by: Sunil Pai <[email protected]>
1 parent 7d10817 commit ca349c2

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,18 +96,20 @@ You can find a full example [here] (cloudflare/agents/examples/email-agent)
9696

9797
### Automatic context wrapping for custom methods
9898

99-
Defining custom methods on your agent is now even safer and cleaner. This means getCurrentAgent(), getCurrentRequest(), and getCurrentConnection() are now reliably accessible from anywhere in your agentnot just inside onRequest.
99+
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.
100+
101+
100102

101103
```ts
102-
export class MyAgent extends Agent<Env, State> {
104+
export class MyAgent extends Agent {
103105
async suggestReply(ctx, { message }) {
104-
// getCurrentAgent() now works!
106+
// getCurrentAgent() now correctly works, even when called inside an RPC method
107+
const { agent } = getCurrentAgent()!;
105108
return generateText({
106-
prompt: `Suggest a reply to: "${message}"`,
109+
prompt: `Suggest a reply to: "${message}" from "${agent.name}"`,
107110
tools: [replyWithEmoji],
108111
});
109112
}
110113
}
111-
```
112114
113115
Try it out and tell us what you build!

0 commit comments

Comments
 (0)