Tools
Tools extend what agents can do. In Octavus, tools can execute either on your server or on the client side.
Server Tools vs Client Tools
| Location | Use Case | Registration |
|---|---|---|
| Server | Database queries, API calls, sensitive operations | Register handler in attach() |
| Client | Browser APIs, interactive UIs, confirmations | No server handler (forwarded to client) |
When the Server SDK encounters a tool call:
- Handler exists → Execute on server, continue automatically
- No handler → Forward to client via
client-tool-requestevent
For client-side tool handling, see Client Tools.
Why Server Tools
Server-side tools give you full control:
- ✅ Full data access — Query your database directly
- ✅ Your authentication — Use your existing auth context
- ✅ No data exposure — Sensitive data never leaves your infrastructure
- ✅ Custom logic — Any complexity you need
Defining Tool Handlers
Tool handlers are async functions that receive arguments and return results:
typescript
Using Tools in Sessions
Pass tool handlers when attaching to a session:
typescript
Tool Handler Signature
typescript
Arguments
Arguments are passed as a Record<string, unknown>. Type-check as needed:
typescript
Return Values
Return any JSON-serializable value. The result is:
- Sent back to the LLM as context
- Stored in session state
- Optionally stored in a variable for protocol use
typescript
Error Handling
Throw errors for failures. They're captured and sent to the LLM:
typescript
The LLM receives the error message and can respond appropriately (e.g., "I couldn't find that account").
Tool Execution Flow
When the LLM calls a tool:
Rendering diagram...
Accessing Request Context
For request-specific data (auth, headers), create handlers dynamically:
typescript
Best Practices
1. Validate Arguments
typescript
2. Handle Timeouts
typescript
3. Log Tool Calls
typescript