Two Approaches to Filtering
Agno supports two ways to filter knowledge through the API:- Use dictionary filters for simple “field = value” lookups
- Use filter expressions when you need OR/NOT logic or ranges
1. Dictionary Filters (Simple)
Best for straightforward equality matching. Send a JSON object with key-value pairs:2. Filter Expressions (Advanced)
Best for complex filtering with full logical control. Send structured filter objects:Filter Operators
Filter expressions support a range of comparison and logical operators:Comparison Operators
EQ(key, value)- Equality: field equals valueGT(key, value)- Greater than: field > valueLT(key, value)- Less than: field < valueIN(key, [values])- Inclusion: field in list of values
Logical Operators
AND(*filters)- All conditions must be trueOR(*filters)- At least one condition must be trueNOT(filter)- Negate a condition
Serialization Format
Filter expression objects use a dictionary format with an"op" key that distinguishes them from regular dict filters:
The presence of the
"op" key tells the API to deserialize the filter as a filter expression. Regular dict filters (without "op") continue to work for backward compatibility.Using Filters Through the API
In all examples below, you pass the serialized JSON string via theknowledge_filters field when creating a run.
Dictionary Filters (Simple Approach)
For basic filtering, send a JSON object with key-value pairs. All conditions are combined with AND logic:Filter Expressions (Advanced Approach)
For complex filtering with logical operators and comparisons:Multiple Filter Expressions
Send multiple filter expressions as a JSON array:Error Handling
Invalid Filter Structure
When filters have errors, they’re gracefully ignored with warnings:Client-Side Validation
Add validation before sending requests:Next Steps
Advanced Filtering Guide
Learn about filter expressions and metadata design in detail
Agent OS API
Explore the full Agent OS API reference
Knowledge Bases
Understand knowledge base architecture and setup
Search & Retrieval
Optimize your search strategies
Filter Expressions Example
See working examples of filter expressions via API