Skip to content

Commit f9f6c4e

Browse files
elithrarOxyjun
andauthored
agents: Apply suggestions from code review
Co-authored-by: Jun Lee <[email protected]>
1 parent 7267caf commit f9f6c4e

File tree

12 files changed

+55
-41
lines changed

12 files changed

+55
-41
lines changed

src/content/docs/agents/concepts/calling-llms.mdx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@ sidebar:
88

99
import { Render } from "~/components";
1010

11-
### Understanding LLM Providers and Model Types
11+
### Understanding LLM providers and model types
1212

1313
Different LLM providers offer models optimized for specific types of tasks. When building AI systems, choosing the right model is crucial for both performance and cost efficiency.
1414

1515
#### Reasoning Models
16+
1617
Models like OpenAI's o1, Anthropic's Claude, and DeepSeek's R1 are particularly well-suited for complex reasoning tasks. These models excel at:
18+
1719
- Breaking down problems into steps
1820
- Following complex instructions
1921
- Maintaining context across long conversations
@@ -22,10 +24,11 @@ Models like OpenAI's o1, Anthropic's Claude, and DeepSeek's R1 are particularly
2224
For example, when implementing a travel booking system, you might use a reasoning model to analyze travel requirements and generate appropriate booking strategies.
2325

2426
#### Instruction Models
27+
2528
Models like GPT-4 and Claude Instant are optimized for following straightforward instructions efficiently. They work well for:
2629
- Content generation
2730
- Simple classification tasks
2831
- Basic question answering
2932
- Text transformation
3033

31-
These models are often more cost-effective for straightforward tasks that don't require complex reasoning.
34+
These models are often more cost-effective for straightforward tasks that do not require complex reasoning.

src/content/docs/agents/concepts/human-in-the-loop.mdx

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,39 +14,40 @@ Human-in-the-Loop (HITL) workflows integrate human judgment and oversight into a
1414

1515
![A human-in-the-loop diagram](~/assets/images/agents/human-in-the-loop.svg)
1616

17-
#### Understanding Human-in-the-Loop Workflows
17+
#### Understanding Human-in-the-Loop workflows
1818

19-
In a Human-in-the-Loop workflow, processes aren't fully automated. Instead, they include designated checkpoints where human intervention is required. For example, in a travel booking system, a human may want to confirm the travel before an agent follows through with a transaction. The workflow manages this interaction, ensuring that:
19+
In a Human-in-the-Loop workflow, processes are not fully automated. Instead, they include designated checkpoints where human intervention is required. For example, in a travel booking system, a human may want to confirm the travel before an agent follows through with a transaction. The workflow manages this interaction, ensuring that:
2020

2121
1. The process pauses at appropriate review points
2222
2. Human reviewers receive necessary context
2323
3. The system maintains state during the review period
2424
4. Review decisions are properly incorporated
25-
5. The process continues once approval is receive
25+
5. The process continues once approval is received
2626

27-
### Best Practices for Human-in-the-Loop Workflows
27+
### Best practices for Human-in-the-Loop workflows
2828

2929
#### Long-Term State Persistence
3030

31-
Human review processes don't operate on predictable timelines. A reviewer might need days or weeks to make a decision, especially for complex cases requiring additional investigation or multiple approvals. Your system needs to maintain perfect state consistency throughout this period, including:
31+
Human review processes do not operate on predictable timelines. A reviewer might need days or weeks to make a decision, especially for complex cases requiring additional investigation or multiple approvals. Your system needs to maintain perfect state consistency throughout this period, including:
32+
3233
- The original request and context
3334
- All intermediate decisions and actions
3435
- Any partial progress or temporary states
3536
- Review history and feedback
3637

37-
<Aside type="tip">
38-
[Durable Objects](https://developers.cloudflare.com/durable-objects/) provide an ideal solution for managing state in human-in-the-loop workflows, offering persistent compute instances that maintain state for hours, weeks, or months.
39-
</Aside>
38+
:::note[Tip]
39+
[Durable Objects](/durable-objects/) provide an ideal solution for managing state in Human-in-the-Loop workflows, offering persistent compute instances that maintain state for hours, weeks, or months.
40+
:::
4041

4142
#### Continuous Improvement Through Evals
4243

4344
Human reviewers play a crucial role in evaluating and improving LLM performance. Implement a systematic evaluation process where human feedback is collected not just on the final output, but on the LLM's decision-making process. This can include:
4445

4546
- Decision Quality Assessment: Have reviewers evaluate the LLM's reasoning process and decision points, not just the final output.
4647
- Edge Case Identification: Use human expertise to identify scenarios where the LLM's performance could be improved.
47-
- Feedback Collection: Gather structured feedback that can be used to fine-tune the LLM or adjust the workflow. [AI Gateway](https://developers.cloudflare.com/ai-gateway/evaluations/add-human-feedback/) can be a useful tool for setting up an LLM feedback loop.
48+
- Feedback Collection: Gather structured feedback that can be used to fine-tune the LLM or adjust the workflow. [AI Gateway](/ai-gateway/evaluations/add-human-feedback/) can be a useful tool for setting up an LLM feedback loop.
4849

49-
#### Error Handling and Recovery
50+
#### Error handling and recovery
5051

5152
Robust error handling is essential for maintaining workflow integrity. Your system should gracefully handle various failure scenarios, including reviewer unavailability, system outages, or conflicting reviews. Implement clear escalation paths for handling exceptional cases that fall outside normal parameters.
5253

src/content/docs/agents/concepts/tools.mdx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,29 @@ sidebar:
66

77
---
88

9-
### What are Tools?
9+
### What are tools?
1010

1111
Tools enable AI systems to interact with external services and perform actions. They provide a structured way for agents and workflows to invoke APIs, manipulate data, and integrate with external systems. Tools form the bridge between AI decision-making capabilities and real-world actions.
1212

13-
### Understanding Tools
13+
### Understanding tools
1414

1515
In an AI system, tools are typically implemented as function calls that the AI can use to accomplish specific tasks. For example, a travel booking agent might have tools for:
16+
1617
- Searching flight availability
1718
- Checking hotel rates
1819
- Processing payments
1920
- Sending confirmation emails
2021

2122
Each tool has a defined interface specifying its inputs, outputs, and expected behavior. This allows the AI system to understand when and how to use each tool appropriately.
2223

23-
### Common Tool Patterns
24+
### Common tool patterns
2425

25-
#### API Integration Tools
26+
#### API integration tools
2627

2728
The most common type of tools are those that wrap external APIs. These tools handle the complexity of API authentication, request formatting, and response parsing, presenting a clean interface to the AI system.
2829

2930
#### Model Context Protocol (MCP)
31+
3032
The (Model Context Protocol)[https://modelcontextprotocol.io/introduction] provides a standardized way to define and interact with tools. Think of it as an abstraction on top of APIs designed for LLMs to interact with external resources. MCP defines a consistent interface for:
3133

3234
- **Tool Discovery**: Systems can dynamically discover available tools
@@ -35,7 +37,8 @@ The (Model Context Protocol)[https://modelcontextprotocol.io/introduction] provi
3537
- **State Management**: Tools can maintain state across invocations
3638

3739

38-
#### Data Processing Tools
40+
#### Data processing tools
41+
3942
Tools that handle data transformation and analysis are essential for many AI workflows. These might include:
4043

4144
- CSV parsing and analysis

src/content/docs/agents/concepts/what-are-agents.mdx

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,33 @@ sidebar:
88

99
import { Render } from "~/components";
1010

11-
### What are agents?
11+
### What are agents?
12+
1213
An agent is an AI system that can autonomously execute tasks by making decisions about tool usage and process flow. Unlike traditional automation that follows predefined paths, agents can dynamically adapt their approach based on context and intermediate results. Agents are also distinct from co-pilots (e.g. traditional chat applications) in that they can fully automate a task, as opposed to simply augmenting and extending human input.
1314

1415
- **Agents** → non-linear, non-deterministic (can change from run to run)
1516
- **Workflows** → linear, deterministic execution paths
1617
- **Co-pilots** → augmentative AI assistance requiring human intervention
1718

18-
### Example: Booking Vacations
19-
If this is your first time working with, or interacting with agents, this example will illustrate how an agent works within a context like booking a vacation. If you're already familiar with the topic, read on.
19+
### Example: Booking vacations
20+
21+
If this is your first time working with, or interacting with agents, this example will illustrate how an agent works within a context like booking a vacation. If you are already familiar with the topic, read on.
2022

2123
Imagine you're trying to book a vacation. You need to research flights, find hotels, check restaurant reviews, and keep track of your budget.
2224

23-
##### Traditional Workflow Automation
25+
#### Traditional workflow automation
26+
2427
A traditional automation system follows a predetermined sequence:
28+
2529
- Takes specific inputs (dates, location, budget)
2630
- Calls predefined API endpoints in a fixed order
2731
- Returns results based on hardcoded criteria
2832
- Cannot adapt if unexpected situations arise
2933

3034
![Traditional workflow automation diagram](~/assets/images/agents/workflow-automation.svg)
3135

32-
##### AI Co-pilot
36+
#### AI Co-pilot
37+
3338
A co-pilot acts as an intelligent assistant that:
3439

3540
- Provides hotel and itinerary recommendations based on your preferences
@@ -39,7 +44,8 @@ A co-pilot acts as an intelligent assistant that:
3944

4045
![A co-pilot diagram](~/assets/images/agents/co-pilot.svg)
4146

42-
##### Agent
47+
#### Agent
48+
4349
An agent combines AI's ability to make judgements and call the relevant tools to execute the task. An agent's output will be nondeterministic given:
4450

4551
- Real-time availability and pricing changes
@@ -49,17 +55,18 @@ An agent combines AI's ability to make judgements and call the relevant tools to
4955

5056
![An agent diagram](~/assets/images/agents/agent-workflow.svg)
5157

52-
An agents can dynamically generate and itinerary and execute on booking reservations, similarly to what you would expect from a travel agent.
58+
An agents can dynamically generate an itinerary and execute on booking reservations, similarly to what you would expect from a travel agent.
5359

5460
### Three primary components of agent systems:
5561

5662
- **Decision Engine**: Usually an LLM (Large Language Model) that determines action steps
5763
- **Tool Integration**: APIs, functions, and services the agent can utilize
5864
- **Memory System**: Maintains context and tracks task progress
5965

60-
#### How Agents Work
66+
#### How agents work
6167

6268
Agents operate in a continuous loop of:
69+
6370
1. **Observing** the current state or task
6471
2. **Planning** what actions to take, using AI for reasoning
6572
3. **Executing** those actions using available tools (often APIs or [MCPs](https://modelcontextprotocol.io/introduction))

src/content/docs/agents/concepts/workflows.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ import { Render } from "~/components";
1111

1212
A workflow is the orchestration layer that coordinates how an agent's components work together. It defines the structured paths through which tasks are processed, tools are called, and results are managed. While agents make dynamic decisions about what to do, workflows provide the underlying framework that governs how those decisions are executed.
1313

14-
### Understanding Workflows in Agent Systems
14+
### Understanding workflows in agent systems
1515

1616
Think of a workflow like the operating procedures of a company. The company (agent) can make various decisions, but how those decisions get implemented follows established processes (workflows). For example, when you book a flight through a travel agent, they might make different decisions about which flights to recommend, but the process of actually booking the flight follows a fixed sequence of steps.
1717

1818
Let's examine a basic agent workflow:
1919

20-
### Core Components of a Workflow
20+
### Core components of a workflow
2121

2222
A workflow typically consists of several key elements:
2323

src/content/docs/agents/examples/manage-and-sync-state.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Agent state is stored in SQL database that associate with each indidivual Agent
1818

1919
### State API
2020

21-
Every agent has built-in state management capabilities. You can set and update the agent's state directly using `this.setState`:
21+
Every Agent has built-in state management capabilities. You can set and update the Agent's state directly using `this.setState`:
2222

2323
<TypeScriptExample>
2424

@@ -95,7 +95,7 @@ Clients can connect to an Agent and stay synchronized with its state using the R
9595

9696
The state synchronization system:
9797

98-
* Automatically syncs the agent's state to all connected clients
98+
* Automatically syncs the Agent's state to all connected clients
9999
* Handles client disconnections and reconnections gracefully
100100
* Provides immediate local updates
101101
* Supports multiple simultaneous client connections
@@ -106,7 +106,7 @@ Common use cases:
106106
* Multi-window/tab synchronization
107107
* Live updates across multiple devices
108108
* Maintaining consistent UI state across clients
109-
* When new clients connect, they automatically receive the current state from the agent, ensuring all clients start with the latest data.
109+
* When new clients connect, they automatically receive the current state from the Agent, ensuring all clients start with the latest data.
110110

111111
### SQL API
112112

src/content/docs/agents/examples/schedule-tasks.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,11 @@ Tasks that set a callback for a method that does not exist will fail silently.
6666

6767
:::
6868

69-
Calling `await this.schedule` returns a `Schedule`, which includes the task's randomly generated `id`. You can use this `id` to retrieve or cancel the task in the future. It also provides a `type` property that indicates the type of schedule - e.g. one of `"scheduled" | "delayed" | "cron"`.
69+
Calling `await this.schedule` returns a `Schedule`, which includes the task's randomly generated `id`. You can use this `id` to retrieve or cancel the task in the future. It also provides a `type` property that indicates the type of schedule, for example, one of `"scheduled" | "delayed" | "cron"`.
7070

7171
:::note[Maximum scheduled tasks]
7272

73-
Each task is mapped to a row in the Agent's underlying [SQLite database](/sqlite-in-durable-objects/), which means that each task can be up to 2MB in size. The maximum number of tasks must be `(task_size * tasks) + all_other_state < maximum_database_size` (currently 1GB per Agent).
73+
Each task is mapped to a row in the Agent's underlying [SQLite database](/sqlite-in-durable-objects/), which means that each task can be up to 2 MB in size. The maximum number of tasks must be `(task_size * tasks) + all_other_state < maximum_database_size` (currently 1GB per Agent).
7474

7575
:::
7676

src/content/docs/agents/examples/using-ai-models.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ sidebar:
88

99
import { MetaInfo, Render, Type, TypeScriptExample, WranglerConfig } from "~/components";
1010

11-
Agents can communicate with AI models hosted on any provider, including [Workers AI](/workers-ai/), OpenAI, Anthropic and Google's Gemini.
11+
Agents can communicate with AI models hosted on any provider, including [Workers AI](/workers-ai/), OpenAI, Anthropic, and Google's Gemini.
1212

13-
Because Agents are built on top of [Durable Objects](/durable-objects/), each agent or chat session is associated with a stateful compute instance. Tradtional serverless architectures often present challenges for persistent connections needed in real-time applications like chat.
13+
Because Agents are built on top of [Durable Objects](/durable-objects/), each Agent or chat session is associated with a stateful compute instance. Tradtional serverless architectures often present challenges for persistent connections needed in real-time applications like chat.
1414

1515
A user can disconnect during a long-running response from a modern reasoning model (such as `o3-mini` or DeepSeek R1), or lose conversational context when refreshing the browser. Instead of relying on request-response patterns and managing an external database to track & store conversation state, state can be stored directly within the Agent. If a client disconnects, the Agent can write to its own distributed storage, and catch the client up as soon as it reconnects: even if it's hours or days later.
1616

src/content/docs/agents/examples/websockets.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Users and clients can connect to an Agent directly over WebSockets, allowing lon
1212

1313
To enable an Agent to accept WebSockets, define `onConnect` and `onMessage` methods on your Agent.
1414

15-
* `onConnect(connection: Connection, ctx: ConnectionContext)` is called when a client establishes a new WebSocket connection. The original HTTP request, including request headers, cookies and the URL itself, are available on `ctx.request`.
15+
* `onConnect(connection: Connection, ctx: ConnectionContext)` is called when a client establishes a new WebSocket connection. The original HTTP request, including request headers, cookies, and the URL itself, are available on `ctx.request`.
1616
* `onMessage(connection: Connection, message: WSMessage)` is called for each incoming WebSocket message. Messages are one of `ArrayBuffer | ArrayBufferView | string`, and you can send messages back to a client using `connection.send()`. You can distinguish between client connections by checking `connection.id`, which is unique for each connected client.
1717

1818
Here's an example of an Agent that echoes back any message it receives:
@@ -55,7 +55,7 @@ export class ChatAgent extends Agent {
5555

5656
## Connecting clients
5757

58-
The Agent framework includes a useful helper package for connecting directly to your agent (or other agents) from a client application. Import `@cloudflare/agents/client`, create an instance of `AgentClient` and use it to connect to an instance of your Agent:
58+
The Agent framework includes a useful helper package for connecting directly to your Agent (or other Agents) from a client application. Import `@cloudflare/agents/client`, create an instance of `AgentClient` and use it to connect to an instance of your Agent:
5959

6060
<TypeScriptExample>
6161

@@ -120,7 +120,7 @@ function AgentInterface() {
120120
```
121121
</TypeScriptExample>
122122

123-
The `useAgent` hook automatically handles the lifecycle of the connection, ensuring that it is properly initialized and cleaned up when the component mounts and unmounts. You can also [combine `useAgent` with `useState`](/agents/examples/manage-and-sync-state/) to automatically synchronize state across all clients connected to your agent.
123+
The `useAgent` hook automatically handles the lifecycle of the connection, ensuring that it is properly initialized and cleaned up when the component mounts and unmounts. You can also [combine `useAgent` with `useState`](/agents/examples/manage-and-sync-state/) to automatically synchronize state across all clients connected to your Agent.
124124

125125
## Handling WebSocket events
126126

src/content/docs/agents/index.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ TODO - refine
4949
args={"--", "--template", "cloudflare/agents/starter"}
5050
/>
5151

52-
Head to the [Agents tutorial[(/getting-started/tutorial/) to dive into shipping your first Agent on Cloudflare.
52+
Head to the [Agents tutorial[(/agents/getting-started/tutorial/) to dive into shipping your first Agent on Cloudflare.
5353

5454
## Agents platform
5555

0 commit comments

Comments
 (0)