|
1 | 1 | """ |
2 | 2 | Get available tools from your StackOne organisation based on the account id. |
3 | 3 |
|
| 4 | +This example demonstrates different ways to filter and organize tools: |
| 5 | +1. Getting all available tools |
| 6 | +2. Filtering by vertical |
| 7 | +3. Using multiple patterns for cross-vertical functionality |
| 8 | +4. Filtering by specific operations |
| 9 | +5. Combining multiple operation patterns |
| 10 | +
|
| 11 | +# TODO: experimental - get_available_tools(account_id="your_account_id") |
| 12 | +
|
4 | 13 | ```bash |
5 | 14 | uv run examples/available_tools.py |
6 | 15 | ``` |
7 | 16 | """ |
8 | 17 |
|
| 18 | +from dotenv import load_dotenv |
| 19 | +from stackone_ai import StackOneToolSet |
| 20 | + |
| 21 | +load_dotenv() |
| 22 | + |
| 23 | + |
| 24 | +def get_available_tools() -> None: |
| 25 | + toolset = StackOneToolSet() |
| 26 | + |
| 27 | + # First, get all tools |
| 28 | + all_tools = toolset.get_tools() |
| 29 | + assert len(all_tools) > 100, "Expected at least 100 tools in total" |
| 30 | + |
| 31 | + # Then, let's get just HRIS tools using a vertical filter |
| 32 | + hris_tools = toolset.get_tools("hris_*") |
| 33 | + assert len(hris_tools) > 10, "Expected at least 10 HRIS tools" |
| 34 | + |
| 35 | + # Now, let's get people-related tools across verticals |
| 36 | + people_tools = toolset.get_tools( |
| 37 | + [ |
| 38 | + "hris_*employee*", |
| 39 | + "crm_*contact*", |
| 40 | + ] |
| 41 | + ) |
| 42 | + assert len(people_tools) > 20, "Expected at least 20 people-related tools" |
| 43 | + for tool in people_tools: |
| 44 | + assert "employee" in tool.name or "contact" in tool.name, ( |
| 45 | + f"Tool {tool.name} doesn't contain 'employee' or 'contact'" |
| 46 | + ) |
| 47 | + |
| 48 | + # We can also filter by specific operations across all verticals |
| 49 | + upload_tools = toolset.get_tools("*upload*") |
| 50 | + assert len(upload_tools) > 0, "Expected at least one upload tool" |
| 51 | + for tool in upload_tools: |
| 52 | + assert "upload" in tool.name.lower(), f"Tool {tool.name} doesn't contain 'upload'" |
| 53 | + |
| 54 | + # Get all tools except HRIS |
| 55 | + non_hris_tools = toolset.get_tools("!hris_*") |
| 56 | + assert len(non_hris_tools) > 0, "Expected at least one non-HRIS tool" |
| 57 | + for tool in non_hris_tools: |
| 58 | + assert not tool.name.startswith("hris_"), f"Tool {tool.name} should not be an HRIS tool" |
9 | 59 |
|
10 | | -# TODO: Add examples |
11 | | -def get_available_tools(): |
12 | | - print("Getting available tools") |
| 60 | + # Complex filtering with positive and negative patterns |
| 61 | + list_tools = toolset.get_tools( |
| 62 | + [ |
| 63 | + "*list*", # Include list operations |
| 64 | + "*search*", # Include search operations |
| 65 | + "!*delete*", # Exclude delete operations |
| 66 | + "!*remove*", # Exclude remove operations |
| 67 | + ] |
| 68 | + ) |
| 69 | + assert len(list_tools) > 0, "Expected at least one list/search tool" |
| 70 | + for tool in list_tools: |
| 71 | + # Should match positive patterns |
| 72 | + assert any(op in tool.name.lower() for op in ["list", "search"]), ( |
| 73 | + f"Tool {tool.name} doesn't contain 'list' or 'search'" |
| 74 | + ) |
| 75 | + # Should not match negative patterns |
| 76 | + assert not any(op in tool.name.lower() for op in ["delete", "remove"]), ( |
| 77 | + f"Tool {tool.name} contains excluded operation" |
| 78 | + ) |
13 | 79 |
|
14 | 80 |
|
15 | 81 | if __name__ == "__main__": |
16 | | - print(get_available_tools()) |
| 82 | + get_available_tools() |
0 commit comments