Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(tools): overhaul Python REPL component with modern tool mode #5463

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

Vigtu
Copy link
Contributor

@Vigtu Vigtu commented Dec 26, 2024

BREAKING CHANGE: Complete redesign of PythonREPL component architecture

  • Replace legacy tool mode with modern tool_mode=true implementation
  • Add automatic import detection for both global and from-imports
  • Remove manual global_imports field in favor of automatic detection
  • Implement CodeInput type support with FieldTypes.CODE
  • Update schema to handle new parameters for agent compatibility
  • Improve error handling and logging for import failures

The component now automatically handles imports without manual configuration, supports modern tool mode, and provides better integration with the agent system through updated schema definitions.

Python REPL Overhaul.json
image
image

code used on the example:

import random
from datetime import datetime, timedelta
from typing import List, Dict

def generate_dates(quantity: int) -> List[Dict[str, str]]:
    dates = []
    base_date = datetime.now()
    
    for i in range(quantity):
        # Add random days to base date
        days = random.randint(1, 365)
        new_date = base_date + timedelta(days=days)
        
        dates.append({
            "date": new_date.strftime("%d/%m/%Y"),
            "weekday": new_date.strftime("%A")
        })
    
    return dates

# Usage example
generated_dates = generate_dates(3)
for date in generated_dates:
    print(f"Date: {date['date']}, Day: {date['weekday']}")

Or just run the code without the Agent:

image

CodeInput terminal:
image

the output:
image

BREAKING CHANGE: Complete redesign of PythonREPL component architecture

- Replace legacy tool mode with modern tool_mode=true implementation
- Add automatic import detection for both global and from-imports
- Remove manual global_imports field in favor of automatic detection
- Implement CodeInput type support with FieldTypes.CODE
- Update schema to handle new parameters for agent compatibility
- Improve error handling and logging for import failures

The component now automatically handles imports without manual configuration,
supports modern tool mode, and provides better integration with the agent
system through updated schema definitions.
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. python Pull requests that update Python code labels Dec 26, 2024
@github-actions github-actions bot added the refactor Maintenance tasks and housekeeping label Dec 26, 2024
@Vigtu
Copy link
Contributor Author

Vigtu commented Dec 26, 2024

Copy link

codspeed-hq bot commented Dec 26, 2024

CodSpeed Performance Report

Merging #5463 will not alter performance

Comparing Vigtu:python-REPL-Overhaul (01a214a) with main (16ff8eb)

Summary

✅ 15 untouched benchmarks

Copy link
Contributor

@ogabrielluiz ogabrielluiz left a comment

Choose a reason for hiding this comment

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

Looking good, @Vigtu !

Thank you

icon = "Python"
name = "PythonREPL"
Copy link
Contributor

Choose a reason for hiding this comment

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

Name is not required

Suggested change
name = "PythonREPL"

Comment on lines 36 to 41
StrInput(
name="global_imports",
display_name="Global Imports",
info="A comma-separated list of modules to import globally, e.g. 'math,numpy'.",
value="math",
),
Copy link
Contributor

Choose a reason for hiding this comment

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

We had imports for security reasons. We need a way to limit what the LLM can do.

@github-actions github-actions bot added refactor Maintenance tasks and housekeeping and removed refactor Maintenance tasks and housekeeping labels Jan 3, 2025
Vigtu added 2 commits January 3, 2025 13:57
- Add explicit global imports input for security control
- Set both global_imports and python_code as required fields
- Remove AST-based import analysis in favor of explicit imports
@github-actions github-actions bot added refactor Maintenance tasks and housekeeping and removed refactor Maintenance tasks and housekeeping labels Jan 3, 2025
@github-actions github-actions bot added refactor Maintenance tasks and housekeeping and removed refactor Maintenance tasks and housekeeping labels Jan 3, 2025
Vigtu added 2 commits January 3, 2025 15:09
Removed overly broad exception handling to comply with linting rules.
@github-actions github-actions bot added refactor Maintenance tasks and housekeeping and removed refactor Maintenance tasks and housekeeping labels Jan 3, 2025
@github-actions github-actions bot added refactor Maintenance tasks and housekeeping and removed refactor Maintenance tasks and housekeeping labels Jan 3, 2025
@Vigtu Vigtu requested a review from ogabrielluiz January 4, 2025 06:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
python Pull requests that update Python code refactor Maintenance tasks and housekeeping size:L This PR changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants