Guides
Conditionals & Predicates
Show or hide Truffle tools dynamically at runtime using Python predicates
What is a predicate?
Predicates let you control exactly which tools your Agent sees at runtime. Instead of a fixed list, you write any Python function that returns True
or False
, and the SDK will only expose the tool when your logic allows it. This unlocks powerful scenarios:
- Show or hide tools based on internal state (e.g., only after you’ve run a search)
- React to environment variables, config flags, or user roles
- Build arbitrarily complex visibility rules to keep your UI clean and context-aware
This pattern scales to any condition—feature flags, user permissions, external API health checks, or even time-based rules. Combine predicates with your tools to build flexible, self-aware agents that only surface the right capabilities at the right moment.
Scenarios where you may want predicates
Assume a situation where you have a tree of tools but don’t want the model to overload it’s context