Skip to content

Commit ee95422

Browse files
committed
improve custom agent features
1 parent 496dc80 commit ee95422

1 file changed

Lines changed: 30 additions & 37 deletions

File tree

content/workspace/developers/ai-features/custom-agent-features.md

Lines changed: 30 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ title: Custom agent features
33
sidebar_position: 8
44
description: Configure and manage custom agent features based on workspace options
55
keywords:
6-
- features
7-
- configuration
8-
- workspace options
9-
- custom agents
10-
- SSE
6+
- features
7+
- configuration
8+
- workspace options
9+
- custom agents
10+
- SSE
1111
---
1212

1313
import HeadTitle from '@site/src/components/General/HeadTitle.tsx';
@@ -22,7 +22,6 @@ Reference implementation in [this GitHub repository](https://github.com/OpenBB-f
2222

2323
<img className="pro-border-gradient" width="500" alt="Custom agent features - on and off" src="https://openbb-cms.directus.app/assets/b7b268df-e576-4cc7-837d-d7358fef23bb.png" />
2424

25-
2625
## Architecture
2726

2827
Configure custom features in your agent's descriptor and access them through the query request payload. Features can have default states, descriptions, and labels.
@@ -92,10 +91,10 @@ return JSONResponse(content={
9291

9392
### OpenBB AI SDK
9493

95-
- `QueryRequest.workspace_options`: List of enabled feature entries
94+
- `QueryRequest.workspace_options`: Dictionary of option values keyed by option id
9695
- `message_chunk(text)`: Streams response content with feature-aware messaging
97-
- Boolean features appear as bare names: `"feature-name" in workspace_options`
98-
- Text and select features appear as `"key=value"` strings: `"model=gpt-4o"`, `"agent-name=My Bot"`
96+
- Boolean features appear as `true` or `false`: `workspace_options["web-search"]`
97+
- Text and select features appear as string values: `workspace_options["model"]`
9998

10099
## Core logic
101100

@@ -108,24 +107,16 @@ from sse_starlette.sse import EventSourceResponse
108107
@app.post("/v1/query")
109108
async def query(request: QueryRequest) -> EventSourceResponse:
110109
# Access workspace options from request payload
111-
# Boolean features appear as bare names: ["web-search", "deep-research"]
112-
# Text/select features appear as "key=value": ["model=gpt-4o", "agent-name=My Bot"]
113-
workspace_options = getattr(request, "workspace_options", [])
114-
115-
# Helper to extract a value from "key=value" entries
116-
def get_option_value(key: str, default: str = "") -> str:
117-
for opt in workspace_options:
118-
if opt.startswith(f"{key}="):
119-
return opt.split("=", 1)[1]
120-
return default
110+
# Example: {"web-search": true, "model": "gpt-4o", "agent-name": "My Bot"}
111+
workspace_options = getattr(request, "workspace_options", {}) or {}
121112

122113
# Check boolean features
123-
deep_research_enabled = "deep-research" in workspace_options
124-
web_search_enabled = "web-search" in workspace_options
114+
deep_research_enabled = bool(workspace_options.get("deep-research", False))
115+
web_search_enabled = bool(workspace_options.get("web-search", True))
125116

126117
# Read text/select feature values
127-
model = get_option_value("model", "claude-sonnet-4-20250514")
128-
agent_name = get_option_value("agent-name", "Example Agent")
118+
model = workspace_options.get("model", "claude-sonnet-4-20250514")
119+
agent_name = workspace_options.get("agent-name", "Example Agent")
129120

130121
# Build feature status message
131122
features_msg = (
@@ -176,7 +167,9 @@ async def query(request: QueryRequest) -> EventSourceResponse:
176167
## Feature types
177168

178169
### Boolean features
170+
179171
Simple on/off toggles with a label and default state:
172+
180173
```python
181174
"features": {
182175
"deep-research": {
@@ -188,7 +181,9 @@ Simple on/off toggles with a label and default state:
188181
```
189182

190183
### Text features
184+
191185
Free-form string input with an optional placeholder:
186+
192187
```python
193188
"features": {
194189
"agent-name": {
@@ -202,7 +197,9 @@ Free-form string input with an optional placeholder:
202197
```
203198

204199
### Select features
200+
205201
Dropdown selection with a list of options:
202+
206203
```python
207204
"features": {
208205
"model": {
@@ -221,22 +218,18 @@ Dropdown selection with a list of options:
221218
```
222219

223220
### Reading feature values
224-
Boolean features appear as bare names in `workspace_options`. Text and select features appear as `"key=value"` strings:
221+
222+
Boolean, text, and select values are sent in `workspace_options` as a dictionary keyed by option id:
223+
225224
```python
226-
workspace_options = getattr(request, "workspace_options", [])
225+
workspace_options = getattr(request, "workspace_options", {}) or {}
227226

228-
# Boolean features — check list membership
229-
if "deep-research" in workspace_options:
227+
# Boolean features
228+
if workspace_options.get("deep-research", False):
230229
# Enable deep research capabilities
231230
pass
232231

233-
# Text/select features — parse "key=value" entries
234-
def get_option_value(key: str, default: str = "") -> str:
235-
for opt in workspace_options:
236-
if opt.startswith(f"{key}="):
237-
return opt.split("=", 1)[1]
238-
return default
239-
240-
model = get_option_value("model", "claude-sonnet-4-20250514")
241-
agent_name = get_option_value("agent-name", "Example Agent")
242-
```
232+
# Text/select features
233+
model = workspace_options.get("model", "claude-sonnet-4-20250514")
234+
agent_name = workspace_options.get("agent-name", "Example Agent")
235+
```

0 commit comments

Comments
 (0)