Unify Multiple Search APIs with Abstract Class, Return Errors Instead of Raising
· 4 min read
Encountered this issue while building an AI Agent platform for a client: needed to support multiple search providers (Tavily, Serper, Brave, Bing) while ensuring tool call failures don't interrupt the Agent's conversation flow.
TL;DR
- Define
SearchProviderabstract base class +SearchResultdata model for unified interface and output - Each provider inherits the base class, implements
search()method with field mapping - Key design: Return
SearchResultwith error info on failure, never raise exceptions