Skip to content

Commit 65b6205

Browse files
ikhareConvex, Inc.
authored and
Convex, Inc.
committed
Update left nav for docs + agents doc (#36476)
GitOrigin-RevId: 538a82feef01934a28c2a1773726012b21f8668b
1 parent bec0fab commit 65b6205

File tree

4 files changed

+135
-0
lines changed

4 files changed

+135
-0
lines changed

npm-packages/docs/docs/agents.mdx

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
---
2+
title: "AI Agents"
3+
sidebar_position: 100
4+
description: "Building AI Agents with Convex"
5+
---
6+
7+
# Building AI Agents with Convex
8+
9+
Convex provides a powerful platform for building AI agents through its robust
10+
set of components.
11+
12+
## Why Convex for AI Agents?
13+
14+
Convex offers several advantages for building AI agents:
15+
16+
1. **Durable Execution**: Long-running workflows that survive server restarts
17+
2. **Real-time State Management**: Reactive state updates for agent progress
18+
3. **Built-in Persistence**: Store conversation history and agent state
19+
4. **Parallel Processing**: Run multiple agent tasks concurrently
20+
5. **Error Handling**: Robust retry mechanisms for API calls
21+
22+
## Core Components
23+
24+
The [Agent](https://www.convex.dev/components/agent) and
25+
[Workflow](https://www.convex.dev/components/workflow) components can be used
26+
together to create powerful long running agents with memory.
27+
28+
Learn more by reading:
29+
[AI Agents with Built-in Memory](https://stack.convex.dev/ai-agents).
30+
31+
Sample code:
32+
33+
```typescript
34+
// Define an agent similarly to the AI SDK
35+
const supportAgent = new Agent(components.agent, {
36+
chat: openai.chat("gpt-4o-mini"),
37+
textEmbedding: openai.embedding("text-embedding-3-small"),
38+
instructions: "You are a helpful assistant.",
39+
tools: { accountLookup, fileTicket, sendEmail },
40+
});
41+
42+
// Use the agent from within a normal action:
43+
export const createThread = action({
44+
args: { prompt: v.string() },
45+
handler: async (ctx, { prompt }) => {
46+
const { threadId, thread } = await supportAgent.createThread(ctx);
47+
const result = await thread.generateText({ prompt });
48+
return { threadId, text: result.text };
49+
},
50+
});
51+
52+
// Pick up where you left off, with the same or a different agent:
53+
export const continueThread = action({
54+
args: { prompt: v.string(), threadId: v.string() },
55+
handler: async (ctx, { prompt, threadId }) => {
56+
// This includes previous message history from the thread automatically.
57+
const { thread } = await anotherAgent.continueThread(ctx, { threadId });
58+
const result = await thread.generateText({ prompt });
59+
return result.text;
60+
},
61+
});
62+
63+
// Or use it within a workflow, specific to a user:
64+
export const supportAgentStep = supportAgent.asAction({ maxSteps: 10 });
65+
66+
const workflow = new WorkflowManager(components.workflow);
67+
const s = internal.example; // where steps are defined
68+
69+
export const supportAgentWorkflow = workflow.define({
70+
args: { prompt: v.string(), userId: v.string(), threadId: v.string() },
71+
handler: async (step, { prompt, userId, threadId }) => {
72+
const suggestion = await step.runAction(s.supportAgentStep, {
73+
threadId,
74+
generateText: { prompt },
75+
});
76+
const polished = await step.runAction(s.adaptSuggestionForUser, {
77+
suggestion,
78+
userId,
79+
});
80+
await step.runMutation(s.sendUserMessage, {
81+
userId,
82+
message: polished.message,
83+
});
84+
},
85+
});
86+
```
87+
88+
## Other Components
89+
90+
Convex also provides other components to help you build reliable AI
91+
applications.
92+
93+
The
94+
[Persistent Text Streaming](https://www.convex.dev/components/persistent-text-streaming)
95+
component provides a React hook for streaming text from HTTP actions while
96+
simultaneously storing the data in the database. This persistence allows the
97+
text to be accessed after the stream ends or by other users.
98+
99+
The [Action Retrier](https://www.convex.dev/components/retrier) Component is
100+
useful for one of flaky AI calls that you want to automatically retry. It will
101+
run the action and retry it on failure, sleeping with exponential backoff, until
102+
the action succeeds or the maximum number of retries is reached.
103+
104+
The [Workpool](https://www.convex.dev/components/workpool) Component lets you
105+
create tiers of parallelism to handle large number of external requests.

npm-packages/docs/sidebars.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,29 @@ const sidebars = {
107107
items: [{ type: "autogenerated", dirName: "components" }],
108108
className: "convex-sidebar-components",
109109
},
110+
111+
{
112+
type: "html",
113+
value: '<hr class="convex-menu-divider" />',
114+
defaultStyle: false,
115+
},
116+
{
117+
type: "html",
118+
value: '<div class="convex-menu-header">Guides</div>',
119+
defaultStyle: false,
120+
},
110121
{
111122
type: "category",
112123
label: "AI Code Gen",
113124
link: { type: "doc", id: "ai" },
114125
items: [{ type: "autogenerated", dirName: "ai" }],
115126
className: "convex-sidebar-ai",
116127
},
128+
{
129+
type: "doc",
130+
id: "agents",
131+
className: "convex-sidebar-ai-agents",
132+
},
117133
{
118134
type: "category",
119135
label: "Testing",

npm-packages/docs/src/css/custom.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,10 @@ html[data-theme="dark"] .convex-menu-header {
721721
--convex-icon: url("../../static/img/sidebar-icons/magic-wand.svg");
722722
}
723723

724+
.convex-sidebar-ai-agents {
725+
--convex-icon: url("../../static/img/sidebar-icons/bot.svg");
726+
}
727+
724728
.convex-sidebar-production {
725729
--convex-icon: url("../../static/img/sidebar-icons/paper-plane.svg");
726730
}
Lines changed: 10 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)