Skip to content

Commit 532ac23

Browse files
Add topk example and add search default
1 parent 8e8e2e3 commit 532ac23

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

examples/search_tool_example.py

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,37 @@ def example_search_modes():
114114
print()
115115

116116

117+
def example_top_k_config():
118+
"""Configuring top_k at the constructor level vs per-call.
119+
120+
Constructor-level top_k applies to all search_tools() and search_action_names()
121+
calls. Per-call top_k overrides the constructor default for that single call.
122+
"""
123+
print("Example 3: top_k at constructor vs per-call\n")
124+
125+
# Constructor-level top_k — all calls default to returning 3 results
126+
toolset = StackOneToolSet(search={"top_k": 3})
127+
128+
query = "manage employee records"
129+
print(f'Constructor top_k=3: searching for "{query}"')
130+
tools_default = toolset.search_tools(query, account_ids=_account_ids)
131+
print(f" Got {len(tools_default)} tools (constructor default)")
132+
for tool in tools_default:
133+
print(f" - {tool.name}")
134+
print()
135+
136+
# Per-call override — this single call returns up to 10 results
137+
print("Per-call top_k=10: overriding constructor default")
138+
tools_override = toolset.search_tools(query, account_ids=_account_ids, top_k=10)
139+
print(f" Got {len(tools_override)} tools (per-call override)")
140+
for tool in tools_override:
141+
print(f" - {tool.name}")
142+
print()
143+
144+
117145
def example_search_tool_with_execution():
118146
"""Example of discovering and executing tools dynamically"""
119-
print("Example 3: Dynamic tool execution\n")
147+
print("Example 4: Dynamic tool execution\n")
120148

121149
# Initialize toolset
122150
toolset = StackOneToolSet()
@@ -151,7 +179,7 @@ def example_search_tool_with_execution():
151179

152180
def example_with_openai():
153181
"""Example of using search tool with OpenAI"""
154-
print("Example 4: Using search tool with OpenAI\n")
182+
print("Example 5: Using search tool with OpenAI\n")
155183

156184
try:
157185
from openai import OpenAI
@@ -199,7 +227,7 @@ def example_with_openai():
199227

200228
def example_with_langchain():
201229
"""Example of using tools with LangChain"""
202-
print("Example 5: Using tools with LangChain\n")
230+
print("Example 6: Using tools with LangChain\n")
203231

204232
try:
205233
from langchain.agents import AgentExecutor, create_tool_calling_agent
@@ -267,6 +295,7 @@ def main():
267295
# Basic examples that work without external APIs
268296
example_search_tool_basic()
269297
example_search_modes()
298+
example_top_k_config()
270299
example_search_tool_with_execution()
271300

272301
# Examples that require OpenAI API

stackone_ai/toolset.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class SearchConfig(TypedDict, total=False):
5252
"""Minimum similarity score threshold 0-1."""
5353

5454

55-
_SEARCH_DEFAULT: SearchConfig = {}
55+
_SEARCH_DEFAULT: SearchConfig = {"method": "auto"}
5656

5757
try:
5858
_SDK_VERSION = metadata.version("stackone-ai")

0 commit comments

Comments
 (0)