Skip to content

Commit 765d15a

Browse files
committed
add changelog
1 parent 8c0104c commit 765d15a

File tree

2 files changed

+36
-46
lines changed

2 files changed

+36
-46
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
title: Build AI Agents with Example Prompts
3+
description:
4+
products:
5+
- agents
6+
- workers
7+
- workflows
8+
date: 2025-02-14T19:00:00Z
9+
---
10+
11+
We've added an [example prompt](/agents/build/prompts/) to help you get started with building AI agents and applications on Cloudflare Workers.
12+
13+
You can use this prompt with your favorite AI model, including Claude 3.5 Sonnet, OpenAI's o3-mini, Gemini 2.0 Flash, or Llama 3.3 on Workers AI. Models with large context windows will allow you to paste the prompt directly: provide your own prompt within the `<user_prompt></iser_prompt>` tags.
14+
15+
```sh
16+
{paste_prompt_here}
17+
<user_prompt>
18+
user: Build an AI agent using Cloudflare Workflows. The Workflow should run when a new GitHub issue is opened on a specific project with the label 'help' or 'bug', and attempt to help the user troubleshoot the issue by calling the OpenAI API with the issue title and description, and a clear, structured prompt that asks the model to suggest 1-3 possible solutions to the issue. Any code snippets should be formatted in Markdown code blocks. Documentation and sources should be referenced at the bottom of the response. The agent should then post the response to the GitHub issue. The agent should run as the provided GitHub bot account.
19+
</user_prompt>
20+
```
21+
22+
This prompt is still experimental, but we encourage you to try it out and [provide feedback](https://github.com/cloudflare/cloudflare-docs/issues/new?template=content.edit.yml).

src/content/docs/agents/build/prompts.md

Lines changed: 14 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -562,9 +562,9 @@ metadata: Record<string, string>;
562562
};
563563

564564
export class MyWorkflow extends WorkflowEntrypoint<Env, Params> {
565-
async run(event: WorkflowEvent<Params>, step: WorkflowStep) {
566-
// Can access bindings on `this.env`
567-
// Can access params on `event.payload`
565+
async run(event: WorkflowEvent<Params>, step: WorkflowStep) {
566+
// Can access bindings on `this.env`
567+
// Can access params on `event.payload`
568568

569569
const files = await step.do('my first step', async () => {
570570
// Fetch a list of files from $SOME_SERVICE
@@ -628,14 +628,22 @@ let url = new URL(req.url);
628628
});
629629
}
630630

631+
const data = await req.json()
632+
631633
// Spawn a new instance and return the ID and status
632-
let instance = await env.MY_WORKFLOW.create();
634+
let instance = await env.MY_WORKFLOW.create({
635+
// Define an ID for the Workflow instance
636+
id: crypto.randomUUID(),
637+
// Pass data to the Workflow instance
638+
// Available on the WorkflowEvent
639+
params: data,
640+
});
641+
633642
return Response.json({
634643
id: instance.id,
635644
details: await instance.status(),
636645
});
637-
638-
},
646+
},
639647
};
640648
</code>
641649

@@ -744,46 +752,6 @@ curl "<https://api.cloudflare.com/client/v4/accounts/{account_id}/analytics_engi
744752

745753
</code_examples>
746754

747-
<api_patterns>
748-
<pattern id="websocket_coordination">
749-
<description>
750-
Fan-in/fan-out for WebSockets. Uses the Hibernatable WebSockets API within Durable Objects. Does NOT use the legacy addEventListener API.
751-
</description>
752-
<implementation>
753-
export class WebSocketHibernationServer extends DurableObject {
754-
async fetch(request: Request, env: Env, ctx: ExecutionContext) {
755-
// Creates two ends of a WebSocket connection.
756-
const webSocketPair = new WebSocketPair();
757-
const [client, server] = Object.values(webSocketPair);
758-
759-
// Call this to accept the WebSocket connection.
760-
// Do NOT call server.accept() (this is the legacy approach and is not preferred)
761-
this.ctx.acceptWebSocket(server);
762-
763-
return new Response(null, {
764-
status: 101,
765-
webSocket: client,
766-
});
767-
},
768-
769-
async webSocketMessage(ws: WebSocket, message: string | ArrayBuffer): void | Promise<void> {
770-
// Invoked on each WebSocket message.
771-
ws.send(message)
772-
},
773-
774-
async webSocketClose(ws: WebSocket, code: number, reason: string, wasClean: boolean) void | Promise<void> {
775-
// Invoked when a client closes the connection.
776-
ws.close(code, "<message>");
777-
},
778-
779-
async webSocketError(ws: WebSocket, error: unknown): void | Promise<void> {
780-
// Handle WebSocket errors
781-
}
782-
}
783-
</implementation>
784-
</pattern>
785-
</api_patterns>
786-
787755
<user_prompt>
788756
{user_prompt}
789757
</user_prompt>

0 commit comments

Comments
 (0)