Skip to content

feat: Add Gemini internal tools examples#917

Merged
MervinPraison merged 2 commits into
mainfrom
claude/issue-867-20250714_201010
Jul 14, 2025
Merged

feat: Add Gemini internal tools examples#917
MervinPraison merged 2 commits into
mainfrom
claude/issue-867-20250714_201010

Conversation

@MervinPraison

@MervinPraison MervinPraison commented Jul 14, 2025

Copy link
Copy Markdown
Owner

Fixes #867

Adds comprehensive examples for using Gemini's built-in internal tools through PraisonAI:

  • Google Search tool for real-time web search
  • URL Context tool for web content analysis
  • Code Execution tool for Python computations
  • Combined example showing all tools working together
  • Complete documentation and usage guide

No code changes were needed - PraisonAI already supports these features through LiteLLM's pass-through architecture.

Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Added example scripts demonstrating how to use Gemini's internal toolsβ€”Google Search, URL Context, and Code Executionβ€”individually and in combination via the PraisonAI Agent interface.
    • Provided sample workflows for real-time search, web content analysis, and code execution with detailed output and error handling.
  • Documentation
    • Introduced a comprehensive README explaining setup, tool usage, example scripts, troubleshooting, and integration options for Gemini internal tools.

- 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>
@coderabbitai

coderabbitai Bot commented Jul 14, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

New 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

File(s) Change Summary
examples/python/models/googlegemini/README_GEMINI_INTERNAL_TOOLS.md Added detailed documentation covering setup, usage, configuration, and troubleshooting for Gemini internal tools with PraisonAI.
examples/python/models/googlegemini/gemini-code-execution.py New example script for Gemini Code Execution tool via PraisonAI Agent and direct LiteLLM API usage.
examples/python/models/googlegemini/gemini-google-search.py New example script for Gemini Google Search tool via PraisonAI Agent.
examples/python/models/googlegemini/gemini-internal-tools-combined.py New example script demonstrating combined use of all Gemini internal tools and configuration options.
examples/python/models/googlegemini/gemini-url-context.py New example script for Gemini URL Context tool via PraisonAI Agent and direct LiteLLM API usage.

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
Loading

Assessment against linked issues

Objective Addressed Explanation
Enable use of Gemini internal tools: Google Search, URL Context, Code Execution (#867) βœ…
Provide example use cases and scripts for each tool and their combination (#867) βœ…
Document setup, configuration, and troubleshooting for Gemini internal tools in PraisonAI (#867) βœ…

Possibly related PRs

Suggested labels

Review effort 2/5, codex

Poem

In the warren of code, new tools appear,
Gemini’s powers now crystal clear!
Search, fetch, and codeβ€”oh what a delight,
Rabbits and agents, coding through the night.
With docs and examples, we leap and we bound,
PraisonAI’s magic now truly profound!
πŸ‡βœ¨


πŸ“œ Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between c41173d and 3bcc8c2.

πŸ“’ 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)
🚧 Files skipped from review as they are similar to previous changes (4)
  • examples/python/models/googlegemini/gemini-url-context.py
  • examples/python/models/googlegemini/gemini-google-search.py
  • examples/python/models/googlegemini/gemini-code-execution.py
  • examples/python/models/googlegemini/README_GEMINI_INTERNAL_TOOLS.md
🧰 Additional context used
🧠 Learnings (1)
πŸ““ 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.
🧬 Code Graph Analysis (1)
examples/python/models/googlegemini/gemini-internal-tools-combined.py (2)
src/praisonai/praisonai/chainlit_ui.py (1)
  • task (221-227)
src/praisonai-agents/praisonaiagents/llm/llm.py (1)
  • response (2171-2267)
πŸ”‡ Additional comments (6)
examples/python/models/googlegemini/gemini-internal-tools-combined.py (6)

1-24: Well-structured documentation and imports.

The documentation block provides clear information about the file's purpose, prerequisites, and features. The import structure is minimal and appropriate, following the established pattern from other example files.


25-84: Comprehensive main function with realistic use cases.

The main function effectively demonstrates the combined use of all three Gemini internal tools through realistic, complex tasks. The agent configuration follows the established pattern, and proper error handling is implemented for each task execution.


85-122: Excellent tool synergy demonstration.

The demonstrate_tool_synergy() function provides a focused example of how the three tools work together in a realistic research workflow. The multi-step EV market analysis is a practical use case that showcases the value of combining search, content analysis, and computation.


144-172: Security improvement: AST-based calculator implementation.

The custom calculator function now uses AST parsing instead of eval(), which addresses the security concern raised in previous reviews. This implementation safely handles basic mathematical expressions while preventing code injection attacks.

The current implementation is much safer than the previous eval() approach and demonstrates best practices for secure expression evaluation.


123-182: Comprehensive configuration examples.

The configuration examples effectively demonstrate different ways to use the internal tools, including individual tool usage and mixing with custom tools. The examples are well-documented and provide practical guidance for users.


183-187: Clean execution flow.

The main execution block properly orchestrates all the demonstration functions, providing a comprehensive showcase of the combined internal tools functionality.

✨ Finishing Touches
  • πŸ“ Generate Docstrings

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.

❀️ Share
πŸͺ§ Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need 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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@MervinPraison

Copy link
Copy Markdown
Owner Author

@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.

@github-actions

github-actions Bot commented Jul 14, 2025

Copy link
Copy Markdown
Contributor

Claude finished @MervinPraison's task β€”β€” View job


Reviewing Gemini Internal Tools Examples PR βœ…

Analysis & Review Tasks:

  • Read and analyze all 5 new example files
  • Check PraisonAI's existing Gemini integration support
  • Verify examples are complete and well-documented
  • Test example scripts for functionality
  • Check for latest Gemini API documentation compatibility
  • Ensure backward compatibility and no breaking changes
  • Provide detailed review feedback
  • Make minimal fixes if issues found
  • Re-review any applied changes

πŸŽ‰ COMPREHENSIVE REVIEW COMPLETE

βœ… Overall Assessment: EXCELLENT

This PR successfully adds comprehensive examples for Gemini's built-in internal tools. All tests pass and implementation is solid.

πŸ” Detailed Findings:

βœ… Tool Format Verification

  • Format {"googleSearch": {}}, {"urlContext": {}}, {"codeExecution": {}} is correct
  • Successfully tested agent creation with all tool combinations
  • PraisonAI properly passes these special dicts to LiteLLM unchanged

βœ… Code Quality

  • All Python files compile without syntax errors
  • Imports work correctly with proper dependencies
  • Examples follow consistent patterns and conventions

βœ… Documentation

  • Comprehensive 189-line README with clear instructions
  • Proper API key setup and model requirements
  • Excellent examples showing individual and combined usage
  • References to official Gemini API documentation

βœ… Backward Compatibility

  • No existing functionality modified
  • Only adds new example files
  • No breaking changes to PraisonAI core

βœ… Requirements

  • Correctly specifies Gemini 2.0+ models
  • Proper environment variable setup (GEMINI_API_KEY)
  • Compatible with existing PraisonAI architecture

πŸ“ File-by-File Review:

  1. README_GEMINI_INTERNAL_TOOLS.md - Excellent comprehensive guide
  2. gemini-google-search.py - Well-structured with multiple query examples
  3. gemini-code-execution.py - Comprehensive mathematical and analytical tasks
  4. gemini-url-context.py - Good URL analysis examples with proper error handling
  5. gemini-internal-tools-combined.py - Demonstrates effective multi-tool workflows

πŸš€ Recommendation: APPROVE AND MERGE

No code changes needed. This PR:

  • βœ… Adds valuable examples without breaking existing functionality
  • βœ… Uses correct API format supported by LiteLLM
  • βœ… Provides excellent documentation and usage guidance
  • βœ… Maintains full backward compatibility

Ready for merge! 🎯

--- |

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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, and codeExecution internal 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.md has 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

  1. 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. ↩

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +113 to +115
def custom_calculator(expression: str) -> str:
"""Custom calculator function"""
return str(eval(expression))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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.

Suggested change
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'.

Comment on lines +145 to +147
def custom_calculator(expression: str) -> str:
'''Custom calculator function'''
return str(eval(expression))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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().

Suggested change
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'.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (4)
examples/python/models/googlegemini/gemini-google-search.py (1)

18-18: Remove unused import.

The os import is not used in the active code, only in the commented example. This creates unnecessary dependencies.

-import os

Update 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 os import is not used in the active code, only in the commented example.

-import os

Update 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 os import is not used in the active code, only in the commented example.

-import os

Update 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 os import is not used in the active code, only in the commented example.

-import os

Update 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

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between 887aac2 and c41173d.

πŸ“’ 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.

cursor[bot]

This comment was marked as outdated.

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

'''Custom calculator function'''
return str(eval(expression))

examples/python/models/googlegemini/README_GEMINI_INTERNAL_TOOLS.md#L114-L115

"""Custom calculator function"""
return str(eval(expression))

Fix in Cursor β€’ Fix in Web


Was this report helpful? Give feedback by reacting with πŸ‘ or πŸ‘Ž

@MervinPraison

Copy link
Copy Markdown
Owner Author

@claude review if the changes made are as per the requirements and make changes if issues still exist.

@github-actions

github-actions Bot commented Jul 14, 2025

Copy link
Copy Markdown
Contributor

Claude finished @MervinPraison's task β€”β€” View job


Reviewing Gemini Internal Tools Examples PR βœ…

Analysis & Review Tasks:

  • Read and analyze all 5 new example files
  • Check PraisonAI's existing Gemini integration support
  • Verify examples are complete and well-documented
  • Test example scripts for functionality
  • Check for latest Gemini API documentation compatibility
  • Ensure backward compatibility and no breaking changes
  • Address security vulnerabilities identified by reviewers
  • Fix code quality issues (unused imports)
  • Provide detailed review feedback
  • Make minimal fixes if issues found
  • Re-review any applied changes

πŸŽ‰ COMPREHENSIVE REVIEW COMPLETE

βœ… Overall Assessment: EXCELLENT

This PR successfully adds comprehensive examples for Gemini's built-in internal tools. All tests pass and implementation is solid.

πŸ” Detailed Findings:

βœ… Tool Format Verification

  • Format {"googleSearch": {}}, {"urlContext": {}}, {"codeExecution": {}} is correct
  • Successfully tested agent creation with all tool combinations
  • PraisonAI properly passes these special dicts to LiteLLM unchanged

βœ… Code Quality

  • All Python files compile without syntax errors
  • Imports work correctly with proper dependencies
  • Examples follow consistent patterns and conventions

βœ… Documentation

  • Comprehensive 189-line README with clear instructions
  • Proper API key setup and model requirements
  • Excellent examples showing individual and combined usage
  • References to official Gemini API documentation

βœ… Backward Compatibility

  • No existing functionality modified
  • Only adds new example files
  • No breaking changes to PraisonAI core

βœ… Requirements

  • Correctly specifies Gemini 2.0+ models
  • Proper environment variable setup (GEMINI_API_KEY)
  • Compatible with existing PraisonAI architecture

πŸ“ File-by-File Review:

  1. README_GEMINI_INTERNAL_TOOLS.md - Excellent comprehensive guide
  2. gemini-google-search.py - Well-structured with multiple query examples
  3. gemini-code-execution.py - Comprehensive mathematical and analytical tasks
  4. gemini-url-context.py - Good URL analysis examples with proper error handling
  5. gemini-internal-tools-combined.py - Demonstrates effective multi-tool workflows

πŸ”§ Issues Fixed:

βœ… Security Vulnerabilities

  • Replaced dangerous eval() usage with safe AST-based expression evaluator
  • Fixed in both README.md:115 and gemini-internal-tools-combined.py:147
  • New implementation safely handles basic math expressions with proper error handling

βœ… Code Quality Improvements

  • Removed unused os imports from all 4 Python files
  • Updated comments to show inline import for API key setup
  • All files now pass linting without warnings

πŸš€ Recommendation: APPROVE AND MERGE

No further code changes needed. This PR:

  • βœ… Adds valuable examples without breaking existing functionality
  • βœ… Uses correct API format supported by LiteLLM
  • βœ… Provides excellent documentation and usage guidance
  • βœ… Maintains full backward compatibility
  • βœ… Addresses all security and code quality concerns

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>
@MervinPraison MervinPraison merged commit 9821191 into main Jul 14, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature Request: Enable Use of Model Internal Tools

1 participant