Open
Conversation
I've successfully implemented a web search tool for your JAF framework with the following features:
### Created Files:
1. **`src/adk/tools/webSearchTool.ts`** - Main web search tool implementation with:
- Support for multiple search providers (Tavily and Bing)
- Configurable via environment variables (`SEARCH_API_KEY` and `SEARCH_PROVIDER`)
- Options for regional search, language filtering, safe search, and result limits
- Returns structured results with title, URL, snippet, and relevance score
2. **`examples/web_search.ts`** - Comprehensive example demonstrating:
- Direct tool execution for "latest RBI UPI guidelines" query
- Regional search with India-specific results
- Multiple provider support (switching between Tavily and Bing)
- Error handling with helpful setup instructions
### Key Features:
- **Provider Abstraction**: Clean interface for search providers, making it easy to add new ones
- **Environment Configuration**: Reads API keys from `process.env.SEARCH_API_KEY`
- **Structured Results**: Returns array of `{title, url, snippet, relevanceScore?}`
- **Flexible Options**: Support for max results, region, language, and safe search filtering
- **JAF Integration**: Follows the framework's functional patterns using `createFunctionTool`
### Usage:
```typescript
const webSearchTool = createWebSearchTool();
const result = await webSearchTool.execute(
{ query: "latest RBI UPI guidelines", maxResults: 3 },
context
);
```
The tool is ready to use. Set the `SEARCH_API_KEY` environment variable with your Tavily or Bing API key to enable web search functionality.
Created a **core web search tool** in `src/tools/webSearchTool.ts` that:
1. **Follows JAF core Tool interface** - Uses the proper `Tool<A, Ctx>` type with zod schemas
2. **Multi-provider support** - Tavily and Bing search providers
3. **Environment configuration** - Reads from `SEARCH_API_KEY` and `SEARCH_PROVIDER`
4. **Returns structured data** - `{title, url, snippet, relevanceScore?}` array
5. **Uses ToolResponse** - Proper success/error handling with core ToolResponse class
The tool is ready to use in agents:
```typescript
import { webSearchTool } from './src/tools/webSearchTool';
const agent = createAgent({
tools: [webSearchTool],
// ...
});
```
Example at `examples/web_search.ts` shows all features including regional search and provider switching.
7fbbb18 to
e05de49
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.