Skip to content

Commit e3997a2

Browse files
committed
sse
1 parent d60546c commit e3997a2

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

src/content/docs/agents/api-reference/http-sse.mdx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,13 @@ Review the [Agents API reference](/agents/api-reference/agents-api/) to learn mo
3838

3939
### Implementing Server-Sent Events
4040

41-
The Agents SDK support Server-Sent Events:
41+
The Agents SDK support Server-Sent Events directly: you can use SSE to stream data back to the client over a long running connection. This avoids buffering large responses, which can both make your Agent feel slow, and forces you to buffer the entire response in memory.
4242

43-
The below example uses the AI SDK to generate text and stream it back to the client. It will automatically stream
43+
When an Agent is deployed to Cloudflare Workers, there is no effective limit on the total time it takes to stream the response back: large AI model responses that take several minutes to reason and then respond will not be prematurely terminated.
44+
45+
Note that this does not mean the client can't potentially disconnect during the streaming process: you can account for this by either [writing to the Agent's stateful storage](/agents/api-reference/store-and-sync-state/) and/or [using WebSockets](/agents/api-reference/websockets/). Because you can always [route to the same Agent](/agents/api-reference/calling-agents/), you do not need to use a centralized session store to pick back up where you left off when a client disconnects.
46+
47+
The following example uses the AI SDK to generate text and stream it back to the client. It will automatically stream the response back to the client as the model generates it:
4448

4549
<TypeScriptExample>
4650

@@ -84,15 +88,18 @@ export class MyAgent extends Agent<Env> {
8488

8589
export default {
8690
async fetch(request: Request, env: Env) {
87-
const agent = await getAgentByName<Env, MyAgent>(env.MyAgent, 'agent');
91+
let agentId = new URL(request.url).searchParams.get('agent-id') || '';
92+
const agent = await getAgentByName<Env, MyAgent>(env.MyAgent, agentId);
8893
return agent.fetch(request);
8994
},
9095
};
9196
```
9297

98+
99+
93100
</TypeScriptExample>
94101

95102
## WebSockets vs. Server-Sent Events
96103

97-
TODO
104+
98105

src/content/docs/agents/getting-started/quickstart.mdx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,6 @@ TODO;
155155
- Adding a new tool
156156
157157
158-
</TypeScriptExample>
159-
160158
### Optional: Clean-up
161159
162160
TODO: delete

0 commit comments

Comments
 (0)