AgentsAgentBase

define_tools

View as MarkdownOpen in Claude

Returns the list of SWAIG functions registered on this agent. The default implementation collects all tools added via define_tool(), the @tool decorator, or register_swaig_function().

Override this method in a subclass to dynamically filter, reorder, or inject tools at SWML generation time.

In most cases you do not need to override this method. Use define_tool() or the @tool decorator to register tools instead.

Parameters

None.

Returns

list[SWAIGFunction | dict] — List of SWAIGFunction objects and/or raw dictionaries (for DataMap-based tools).

Example

1from signalwire import AgentBase
2from signalwire.core.function_result import FunctionResult
3
4class FilteredAgent(AgentBase):
5 def __init__(self):
6 super().__init__(name="filtered", route="/filtered")
7 self.set_prompt_text("You are a helpful assistant.")
8 self._disabled_tools = set()
9
10 @AgentBase.tool(description="Check the weather")
11 def check_weather(self, args, raw_data=None):
12 return FunctionResult("It's sunny and 72F.")
13
14 def define_tools(self):
15 """Filter out any disabled tools before SWML generation."""
16 all_tools = super().define_tools()
17 return [
18 t for t in all_tools
19 if getattr(t, 'name', None) not in self._disabled_tools
20 ]
21
22agent = FilteredAgent()
23agent.run()