-
Notifications
You must be signed in to change notification settings - Fork 9.9k
agents sdk changelog (email, .queue and automatic context) #23828
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
+84
−0
Closed
Changes from 7 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
f876f65
agents sdk changelog
whoiskatrin 7d10817
simplify examples
whoiskatrin ca349c2
simplify examples
whoiskatrin 68fc25f
simplify examples
whoiskatrin 22c6436
simplify examples
whoiskatrin a6563a0
Update src/content/changelog/agents/2025-07-21-agents-queue-email-con…
whoiskatrin 8f805fa
fixed trailing
whoiskatrin 179ecd5
small fixes and typos
whoiskatrin daf9d82
fix hyperlink
whoiskatrin c6a6781
Update 2025-07-21-agents-queue-email-context-update.mdx
threepointone 3f5e6b6
Update 2025-07-21-agents-queue-email-context-update.mdx
threepointone File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
85 changes: 85 additions & 0 deletions
85
src/content/changelog/agents/2025-07-21-agents-queue-email-context-update.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| --- | ||
| title: Agents SDK now supports task queues, email handling, and context-wrapped methods | ||
| description: The latest release adds .queue(), email support, and automatic context for custom methods | ||
| products: | ||
| - agents | ||
| - workers | ||
| - workflows | ||
| date: 2025-07-21 | ||
| --- | ||
|
|
||
| The latest releases of [@cloudflare/agents] (https://github.com/cloudflare/agents) brings three powerful improvements that make building and scaling agents even easier. You now get: | ||
|
|
||
| ### Lightweight .queue for fast task deferral | ||
|
|
||
| You can use .queue() to enqueue background work — ideal for tasks like processing user messages, sending notifications etc. | ||
whoiskatrin marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ```ts | ||
| class MyAgent extends Agent { | ||
| doSomethingExpensive(payload) { | ||
| // a long running process that you want to run in the background | ||
| } | ||
|
|
||
| queueSomething() { | ||
| await this.queue("doSomethingExpensive", somePayload); // this will NOT block further execution, and runs in the background | ||
| await this.queue("doSomethingExpensive", someOtherPayload); // the callback will NOT run until the previous callback is complete | ||
| // ... call as many times as you want | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| Want to try it yourself? Just define a method like processMessage in your agent, and you’re ready to scale. | ||
|
|
||
| ### New email adaptor | ||
|
|
||
| Want to build an AI agent that can receive and respond to emails automatically? With the new email adaptor and onEmail lifecycle method, now you can. | ||
whoiskatrin marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ```ts | ||
| export class EmailAgent extends Agent { | ||
| async onEmail(email: AgentEmail) { | ||
| const raw = await email.getRaw(); | ||
| const parsed = await PostalMime.parse(raw); | ||
|
|
||
| // create a response based on the email contents | ||
| // and then send a reply | ||
|
|
||
| await this.replyToEmail(email, { | ||
| fromName: "Email Agent", | ||
| body: `Thanks for your email! You've sent us "${parsed.subject}". We'll process it shortly.`, | ||
| }); | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| You route incoming mail like this: | ||
|
|
||
| ```ts | ||
| export default { | ||
| async email(email, env) { | ||
| await routeAgentEmail(email, env, { | ||
| resolver: createAddressBasedEmailResolver("EmailAgent"), | ||
| }); | ||
| }, | ||
| }; | ||
| ``` | ||
|
|
||
| You can find a full example [here](https://github.com/cloudflare/agents/tree/main/examples/email-agent). | ||
|
|
||
| ### Automatic context wrapping for custom methods | ||
|
|
||
| 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. | ||
whoiskatrin marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ```ts | ||
| export class MyAgent extends Agent { | ||
| async suggestReply(ctx, { message }) { | ||
whoiskatrin marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| // getCurrentAgent() now correctly works, even when called inside an RPC method | ||
| const { agent } = getCurrentAgent()!; | ||
| return generateText({ | ||
| prompt: `Suggest a reply to: "${message}" from "${agent.name}"`, | ||
| tools: [replyWithEmoji], | ||
| }); | ||
| } | ||
| } | ||
whoiskatrin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ``` | ||
|
|
||
| Try it out and tell us what you build! | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.