@octavus/docs 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/LICENSE +22 -0
  2. package/content/01-getting-started/01-introduction.md +93 -0
  3. package/content/01-getting-started/02-quickstart.md +268 -0
  4. package/content/01-getting-started/_meta.md +4 -0
  5. package/content/02-server-sdk/01-overview.md +133 -0
  6. package/content/02-server-sdk/02-sessions.md +164 -0
  7. package/content/02-server-sdk/03-tools.md +242 -0
  8. package/content/02-server-sdk/04-streaming.md +211 -0
  9. package/content/02-server-sdk/_meta.md +4 -0
  10. package/content/03-client-sdk/01-overview.md +148 -0
  11. package/content/03-client-sdk/02-messages.md +207 -0
  12. package/content/03-client-sdk/03-streaming.md +215 -0
  13. package/content/03-client-sdk/04-execution-blocks.md +231 -0
  14. package/content/03-client-sdk/_meta.md +4 -0
  15. package/content/04-protocol/01-overview.md +142 -0
  16. package/content/04-protocol/02-input-resources.md +200 -0
  17. package/content/04-protocol/03-triggers.md +209 -0
  18. package/content/04-protocol/04-tools.md +255 -0
  19. package/content/04-protocol/05-handlers.md +251 -0
  20. package/content/04-protocol/06-agent-config.md +215 -0
  21. package/content/04-protocol/_meta.md +4 -0
  22. package/content/05-api-reference/01-overview.md +129 -0
  23. package/content/05-api-reference/02-sessions.md +232 -0
  24. package/content/05-api-reference/03-agents.md +222 -0
  25. package/content/05-api-reference/_meta.md +4 -0
  26. package/dist/chunk-2YMRODFE.js +421 -0
  27. package/dist/chunk-2YMRODFE.js.map +1 -0
  28. package/dist/chunk-6JQ3OMGF.js +421 -0
  29. package/dist/chunk-6JQ3OMGF.js.map +1 -0
  30. package/dist/chunk-ESGSYVGK.js +421 -0
  31. package/dist/chunk-ESGSYVGK.js.map +1 -0
  32. package/dist/chunk-GDCTM2SV.js +421 -0
  33. package/dist/chunk-GDCTM2SV.js.map +1 -0
  34. package/dist/chunk-J26MLMLN.js +421 -0
  35. package/dist/chunk-J26MLMLN.js.map +1 -0
  36. package/dist/chunk-LWYMRXBF.js +421 -0
  37. package/dist/chunk-LWYMRXBF.js.map +1 -0
  38. package/dist/chunk-NFVJQNDP.js +421 -0
  39. package/dist/chunk-NFVJQNDP.js.map +1 -0
  40. package/dist/chunk-SCKIOGKI.js +421 -0
  41. package/dist/chunk-SCKIOGKI.js.map +1 -0
  42. package/dist/chunk-VWPQ6ORV.js +421 -0
  43. package/dist/chunk-VWPQ6ORV.js.map +1 -0
  44. package/dist/chunk-WUNFFJ32.js +421 -0
  45. package/dist/chunk-WUNFFJ32.js.map +1 -0
  46. package/dist/chunk-XVSMRXBJ.js +421 -0
  47. package/dist/chunk-XVSMRXBJ.js.map +1 -0
  48. package/dist/content.d.ts +37 -0
  49. package/dist/content.js +17 -0
  50. package/dist/content.js.map +1 -0
  51. package/dist/docs.json +173 -0
  52. package/dist/index.d.ts +2 -0
  53. package/dist/index.js +11 -0
  54. package/dist/index.js.map +1 -0
  55. package/dist/search-index.json +1 -0
  56. package/dist/search.d.ts +19 -0
  57. package/dist/search.js +30 -0
  58. package/dist/search.js.map +1 -0
  59. package/dist/sections.json +213 -0
  60. package/dist/types-BNRNBPDE.d.ts +28 -0
  61. package/dist/types-BltYGlWI.d.ts +36 -0
  62. package/package.json +52 -0
package/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Octavus AI
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
@@ -0,0 +1,93 @@
1
+ ---
2
+ title: Introduction
3
+ description: Overview of Octavus AI - an agent orchestration platform for developers.
4
+ ---
5
+
6
+ # Introduction to Octavus
7
+
8
+ Octavus is an agent orchestration platform that lets developers define, manage, and deploy AI agents through a unified service. It handles the orchestration layer so teams can focus on their agent logic and business requirements.
9
+
10
+ ## What is Octavus?
11
+
12
+ Building and managing AI agents is complex. Developers face challenges with:
13
+
14
+ - **Fragmented tooling** — No unified way to define, manage, and deploy agents
15
+ - **Prompt management** — Prompts are scattered across codebases, hard to version and iterate
16
+ - **Integration complexity** — Connecting agents to tools, resources, and other agents requires significant custom work
17
+ - **Observability** — Difficult to debug, monitor, and understand agent behavior in production
18
+ - **Infrastructure overhead** — Teams rebuild the same agent infrastructure repeatedly
19
+
20
+ Octavus solves these problems by providing:
21
+
22
+ - A **protocol-based approach** to defining agent behavior
23
+ - **Server and client SDKs** for easy integration
24
+ - **Built-in streaming** support for real-time responses
25
+ - **Tool execution** that runs on your servers with your data
26
+ - **Session management** for stateful conversations
27
+
28
+ ## Core Concepts
29
+
30
+ ### Agents
31
+
32
+ An **Agent** is the main entity in Octavus — a self-contained unit that defines how an AI agent behaves. Agents are defined using YAML protocols that specify:
33
+
34
+ - Input variables the agent accepts
35
+ - Triggers that invoke the agent (user messages, button clicks, API calls)
36
+ - Tools the agent can use
37
+ - Handlers that define execution flow
38
+
39
+ ### Sessions
40
+
41
+ A **Session** represents a conversation with an agent. Sessions:
42
+
43
+ - Store conversation history
44
+ - Track resources and variables
45
+ - Enable stateful interactions across multiple messages
46
+
47
+ ### Triggers
48
+
49
+ **Triggers** define how an agent is invoked:
50
+
51
+ - **User Message** — Respond to a text message in a chat interface
52
+ - **User Action** — Respond to UI actions (button clicks, form submissions)
53
+ - **API Call** — Direct invocation via SDK
54
+
55
+ ### Tools
56
+
57
+ **Tools** extend what agents can do:
58
+
59
+ - **External Tools** — Consumer-defined tools that call back to your systems
60
+ - **Internal Tools** — Built-in capabilities (web search, code execution)
61
+
62
+ Tools execute on your server, not on Octavus, giving you full control over data and authentication.
63
+
64
+ ## Architecture Overview
65
+
66
+ ```mermaid
67
+ sequenceDiagram
68
+ participant App as Your App
69
+ participant API as Octavus API
70
+ participant LLM as LLM Provider
71
+
72
+ App->>API: 1. Trigger action
73
+ API->>LLM: 2. Execute protocol
74
+ LLM-->>API: Response
75
+ API-->>App: 3. Stream events
76
+
77
+ Note over App: Tool request received
78
+ API-->>App: 4. Tool request
79
+ Note over App: 5. Execute tool locally
80
+ App->>API: 6. Return results
81
+
82
+ API->>LLM: 7. Continue
83
+ LLM-->>API: Response
84
+ API-->>App: 8. Stream response
85
+ ```
86
+
87
+ ## Next Steps
88
+
89
+ - [Quick Start](/docs/getting-started/quickstart) — Get your first agent running in minutes
90
+ - [Server SDK](/docs/server-sdk/overview) — Learn about backend integration
91
+ - [Client SDK](/docs/client-sdk/overview) — Build chat interfaces with React
92
+ - [Protocol Reference](/docs/protocol/overview) — Deep dive into agent protocols
93
+
@@ -0,0 +1,268 @@
1
+ ---
2
+ title: Quick Start
3
+ description: Get your first Octavus agent running in minutes.
4
+ ---
5
+
6
+ # Quick Start
7
+
8
+ This guide will walk you through integrating Octavus into your application in under 10 minutes.
9
+
10
+ ## Prerequisites
11
+
12
+ - Node.js 18+
13
+ - An Octavus account with API key
14
+ - A Next.js application (or any Node.js backend)
15
+
16
+ ## Installation
17
+
18
+ Install the Octavus SDKs in your project:
19
+
20
+ ```bash
21
+ # Server SDK for backend
22
+ npm install @octavus/server-sdk
23
+
24
+ # Client SDK for frontend (React)
25
+ npm install @octavus/client-sdk
26
+ ```
27
+
28
+ ## Backend Setup
29
+
30
+ ### 1. Initialize the Client
31
+
32
+ Create an Octavus client instance in your backend:
33
+
34
+ ```typescript
35
+ // lib/octavus.ts
36
+ import { OctavusClient } from '@octavus/server-sdk';
37
+
38
+ export const octavus = new OctavusClient({
39
+ baseUrl: process.env.OCTAVUS_API_URL!,
40
+ apiKey: process.env.OCTAVUS_API_KEY!,
41
+ });
42
+ ```
43
+
44
+ ### 2. Create a Session Endpoint
45
+
46
+ Create an API endpoint that creates sessions and returns the session ID:
47
+
48
+ ```typescript
49
+ // app/api/chat/create/route.ts
50
+ import { NextResponse } from 'next/server';
51
+ import { octavus } from '@/lib/octavus';
52
+
53
+ export async function POST(request: Request) {
54
+ const { agentId, input } = await request.json();
55
+
56
+ // Create a new session
57
+ const sessionId = await octavus.agentSessions.create(agentId, input);
58
+
59
+ return NextResponse.json({ sessionId });
60
+ }
61
+ ```
62
+
63
+ ### 3. Create a Trigger Endpoint
64
+
65
+ Create an endpoint that handles triggers and streams responses:
66
+
67
+ ```typescript
68
+ // app/api/trigger/route.ts
69
+ import { octavus } from '@/lib/octavus';
70
+
71
+ export async function POST(request: Request) {
72
+ const { sessionId, triggerName, input } = await request.json();
73
+
74
+ // Attach to session with tool handlers
75
+ const session = octavus.agentSessions.attach(sessionId, {
76
+ tools: {
77
+ // Define tool handlers that run on your server
78
+ 'get-user-account': async (args) => {
79
+ const userId = args.userId as string;
80
+ // Fetch from your database
81
+ return {
82
+ name: 'Demo User',
83
+ email: 'demo@example.com',
84
+ plan: 'pro',
85
+ };
86
+ },
87
+ 'create-support-ticket': async (args) => {
88
+ // Create ticket in your system
89
+ return {
90
+ ticketId: 'TICKET-123',
91
+ estimatedResponse: '24 hours',
92
+ };
93
+ },
94
+ },
95
+ });
96
+
97
+ // Trigger the action and get the stream
98
+ const { stream } = session.trigger(triggerName, input);
99
+
100
+ // Return as streaming response
101
+ return new Response(stream, {
102
+ headers: {
103
+ 'Content-Type': 'text/event-stream',
104
+ 'Cache-Control': 'no-cache',
105
+ Connection: 'keep-alive',
106
+ },
107
+ });
108
+ }
109
+ ```
110
+
111
+ ## Frontend Setup
112
+
113
+ ### 1. Create a Chat Component
114
+
115
+ Use the `useOctavusChat` hook to build a chat interface:
116
+
117
+ ```tsx
118
+ // components/chat.tsx
119
+ 'use client';
120
+
121
+ import { useOctavusChat } from '@octavus/client-sdk';
122
+ import { useState } from 'react';
123
+
124
+ interface ChatProps {
125
+ sessionId: string;
126
+ }
127
+
128
+ export function Chat({ sessionId }: ChatProps) {
129
+ const [inputValue, setInputValue] = useState('');
130
+
131
+ const {
132
+ messages,
133
+ status,
134
+ isLoading,
135
+ streamingText,
136
+ addUserMessage,
137
+ triggerAction,
138
+ } = useOctavusChat({
139
+ onTrigger: async (triggerName, input) => {
140
+ return fetch('/api/trigger', {
141
+ method: 'POST',
142
+ headers: { 'Content-Type': 'application/json' },
143
+ body: JSON.stringify({ sessionId, triggerName, input }),
144
+ });
145
+ },
146
+ });
147
+
148
+ const handleSubmit = async (e: React.FormEvent) => {
149
+ e.preventDefault();
150
+ if (!inputValue.trim() || isLoading) return;
151
+
152
+ const message = inputValue.trim();
153
+ setInputValue('');
154
+
155
+ // Add user message to UI
156
+ addUserMessage(message);
157
+
158
+ // Trigger the agent
159
+ await triggerAction('user-message', { USER_MESSAGE: message });
160
+ };
161
+
162
+ return (
163
+ <div className="flex flex-col h-full">
164
+ {/* Messages */}
165
+ <div className="flex-1 overflow-y-auto p-4 space-y-4">
166
+ {messages.map((msg) => (
167
+ <div
168
+ key={msg.id}
169
+ className={`p-3 rounded-lg ${
170
+ msg.role === 'user'
171
+ ? 'bg-blue-500 text-white ml-auto max-w-xs'
172
+ : 'bg-gray-100 max-w-md'
173
+ }`}
174
+ >
175
+ {msg.content}
176
+ </div>
177
+ ))}
178
+
179
+ {/* Streaming text */}
180
+ {streamingText && (
181
+ <div className="bg-gray-100 p-3 rounded-lg max-w-md">
182
+ {streamingText}
183
+ </div>
184
+ )}
185
+ </div>
186
+
187
+ {/* Input */}
188
+ <form onSubmit={handleSubmit} className="p-4 border-t">
189
+ <div className="flex gap-2">
190
+ <input
191
+ type="text"
192
+ value={inputValue}
193
+ onChange={(e) => setInputValue(e.target.value)}
194
+ placeholder="Type a message..."
195
+ className="flex-1 px-4 py-2 border rounded-lg"
196
+ disabled={isLoading}
197
+ />
198
+ <button
199
+ type="submit"
200
+ disabled={isLoading}
201
+ className="px-4 py-2 bg-blue-500 text-white rounded-lg disabled:opacity-50"
202
+ >
203
+ Send
204
+ </button>
205
+ </div>
206
+ </form>
207
+ </div>
208
+ );
209
+ }
210
+ ```
211
+
212
+ ### 2. Create Session and Render Chat
213
+
214
+ ```tsx
215
+ // app/chat/page.tsx
216
+ 'use client';
217
+
218
+ import { useEffect, useState } from 'react';
219
+ import { Chat } from '@/components/chat';
220
+
221
+ export default function ChatPage() {
222
+ const [sessionId, setSessionId] = useState<string | null>(null);
223
+
224
+ useEffect(() => {
225
+ async function createSession() {
226
+ const response = await fetch('/api/chat/create', {
227
+ method: 'POST',
228
+ headers: { 'Content-Type': 'application/json' },
229
+ body: JSON.stringify({
230
+ agentId: 'support-chat',
231
+ input: {
232
+ COMPANY_NAME: 'Acme Corp',
233
+ PRODUCT_NAME: 'Widget Pro',
234
+ },
235
+ }),
236
+ });
237
+ const { sessionId } = await response.json();
238
+ setSessionId(sessionId);
239
+ }
240
+
241
+ createSession();
242
+ }, []);
243
+
244
+ if (!sessionId) {
245
+ return <div>Loading...</div>;
246
+ }
247
+
248
+ return <Chat sessionId={sessionId} />;
249
+ }
250
+ ```
251
+
252
+ ## Environment Variables
253
+
254
+ Add these to your `.env.local`:
255
+
256
+ ```bash
257
+ OCTAVUS_API_URL=https://octavus.ai
258
+ OCTAVUS_API_KEY=your-api-key-here
259
+ ```
260
+
261
+ ## What's Next?
262
+
263
+ Now that you have a basic integration working:
264
+
265
+ - [Learn about the protocol](/docs/protocol/overview) to define custom agent behavior
266
+ - [Explore the Server SDK](/docs/server-sdk/overview) for advanced backend features
267
+ - [Build rich UIs](/docs/client-sdk/overview) with the Client SDK
268
+
@@ -0,0 +1,4 @@
1
+ ---
2
+ title: Getting Started
3
+ description: Learn the basics of Octavus and how to integrate AI agents into your application.
4
+ ---
@@ -0,0 +1,133 @@
1
+ ---
2
+ title: Overview
3
+ description: Introduction to the Octavus Server SDK for backend integration.
4
+ ---
5
+
6
+ # Server SDK Overview
7
+
8
+ The `@octavus/server-sdk` package provides a Node.js SDK for integrating Octavus agents into your backend application. It handles session management, streaming, and the tool execution continuation loop.
9
+
10
+ ## Installation
11
+
12
+ ```bash
13
+ npm install @octavus/server-sdk
14
+ ```
15
+
16
+ ## Basic Usage
17
+
18
+ ```typescript
19
+ import { OctavusClient } from '@octavus/server-sdk';
20
+
21
+ const client = new OctavusClient({
22
+ baseUrl: 'https://octavus.ai',
23
+ apiKey: 'your-api-key',
24
+ });
25
+ ```
26
+
27
+ ## Key Features
28
+
29
+ ### Session Management
30
+
31
+ Create and manage agent sessions:
32
+
33
+ ```typescript
34
+ // Create a new session
35
+ const sessionId = await client.agentSessions.create('support-chat', {
36
+ COMPANY_NAME: 'Acme Corp',
37
+ PRODUCT_NAME: 'Widget Pro',
38
+ });
39
+
40
+ // Get session state
41
+ const state = await client.agentSessions.get(sessionId);
42
+ ```
43
+
44
+ ### Tool Handlers
45
+
46
+ Tools run on your server with your data:
47
+
48
+ ```typescript
49
+ const session = client.agentSessions.attach(sessionId, {
50
+ tools: {
51
+ 'get-user-account': async (args) => {
52
+ // Access your database, APIs, etc.
53
+ return await db.users.findById(args.userId);
54
+ },
55
+ },
56
+ });
57
+ ```
58
+
59
+ ### Streaming
60
+
61
+ All responses stream in real-time:
62
+
63
+ ```typescript
64
+ const { stream } = session.trigger('user-message', {
65
+ USER_MESSAGE: 'Hello!'
66
+ });
67
+
68
+ // Use as a streaming response
69
+ return new Response(stream, {
70
+ headers: { 'Content-Type': 'text/event-stream' },
71
+ });
72
+ ```
73
+
74
+ ## API Reference
75
+
76
+ ### OctavusClient
77
+
78
+ The main entry point for interacting with Octavus.
79
+
80
+ ```typescript
81
+ interface OctavusClientConfig {
82
+ baseUrl: string; // Octavus API URL
83
+ apiKey?: string; // Your API key
84
+ }
85
+
86
+ class OctavusClient {
87
+ readonly agents: AgentsApi;
88
+ readonly agentSessions: AgentSessionsApi;
89
+
90
+ constructor(config: OctavusClientConfig);
91
+ }
92
+ ```
93
+
94
+ ### AgentSessionsApi
95
+
96
+ Manages agent sessions.
97
+
98
+ ```typescript
99
+ class AgentSessionsApi {
100
+ // Create a new session
101
+ async create(agentId: string, input?: Record<string, unknown>): Promise<string>;
102
+
103
+ // Get session state
104
+ async get(sessionId: string): Promise<SessionState>;
105
+
106
+ // Attach to a session for triggering
107
+ attach(sessionId: string, options?: SessionAttachOptions): AgentSession;
108
+ }
109
+ ```
110
+
111
+ ### AgentSession
112
+
113
+ Handles triggering and streaming for a specific session.
114
+
115
+ ```typescript
116
+ class AgentSession {
117
+ // Trigger an action and stream the response
118
+ trigger(
119
+ triggerName: string,
120
+ input?: Record<string, unknown>
121
+ ): { stream: ReadableStream<Uint8Array> };
122
+
123
+ // Get the session ID
124
+ getSessionId(): string;
125
+ }
126
+ ```
127
+
128
+ ## Next Steps
129
+
130
+ - [Sessions](/docs/server-sdk/sessions) — Deep dive into session management
131
+ - [Tools](/docs/server-sdk/tools) — Implementing tool handlers
132
+ - [Streaming](/docs/server-sdk/streaming) — Understanding stream events
133
+
@@ -0,0 +1,164 @@
1
+ ---
2
+ title: Sessions
3
+ description: Managing agent sessions with the Server SDK.
4
+ ---
5
+
6
+ # Sessions
7
+
8
+ Sessions represent conversations with an agent. They store conversation history, track resources and variables, and enable stateful interactions.
9
+
10
+ ## Creating Sessions
11
+
12
+ Create a session by specifying the agent ID and initial input variables:
13
+
14
+ ```typescript
15
+ import { OctavusClient } from '@octavus/server-sdk';
16
+
17
+ const client = new OctavusClient({
18
+ baseUrl: process.env.OCTAVUS_API_URL!,
19
+ apiKey: process.env.OCTAVUS_API_KEY!,
20
+ });
21
+
22
+ // Create a session with the support-chat agent
23
+ const sessionId = await client.agentSessions.create('support-chat', {
24
+ COMPANY_NAME: 'Acme Corp',
25
+ PRODUCT_NAME: 'Widget Pro',
26
+ USER_ID: 'user-123', // Optional inputs
27
+ });
28
+
29
+ console.log('Session created:', sessionId);
30
+ ```
31
+
32
+ ## Session State
33
+
34
+ Retrieve the current state of a session:
35
+
36
+ ```typescript
37
+ const state = await client.agentSessions.get(sessionId);
38
+
39
+ console.log({
40
+ id: state.id,
41
+ agentId: state.agentId,
42
+ messages: state.messages.length,
43
+ resources: state.resources,
44
+ variables: state.variables,
45
+ createdAt: state.createdAt,
46
+ updatedAt: state.updatedAt,
47
+ });
48
+ ```
49
+
50
+ ### SessionState Interface
51
+
52
+ ```typescript
53
+ interface SessionState {
54
+ id: string;
55
+ agentId: string;
56
+ input: Record<string, unknown>; // Initial input (immutable)
57
+ variables: Record<string, unknown>; // Mutable session variables
58
+ resources: Record<string, unknown>; // Resources (synced to consumer)
59
+ messages: ChatMessage[]; // Conversation history
60
+ createdAt: string;
61
+ updatedAt: string;
62
+ }
63
+ ```
64
+
65
+ ## Attaching to Sessions
66
+
67
+ To trigger actions on a session, you need to attach to it first:
68
+
69
+ ```typescript
70
+ const session = client.agentSessions.attach(sessionId, {
71
+ tools: {
72
+ // Tool handlers (see Tools documentation)
73
+ },
74
+ resources: [
75
+ // Resource watchers (optional)
76
+ ],
77
+ });
78
+ ```
79
+
80
+ ## Triggering Actions
81
+
82
+ Once attached, trigger actions on the session:
83
+
84
+ ```typescript
85
+ const { stream } = session.trigger('user-message', {
86
+ USER_MESSAGE: 'How do I reset my password?',
87
+ });
88
+
89
+ // Return the stream to your frontend
90
+ return new Response(stream, {
91
+ headers: { 'Content-Type': 'text/event-stream' },
92
+ });
93
+ ```
94
+
95
+ ## Session Lifecycle
96
+
97
+ ```mermaid
98
+ flowchart TD
99
+ A[1. CREATE] --> B[2. ATTACH]
100
+ B --> C[3. TRIGGER]
101
+ C --> C
102
+ C --> D[4. RETRIEVE]
103
+ D --> C
104
+ C --> E[5. EXPIRE]
105
+
106
+ A -.- A1["`**client.agentSessions.create()**
107
+ Returns sessionId
108
+ Initializes state`"]
109
+
110
+ B -.- B1["`**client.agentSessions.attach()**
111
+ Configure tool handlers
112
+ Configure resource watchers`"]
113
+
114
+ C -.- C1["`**session.trigger()**
115
+ Execute handler
116
+ Stream events
117
+ Update state`"]
118
+
119
+ D -.- D1["`**client.agentSessions.get()**
120
+ Get current state
121
+ Restore conversation`"]
122
+
123
+ E -.- E1["`Sessions expire after
124
+ 24 hours (configurable)`"]
125
+ ```
126
+
127
+ ## Restoring Sessions
128
+
129
+ When a user returns to your app, restore their session:
130
+
131
+ ```typescript
132
+ // On page load
133
+ const state = await client.agentSessions.get(sessionId);
134
+
135
+ // Pass messages to frontend to restore UI
136
+ return {
137
+ sessionId,
138
+ messages: state.messages,
139
+ resources: state.resources,
140
+ };
141
+ ```
142
+
143
+ The `messages` array includes all conversation history with proper content ordering (text, tool calls, thinking blocks), enabling accurate UI restoration.
144
+
145
+ ## Error Handling
146
+
147
+ ```typescript
148
+ import { ApiError } from '@octavus/server-sdk';
149
+
150
+ try {
151
+ const state = await client.agentSessions.get(sessionId);
152
+ } catch (error) {
153
+ if (error instanceof ApiError) {
154
+ if (error.status === 404) {
155
+ // Session not found or expired
156
+ console.log('Session expired, create a new one');
157
+ } else {
158
+ console.error('API Error:', error.message);
159
+ }
160
+ }
161
+ throw error;
162
+ }
163
+ ```
164
+