feat: Add Gemini internal tools examples#917
Conversation
- Add Google Search tool example (gemini-google-search.py) - Add URL Context tool example (gemini-url-context.py) - Add Code Execution tool example (gemini-code-execution.py) - Add combined tools example (gemini-internal-tools-combined.py) - Add comprehensive documentation (README_GEMINI_INTERNAL_TOOLS.md) These examples demonstrate how to use Gemini''s built-in internal tools through PraisonAI''s existing tool system without any code changes. Co-authored-by: Mervin Praison <MervinPraison@users.noreply.github.com>
WalkthroughNew example scripts and a comprehensive README were added to demonstrate and document the use of Gemini model's internal toolsβGoogle Search, URL Context, and Code Executionβvia the PraisonAI Agent interface. Each script showcases a specific tool or their combination, with setup instructions, usage examples, and error handling. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant ExampleScript
participant PraisonAI_Agent
participant LiteLLM
participant Gemini_Model
User->>ExampleScript: Run example (e.g., gemini-code-execution.py)
ExampleScript->>PraisonAI_Agent: Create agent with internal tools enabled
PraisonAI_Agent->>LiteLLM: Pass tool configuration and prompt
LiteLLM->>Gemini_Model: Forward request with tool config
Gemini_Model-->>LiteLLM: Execute tool(s), return response
LiteLLM-->>PraisonAI_Agent: Return model response
PraisonAI_Agent-->>ExampleScript: Return final result
ExampleScript-->>User: Print output
Assessment against linked issues
Possibly related PRs
Suggested labels
Poem
π Recent review detailsConfiguration used: CodeRabbit UI π Files selected for processing (5)
π§ Files skipped from review as they are similar to previous changes (4)
π§° Additional context usedπ§ Learnings (1)π Common learnings𧬠Code Graph Analysis (1)examples/python/models/googlegemini/gemini-internal-tools-combined.py (2)
π Additional comments (6)
β¨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. πͺ§ TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
|
@claude review this pull request and do a detailed analysis and fix this if the existing code doesn't have the solution implemented. Making sure it has backward compatibility, no existing features removed. After making those changes, again review the applied changes. Use @web to search if you dont know any information or to find the latest documentation or to find the latest version. Run the code if you think you need to run it to test it. Minimal code change to start with if required any changes. |
|
Claude finished @MervinPraison's task ββ View job Reviewing Gemini Internal Tools Examples PR βAnalysis & Review Tasks:
π COMPREHENSIVE REVIEW COMPLETEβ Overall Assessment: EXCELLENTThis PR successfully adds comprehensive examples for Gemini's built-in internal tools. All tests pass and implementation is solid. π Detailed Findings:β Tool Format Verification
β Code Quality
β Documentation
β Backward Compatibility
β Requirements
π File-by-File Review:
π Recommendation: APPROVE AND MERGENo code changes needed. This PR:
Ready for merge! π― --- | |
There was a problem hiding this comment.
Summary of Changes
Hello @MervinPraison, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request significantly expands the example suite for PraisonAI by providing clear, runnable demonstrations of how to utilize Google Gemini's powerful built-in internal tools. The additions include individual examples for Google Search, URL Context, and Code Execution, along with a combined example, all supported by comprehensive documentation. Notably, these examples leverage PraisonAI's existing LiteLLM integration, meaning no core code changes were required within the PraisonAI framework itself.
Highlights
- New Example Category: I've added a new directory under
examples/python/models/googlegemini/specifically for demonstrating Gemini's internal tools. - Gemini Internal Tool Examples: This PR introduces dedicated Python examples for using Gemini's
googleSearch,urlContext, andcodeExecutioninternal tools individually within PraisonAI agents. - Combined Tool Usage Example: A combined example (
gemini-internal-tools-combined.py) is included to showcase how all three Gemini internal tools can be leveraged together for more complex tasks. - Comprehensive Documentation: A detailed
README_GEMINI_INTERNAL_TOOLS.mdhas been added, explaining the purpose of each tool, prerequisites, how PraisonAI integrates with these tools via LiteLLM's pass-through architecture, benefits of using internal tools, and troubleshooting tips.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| Feature | Command | Description |
|---|---|---|
| Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
| Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with π and π on @gemini-code-assist comments to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. β©
There was a problem hiding this comment.
Code Review
This pull request adds comprehensive examples for using Google Gemini's internal tools with PraisonAI. The examples are clear and well-structured. The use of eval() in the custom_calculator example poses a security risk and should be addressed to promote secure coding practices.
| def custom_calculator(expression: str) -> str: | ||
| """Custom calculator function""" | ||
| return str(eval(expression)) |
There was a problem hiding this comment.
The use of eval() in the custom_calculator example poses a significant security risk. If the expression string is influenced by an LLM or any other external input, it could be exploited to execute arbitrary code. It's important to promote secure coding practices in examples.
Please consider replacing eval() with a safer alternative or adding a prominent warning about its use. A safer approach would be to use a dedicated expression parsing library like numexpr.
| def custom_calculator(expression: str) -> str: | |
| """Custom calculator function""" | |
| return str(eval(expression)) | |
| def custom_calculator(expression: str) -> str: | |
| """Custom calculator function. WARNING: Uses eval(), which is a security risk.""" | |
| return str(eval(expression)) # In production, use a safe alternative like 'ast.literal_eval' or 'numexpr'. |
| def custom_calculator(expression: str) -> str: | ||
| '''Custom calculator function''' | ||
| return str(eval(expression)) |
There was a problem hiding this comment.
The custom_calculator example within the show_configuration_options function uses eval(). Although this code is inside a print statement and not executed directly, it serves as an example for users who might copy and paste it. This promotes an insecure practice.
To prevent potential security vulnerabilities in user applications, please add a warning about the use of eval().
| def custom_calculator(expression: str) -> str: | |
| '''Custom calculator function''' | |
| return str(eval(expression)) | |
| def custom_calculator(expression: str) -> str: | |
| '''Custom calculator function. WARNING: eval() is a security risk.''' | |
| return str(eval(expression)) # In production, use a safe alternative like 'ast.literal_eval' or 'numexpr'. |
There was a problem hiding this comment.
Actionable comments posted: 0
π§Ή Nitpick comments (4)
examples/python/models/googlegemini/gemini-google-search.py (1)
18-18: Remove unused import.The
osimport is not used in the active code, only in the commented example. This creates unnecessary dependencies.-import osUpdate the comment to show the import inline:
-# os.environ["GEMINI_API_KEY"] = "your-api-key-here" +# import os; os.environ["GEMINI_API_KEY"] = "your-api-key-here"examples/python/models/googlegemini/gemini-url-context.py (1)
19-19: Remove unused import.The
osimport is not used in the active code, only in the commented example.-import osUpdate the comment to show the import inline:
-# os.environ["GEMINI_API_KEY"] = "your-api-key-here" +# import os; os.environ["GEMINI_API_KEY"] = "your-api-key-here"examples/python/models/googlegemini/gemini-code-execution.py (1)
19-19: Remove unused import.The
osimport is not used in the active code, only in the commented example.-import osUpdate the comment to show the import inline:
-# os.environ["GEMINI_API_KEY"] = "your-api-key-here" +# import os; os.environ["GEMINI_API_KEY"] = "your-api-key-here"examples/python/models/googlegemini/gemini-internal-tools-combined.py (1)
20-20: Remove unused import.The
osimport is not used in the active code, only in the commented example.-import osUpdate the comment to show the import inline:
-# os.environ["GEMINI_API_KEY"] = "your-api-key-here" +# import os; os.environ["GEMINI_API_KEY"] = "your-api-key-here"
π Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
π Files selected for processing (5)
examples/python/models/googlegemini/README_GEMINI_INTERNAL_TOOLS.md(1 hunks)examples/python/models/googlegemini/gemini-code-execution.py(1 hunks)examples/python/models/googlegemini/gemini-google-search.py(1 hunks)examples/python/models/googlegemini/gemini-internal-tools-combined.py(1 hunks)examples/python/models/googlegemini/gemini-url-context.py(1 hunks)
π§° Additional context used
π§ Learnings (2)
π Common learnings
Learnt from: CR
PR: MervinPraison/PraisonAI#0
File: src/praisonai-ts/.windsurfrules:0-0
Timestamp: 2025-06-30T10:06:44.129Z
Learning: Applies to src/praisonai-ts/src/tools/test.ts : The 'src/tools/test.ts' file should serve as a script for running internal tests or examples for each tool.
Learnt from: CR
PR: MervinPraison/PraisonAI#0
File: src/praisonai-agents/CLAUDE.md:0-0
Timestamp: 2025-06-30T10:06:17.673Z
Learning: Use the `Agent` class from `praisonaiagents/agent/` for core agent implementations, supporting LLM integration, tool calling, and self-reflection.
Learnt from: CR
PR: MervinPraison/PraisonAI#0
File: src/praisonai-ts/.cursorrules:0-0
Timestamp: 2025-06-30T10:05:51.843Z
Learning: Applies to src/praisonai-ts/src/tools/test.ts : The 'src/tools/test.ts' file should provide a script for running each tool's internal test or example.
examples/python/models/googlegemini/README_GEMINI_INTERNAL_TOOLS.md (4)
Learnt from: CR
PR: MervinPraison/PraisonAI#0
File: src/praisonai-ts/.windsurfrules:0-0
Timestamp: 2025-06-30T10:06:44.129Z
Learning: Applies to src/praisonai-ts/src/tools/README.md : The 'src/tools/README.md' file should provide documentation for tool developers on how to write tools in JS/TS.
Learnt from: CR
PR: MervinPraison/PraisonAI#0
File: src/praisonai-ts/.cursorrules:0-0
Timestamp: 2025-06-30T10:05:51.843Z
Learning: Applies to src/praisonai-ts/src/tools/README.md : The 'src/tools/README.md' file should provide documentation for tool developers on how to write tools in JS/TS.
Learnt from: CR
PR: MervinPraison/PraisonAI#0
File: src/praisonai-ts/.windsurfrules:0-0
Timestamp: 2025-06-30T10:06:44.129Z
Learning: Applies to src/praisonai-ts/src/tools/test.ts : The 'src/tools/test.ts' file should serve as a script for running internal tests or examples for each tool.
Learnt from: CR
PR: MervinPraison/PraisonAI#0
File: src/praisonai-ts/.cursorrules:0-0
Timestamp: 2025-06-30T10:05:51.843Z
Learning: Applies to src/praisonai-ts/src/tools/test.ts : The 'src/tools/test.ts' file should provide a script for running each tool's internal test or example.
πͺ Ruff (0.12.2)
examples/python/models/googlegemini/gemini-google-search.py
18-18: os imported but unused
Remove unused import: os
(F401)
examples/python/models/googlegemini/gemini-code-execution.py
19-19: os imported but unused
Remove unused import: os
(F401)
examples/python/models/googlegemini/gemini-internal-tools-combined.py
20-20: os imported but unused
Remove unused import: os
(F401)
examples/python/models/googlegemini/gemini-url-context.py
19-19: os imported but unused
Remove unused import: os
(F401)
π Additional comments (13)
examples/python/models/googlegemini/gemini-google-search.py (2)
24-47: Well-structured agent configuration and example queries.The agent setup is clean and the example queries demonstrate real-world use cases effectively. The tool configuration follows the documented pattern correctly.
54-61: Good error handling implementation.The try-catch block properly handles exceptions and provides meaningful error messages. The formatting creates clear separation between queries.
examples/python/models/googlegemini/gemini-url-context.py (2)
40-58: Excellent variety of URL examples for testing.The URL examples cover different content types (documentation, GitHub repo, tutorial, research paper) which provides comprehensive testing scenarios for the URL Context tool.
83-112: Valuable educational demonstration of direct LiteLLM usage.The demonstrate_direct_usage() function provides excellent educational value by showing how the tool works at the LiteLLM level, including metadata access. This helps users understand the underlying implementation.
examples/python/models/googlegemini/README_GEMINI_INTERNAL_TOOLS.md (4)
1-21: Comprehensive and well-structured documentation introduction.The documentation provides a clear overview of all three internal tools with proper categorization and use cases. The structure is logical and easy to follow.
44-74: Excellent code examples with proper syntax.The individual tool examples are well-formatted with correct syntax and realistic use cases. The code snippets are concise yet comprehensive.
112-124: Valuable guidance on mixing internal and external tools.The section on combining internal tools with custom external tools provides practical insights for advanced usage scenarios. The example clearly demonstrates the syntax differences.
162-178: Comprehensive troubleshooting section.The troubleshooting section covers common issues users might encounter and provides actionable solutions. The debug mode guidance is particularly useful.
examples/python/models/googlegemini/gemini-code-execution.py (2)
40-55: Excellent progression of computational complexity in example tasks.The tasks demonstrate a good range of computational complexity, from basic compound interest calculations to advanced topics like numerical integration. This provides comprehensive coverage of the Code Execution tool's capabilities.
72-96: Educational direct usage example with clear context.The demonstrate_direct_usage() function provides valuable insight into the underlying LiteLLM implementation, helping users understand how the tool works at a lower level.
examples/python/models/googlegemini/gemini-internal-tools-combined.py (3)
49-68: Excellent complex tasks demonstrating tool synergy.The complex tasks effectively show how multiple internal tools can work together to solve real-world problems. Each task requires different combinations of search, content analysis, and computation.
86-123: Valuable demonstration of multi-step research workflow.The tool synergy example provides an excellent real-world scenario showing how the tools complement each other in a market research workflow. This demonstrates the practical value of the combined approach.
124-157: Comprehensive configuration examples for different use cases.The configuration examples section provides valuable guidance for users on how to configure tools individually or in combination, including mixing with custom tools. This is excellent documentation through code.
There was a problem hiding this comment.
Bug: Code Injection Risk in Example Function
The custom_calculator example function uses eval(expression), creating a code injection vulnerability that allows arbitrary code execution. This dangerous example could be copied by users, introducing significant security risks. Safer alternatives like ast.literal_eval() or a proper expression parser should be considered.
examples/python/models/googlegemini/gemini-internal-tools-combined.py#L146-L147
examples/python/models/googlegemini/README_GEMINI_INTERNAL_TOOLS.md#L114-L115
PraisonAI/examples/python/models/googlegemini/README_GEMINI_INTERNAL_TOOLS.md
Lines 114 to 115 in c41173d
Was this report helpful? Give feedback by reacting with π or π
|
@claude review if the changes made are as per the requirements and make changes if issues still exist. |
|
Claude finished @MervinPraison's task ββ View job Reviewing Gemini Internal Tools Examples PR βAnalysis & Review Tasks:
π COMPREHENSIVE REVIEW COMPLETEβ Overall Assessment: EXCELLENTThis PR successfully adds comprehensive examples for Gemini's built-in internal tools. All tests pass and implementation is solid. π Detailed Findings:β Tool Format Verification
β Code Quality
β Documentation
β Backward Compatibility
β Requirements
π File-by-File Review:
π§ Issues Fixed:β Security Vulnerabilities
β Code Quality Improvements
π Recommendation: APPROVE AND MERGENo further code changes needed. This PR:
Ready for merge! π― |
β¦ve unused imports - Replace insecure eval() usage with ast-based safe expression evaluator in README and combined examples - Remove unused os imports from all Python example files - Update comments to show import os inline for API key setup - Addresses security vulnerabilities identified in code review Co-authored-by: Mervin Praison <MervinPraison@users.noreply.github.com>
Fixes #867
Adds comprehensive examples for using Gemini's built-in internal tools through PraisonAI:
No code changes were needed - PraisonAI already supports these features through LiteLLM's pass-through architecture.
Generated with Claude Code
Summary by CodeRabbit