### Install @elizaos/plugin-web-search Source: https://github.com/elizaos-plugins/plugin-web-search/blob/main/README.md Installs the web search plugin using pnpm. ```bash pnpm install @elizaos/plugin-web-search ``` -------------------------------- ### Run Development Mode Source: https://github.com/elizaos-plugins/plugin-web-search/blob/main/README.md Starts the project in development mode using pnpm. ```bash pnpm run dev ``` -------------------------------- ### Token Management Example Source: https://github.com/elizaos-plugins/plugin-web-search/blob/main/README.md Illustrates token limit management with a predefined constant. ```typescript // The plugin automatically handles token limits const DEFAULT_MAX_WEB_SEARCH_TOKENS = 4000; // Example of token-limited response const response = MaxTokens(searchResult, DEFAULT_MAX_WEB_SEARCH_TOKENS); ``` -------------------------------- ### Example Usage: Basic Search Source: https://github.com/elizaos-plugins/plugin-web-search/blob/main/README.md Demonstrates a basic web search query and processing the results. ```typescript // Basic search const searchQuery = "Latest developments in quantum computing"; const results = await generateWebSearch(searchQuery, runtime); // With formatted response if (results && results.results.length) { const formattedResponse = `${results.answer}\n\nFor more details, check out:\n${results.results .map( (result, index) => `${index + 1}. [${result.title}](${result.url})` ) .join("\n")}`; } ``` -------------------------------- ### Build Project Source: https://github.com/elizaos-plugins/plugin-web-search/blob/main/README.md Builds the project using pnpm. ```bash pnpm run build ``` -------------------------------- ### Test Project Source: https://github.com/elizaos-plugins/plugin-web-search/blob/main/README.md Runs tests for the project using pnpm. ```bash pnpm run test ``` -------------------------------- ### Contributing Guidelines Source: https://github.com/elizaos-plugins/plugin-web-search/blob/main/README.md Information on how to contribute to the plugin's development. ```markdown ## Contributing Contributions are welcome! Please see the [CONTRIBUTING.md](CONTRIBUTING.md) file for more information. ``` -------------------------------- ### Plugin Methods Source: https://github.com/elizaos-plugins/plugin-web-search/blob/main/README.md Lists the primary methods provided by the web search plugin. ```javascript - `webSearch.handler`: Main method for executing searches - `generateWebSearch`: Core search generation function - `MaxTokens`: Token limit management function - `getTotalTokensFromString`: Token counting utility ``` -------------------------------- ### Security Best Practices Source: https://github.com/elizaos-plugins/plugin-web-search/blob/main/README.md Outlines security recommendations for using the web search plugin. ```markdown ### Security Best Practices - Store API keys securely using environment variables - Validate all search inputs - Implement proper error handling - Keep dependencies updated - Monitor API usage and rate limits - Use HTTPS for API communication ``` -------------------------------- ### Troubleshooting: Search Rate Limiting Source: https://github.com/elizaos-plugins/plugin-web-search/blob/main/README.md Explains how to handle search rate limiting issues. ```markdown ### Issue: Search Rate Limiting - **Cause**: Too many requests in short time - **Solution**: Implement proper request throttling ``` -------------------------------- ### Configuration Options: Token Management Source: https://github.com/elizaos-plugins/plugin-web-search/blob/main/README.md Defines constants related to token management for web searches. ```typescript const DEFAULT_MODEL_ENCODING = "gpt-3.5-turbo"; const DEFAULT_MAX_WEB_SEARCH_TOKENS = 4000; ``` -------------------------------- ### Custom Web Search Service Usage Source: https://github.com/elizaos-plugins/plugin-web-search/blob/main/README.md Demonstrates direct usage of the WebSearchService in a social media client. ```typescript // Example usage in a social media client const webSearchService = new WebSearchService(); await webSearchService.initialize(runtime); const latestNews = await webSearchService.search( "latest news on AI Agents", // searchOptions ); const state = await this.runtime.composeState( { } // memory, { // additional keys latestNews: latestNews, } ); // Then modify the post template to include the {{latestNews}} and however you need ``` -------------------------------- ### Search Actions Similes Source: https://github.com/elizaos-plugins/plugin-web-search/blob/main/README.md Lists various similes used for web search actions within the plugin. ```markdown ### Search Actions The plugin includes multiple search action similes: - SEARCH_WEB - INTERNET_SEARCH - LOOKUP - QUERY_WEB - FIND_ONLINE - And more... ``` -------------------------------- ### Troubleshooting: API Authentication Failures Source: https://github.com/elizaos-plugins/plugin-web-search/blob/main/README.md Provides solutions for API authentication issues, typically related to the Tavily API key. ```markdown ### Issue: API Authentication Failures - **Cause**: Invalid or missing Tavily API key - **Solution**: Verify TAVILY_API_KEY environment variable ``` -------------------------------- ### Register Web Search Plugin Source: https://github.com/elizaos-plugins/plugin-web-search/blob/main/README.md Imports and registers the webSearchPlugin in Eliza configuration. ```typescript import { webSearchPlugin } from "@elizaos/plugin-web-search"; export default { plugins: [webSearchPlugin], // ... other configuration }; ``` -------------------------------- ### Execute Web Search Query Source: https://github.com/elizaos-plugins/plugin-web-search/blob/main/README.md Executes a web search query using the webSearch.handler function. ```typescript import { webSearch } from "@elizaos/plugin-web-search"; // Execute a search query const result = await webSearch.handler( runtime, { content: { text: "What is the latest news about AI?" }, }, state, {}, callback ); ``` -------------------------------- ### API Reference: Core Interfaces Source: https://github.com/elizaos-plugins/plugin-web-search/blob/main/README.md Defines the core interfaces used by the web search plugin, including Action and SearchResult. ```typescript interface Action { name: "WEB_SEARCH"; similes: string[]; description: string; validate: (runtime: IAgentRuntime, message: Memory) => Promise; handler: ( runtime: IAgentRuntime, message: Memory, state: State, options: any, callback: HandlerCallback ) => Promise; examples: Array>; } interface SearchResult { title: string; url: string; answer?: string; results?: Array<{ title: string; url: string; }>; } ``` -------------------------------- ### Configure TAVILY_API_KEY Source: https://github.com/elizaos-plugins/plugin-web-search/blob/main/README.md Sets the required environment variable for the Tavily API key. ```env TAVILY_API_KEY=your_api_key ``` -------------------------------- ### Troubleshooting: Token Limit Exceeded Source: https://github.com/elizaos-plugins/plugin-web-search/blob/main/README.md Addresses issues where search results exceed the maximum token limit. ```markdown ### Issue: Token Limit Exceeded - **Cause**: Search results exceeding maximum token limit - **Solution**: Results are automatically truncated to fit within limits ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.