Skip to content

Commit 1b16c8b

Browse files
DidierRLopespiiq
andauthored
Update custom features example for object workspace_options (#93)
* custom features agent * readme and tests * Update openbb-ai --------- Co-authored-by: Theodore Aptekarev <aptekarev@gmail.com>
1 parent 2c5f9f5 commit 1b16c8b

5 files changed

Lines changed: 1139 additions & 911 deletions

File tree

37-vanilla-agent-custom-features/README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,18 @@ This is a simple example agent that demonstrates how to detect and report which
66

77
This agent:
88
- Greets users with a friendly hello message
9-
- Reports the status of custom features (Deep Research and Web Search)
10-
- Shows whether each feature is enabled (✅) or disabled (❌) based on the UI settings
9+
- Reports the status of custom features (Deep Research and Web Search)
10+
- Shows boolean, text, and select option values based on the UI settings
1111

1212
## Features
1313

14-
The agent defines two custom features in its configuration:
14+
The agent defines four custom features in its configuration:
1515
- **Deep Research**: Allows the agent to perform deep research (default: disabled)
1616
- **Web Search**: Allows the agent to search the web (default: enabled)
17+
- **Model**: Selects the model value sent to the agent
18+
- **Agent Name**: Sets the display name the agent uses in its response
1719

18-
Users can toggle these features on/off in the OpenBB Workspace UI, and the agent will detect and report the current status.
20+
Users can update these options in the OpenBB Workspace UI, and the agent will detect and report the current values from `workspace_options`.
1921

2022
## Getting started
2123

@@ -61,4 +63,4 @@ pytest tests
6163
6264
### Accessing the Documentation
6365
64-
Once the API server is running, you can view the documentation and interact with the API by visiting: http://localhost:7777/docs
66+
Once the API server is running, you can view the documentation and interact with the API by visiting: http://localhost:7777/docs

37-vanilla-agent-custom-features/tests/test_agent.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,12 @@ def test_query_with_workspace_options():
5757
"""Test query with workspace options to verify feature detection."""
5858
test_payload = {
5959
"messages": [{"role": "human", "content": "Hello, what features are enabled?"}],
60-
"workspace_options": {"deep-research": True, "web-search": False},
60+
"workspace_options": {
61+
"deep-research": True,
62+
"web-search": False,
63+
"model": "gpt-4o",
64+
"agent-name": "Test Agent",
65+
},
6166
}
6267

6368
with mock.patch("openai.AsyncOpenAI") as mock_openai:
@@ -73,6 +78,8 @@ async def mock_create(**kwargs):
7378
# Check that the system message contains the feature status
7479
assert "Deep Research: ✅ Enabled" in system_message
7580
assert "Web Search: ❌ Disabled" in system_message
81+
assert "Model: gpt-4o" in system_message
82+
assert "Agent Name: Test Agent" in system_message
7683

7784
# Return a mock stream
7885
class MockEvent:
@@ -84,7 +91,10 @@ class Delta:
8491

8592
choices = [Choice()]
8693

87-
yield MockEvent()
94+
async def stream():
95+
yield MockEvent()
96+
97+
return stream()
8898

8999
mock_client.chat.completions.create = mock_create
90100

@@ -109,6 +119,8 @@ async def mock_create(**kwargs):
109119
# Check that defaults are used (deep-research: False, web-search: True)
110120
assert "Deep Research: ❌ Disabled" in system_message
111121
assert "Web Search: ✅ Enabled" in system_message
122+
assert "Model: claude-sonnet-4-20250514" in system_message
123+
assert "Agent Name: Example Agent" in system_message
112124

113125
# Return a mock stream
114126
class MockEvent:
@@ -120,7 +132,10 @@ class Delta:
120132

121133
choices = [Choice()]
122134

123-
yield MockEvent()
135+
async def stream():
136+
yield MockEvent()
137+
138+
return stream()
124139

125140
mock_client.chat.completions.create = mock_create
126141

37-vanilla-agent-custom-features/vanilla_agent_custom_features/main.py

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -87,25 +87,18 @@ def get_copilot_description():
8787
async def query(request: QueryRequest) -> EventSourceResponse:
8888
"""Stream a simple greeting with feature status."""
8989

90-
# Check workspace_options from request payload
91-
# workspace_options is a list like ["web-search"] or ["deep-research", "web-search"]
92-
# Text/select features are sent as "key=value" entries
93-
workspace_options = getattr(request, "workspace_options", [])
94-
95-
# Helper to extract a value from "key=value" entries
96-
def get_option_value(key: str, default: str = "") -> str:
97-
for opt in workspace_options:
98-
if opt.startswith(f"{key}="):
99-
return opt.split("=", 1)[1]
100-
return default
90+
# Check workspace_options from request payload.
91+
# workspace_options is a dictionary like:
92+
# {"deep-research": true, "web-search": false, "model": "gpt-4o"}
93+
workspace_options = getattr(request, "workspace_options", {}) or {}
10194

10295
# Check which features are enabled
103-
deep_research_enabled = "deep-research" in workspace_options
104-
web_search_enabled = "web-search" in workspace_options
96+
deep_research_enabled = bool(workspace_options.get("deep-research", False))
97+
web_search_enabled = bool(workspace_options.get("web-search", True))
10598

10699
# Read text/select feature values
107-
model = get_option_value("model", "claude-sonnet-4-20250514")
108-
agent_name = get_option_value("agent-name", "Example Agent")
100+
model = workspace_options.get("model", "claude-sonnet-4-20250514")
101+
agent_name = workspace_options.get("agent-name", "Example Agent")
109102

110103
# Build the feature status message
111104
features_msg = (

0 commit comments

Comments
 (0)