You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/content/docs/agents/concepts/calling-llms.mdx
+5-2Lines changed: 5 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,12 +8,14 @@ sidebar:
8
8
9
9
import { Render } from"~/components";
10
10
11
-
### Understanding LLM Providers and Model Types
11
+
### Understanding LLM providers and model types
12
12
13
13
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.
14
14
15
15
#### Reasoning Models
16
+
16
17
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
+
17
19
- Breaking down problems into steps
18
20
- Following complex instructions
19
21
- Maintaining context across long conversations
@@ -22,10 +24,11 @@ Models like OpenAI's o1, Anthropic's Claude, and DeepSeek's R1 are particularly
22
24
For example, when implementing a travel booking system, you might use a reasoning model to analyze travel requirements and generate appropriate booking strategies.
23
25
24
26
#### Instruction Models
27
+
25
28
Models like GPT-4 and Claude Instant are optimized for following straightforward instructions efficiently. They work well for:
26
29
- Content generation
27
30
- Simple classification tasks
28
31
- Basic question answering
29
32
- Text transformation
30
33
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.
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:
20
20
21
21
1. The process pauses at appropriate review points
22
22
2. Human reviewers receive necessary context
23
23
3. The system maintains state during the review period
24
24
4. Review decisions are properly incorporated
25
-
5. The process continues once approval is receive
25
+
5. The process continues once approval is received
26
26
27
-
### Best Practices for Human-in-the-Loop Workflows
27
+
### Best practices for Human-in-the-Loop workflows
28
28
29
29
#### Long-Term State Persistence
30
30
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
+
32
33
- The original request and context
33
34
- All intermediate decisions and actions
34
35
- Any partial progress or temporary states
35
36
- Review history and feedback
36
37
37
-
<Asidetype="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
+
:::
40
41
41
42
#### Continuous Improvement Through Evals
42
43
43
44
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:
44
45
45
46
- Decision Quality Assessment: Have reviewers evaluate the LLM's reasoning process and decision points, not just the final output.
46
47
- 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.
48
49
49
-
#### Error Handling and Recovery
50
+
#### Error handling and recovery
50
51
51
52
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.
Copy file name to clipboardExpand all lines: src/content/docs/agents/concepts/tools.mdx
+8-5Lines changed: 8 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,27 +6,29 @@ sidebar:
6
6
7
7
---
8
8
9
-
### What are Tools?
9
+
### What are tools?
10
10
11
11
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.
12
12
13
-
### Understanding Tools
13
+
### Understanding tools
14
14
15
15
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
+
16
17
- Searching flight availability
17
18
- Checking hotel rates
18
19
- Processing payments
19
20
- Sending confirmation emails
20
21
21
22
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.
22
23
23
-
### Common Tool Patterns
24
+
### Common tool patterns
24
25
25
-
#### API Integration Tools
26
+
#### API integration tools
26
27
27
28
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.
28
29
29
30
#### Model Context Protocol (MCP)
31
+
30
32
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:
31
33
32
34
-**Tool Discovery**: Systems can dynamically discover available tools
@@ -35,7 +37,8 @@ The (Model Context Protocol)[https://modelcontextprotocol.io/introduction] provi
35
37
-**State Management**: Tools can maintain state across invocations
36
38
37
39
38
-
#### Data Processing Tools
40
+
#### Data processing tools
41
+
39
42
Tools that handle data transformation and analysis are essential for many AI workflows. These might include:
Copy file name to clipboardExpand all lines: src/content/docs/agents/concepts/what-are-agents.mdx
+15-8Lines changed: 15 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,28 +8,33 @@ sidebar:
8
8
9
9
import { Render } from"~/components";
10
10
11
-
### What are agents?
11
+
### What are agents?
12
+
12
13
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.
13
14
14
15
-**Agents** → non-linear, non-deterministic (can change from run to run)
-**Co-pilots** → augmentative AI assistance requiring human intervention
17
18
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.
20
22
21
23
Imagine you're trying to book a vacation. You need to research flights, find hotels, check restaurant reviews, and keep track of your budget.
22
24
23
-
##### Traditional Workflow Automation
25
+
#### Traditional workflow automation
26
+
24
27
A traditional automation system follows a predetermined sequence:
Copy file name to clipboardExpand all lines: src/content/docs/agents/concepts/workflows.mdx
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,13 +11,13 @@ import { Render } from "~/components";
11
11
12
12
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.
13
13
14
-
### Understanding Workflows in Agent Systems
14
+
### Understanding workflows in agent systems
15
15
16
16
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.
17
17
18
18
Let's examine a basic agent workflow:
19
19
20
-
### Core Components of a Workflow
20
+
### Core components of a workflow
21
21
22
22
A workflow typically consists of several key elements:
Copy file name to clipboardExpand all lines: src/content/docs/agents/examples/schedule-tasks.mdx
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -66,11 +66,11 @@ Tasks that set a callback for a method that does not exist will fail silently.
66
66
67
67
:::
68
68
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"`.
70
70
71
71
:::note[Maximum scheduled tasks]
72
72
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).
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.
12
12
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.
14
14
15
15
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.
Copy file name to clipboardExpand all lines: src/content/docs/agents/examples/websockets.mdx
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,7 +12,7 @@ Users and clients can connect to an Agent directly over WebSockets, allowing lon
12
12
13
13
To enable an Agent to accept WebSockets, define `onConnect` and `onMessage` methods on your Agent.
14
14
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`.
16
16
*`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.
17
17
18
18
Here's an example of an Agent that echoes back any message it receives:
@@ -55,7 +55,7 @@ export class ChatAgent extends Agent {
55
55
56
56
## Connecting clients
57
57
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:
59
59
60
60
<TypeScriptExample>
61
61
@@ -120,7 +120,7 @@ function AgentInterface() {
120
120
```
121
121
</TypeScriptExample>
122
122
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.
0 commit comments