Skip to content

fix(motion-graphics): correct FileTools import path + constructor (v0.2.25)#28

Merged
MervinPraison merged 1 commit intomainfrom
hotfix/motion-graphics-import-fix-0.2.25
Apr 19, 2026
Merged

fix(motion-graphics): correct FileTools import path + constructor (v0.2.25)#28
MervinPraison merged 1 commit intomainfrom
hotfix/motion-graphics-import-fix-0.2.25

Conversation

@MervinPraison
Copy link
Copy Markdown
Owner

@MervinPraison MervinPraison commented Apr 19, 2026

Hotfix for live-run failures in motion_graphics_team() / create_motion_graphics_agent()

Caught via live run of

from praisonai_tools.video.motion_graphics import motion_graphics_team
team = motion_graphics_team()
team.start("Animate Dijkstra's algorithm on a small weighted graph, 30s.")

Which failed with:

ImportError: praisonaiagents not available. Install with: pip install praisonaiagents

…despite praisonaiagents being installed and importable. Unit tests never caught this because they mock out Agent/AgentTeam/FileTools.

Root causes

  1. Wrong import path for FileTools
    praisonai_tools/video/motion_graphics/agent.py:9 and team.py:9 did:

    from praisonaiagents.tools import FileTools

    FileTools is not exported by the tools package __getattr__ (only lowercase keys like file_tools, read_file, etc. are). The import raises ImportError, which the broad except ImportError: swallows — setting every symbol (Agent, AgentTeam, FileTools, search_web) to None and making the factory raise the misleading top-level ImportError.

  2. FileTools(base_dir=...) crashes
    agent.py:197 did FileTools(base_dir=str(workspace)). The actual class takes no constructor args — methods are bound directly. Even if import had succeeded, the factory would still have raised TypeError: FileTools() takes no arguments.

Fix

- from praisonaiagents.tools import FileTools
+ from praisonaiagents.tools.file_tools import FileTools
- file_tools = FileTools(base_dir=str(workspace))
+ file_tools = FileTools()

Also catch AttributeError alongside ImportError in team.py so lazy-attribute failures fall back cleanly.

Verification (live, not mocked)

$ python -c "
from praisonai_tools.video.motion_graphics import motion_graphics_team
team = motion_graphics_team(research=False, code_exploration=False)
print(f'team OK: {len(team.agents)} agents = {[a.name for a in team.agents]}')"
team OK: 2 agents = ['coordinator', 'animator']

Deterministic HtmlRenderBackend path (Example 01) still renders 1920×1080 MP4 end-to-end in ~5s. All 87/87 unit tests still green.

Version

Bump 0.2.240.2.25 (patch).

Follow-up (not in this PR)

Add one non-mocked smoke test that actually instantiates motion_graphics_team() and create_motion_graphics_agent() against the real praisonaiagents SDK, so future regressions of this class are caught by CI.

Summary by CodeRabbit

  • Chores

    • Version bumped to 0.2.25.
  • Bug Fixes

    • Improved error handling for motion graphics tools to gracefully manage missing or unavailable dependencies.

Post-merge fixes for #27 caught via live end-to-end run of motion_graphics_team:

- agent.py / team.py: import FileTools from praisonaiagents.tools.file_tools
  (not praisonaiagents.tools). FileTools is not exported via the tools
  package __getattr__, so 'from praisonaiagents.tools import FileTools'
  raises ImportError in production and causes motion_graphics_team() and
  create_motion_graphics_agent() to both fail with the generic
  'praisonaiagents not available' ImportError.

- agent.py: drop the base_dir kwarg when instantiating FileTools — the
  class takes no constructor args (methods are bound directly).

- team.py: also catch AttributeError alongside ImportError so lazy
  attribute failures fall back cleanly to None stubs.

- pyproject.toml: bump version 0.2.24 -> 0.2.25

Unit tests continue to pass because they mock out praisonaiagents. The
bug only surfaces in live runs. Follow-up: add one non-mocked smoke test
that actually instantiates motion_graphics_team().
Copilot AI review requested due to automatic review settings April 19, 2026 00:15
@MervinPraison MervinPraison merged commit ddc77bc into main Apr 19, 2026
0 of 3 checks passed
Copy link
Copy Markdown

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

MervinPraison has reached the 50-review limit for trial accounts. To continue receiving code reviews, upgrade your plan.

@MervinPraison MervinPraison deleted the hotfix/motion-graphics-import-fix-0.2.25 branch April 19, 2026 00:15
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 19, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 86a7cb31-ce82-44f5-85cc-2de358ae858a

📥 Commits

Reviewing files that changed from the base of the PR and between 6d0d510 and e7117cf.

📒 Files selected for processing (3)
  • praisonai_tools/video/motion_graphics/agent.py
  • praisonai_tools/video/motion_graphics/team.py
  • pyproject.toml

📝 Walkthrough

Walkthrough

This PR updates FileTools imports and initialization in motion graphics modules, changing the import path from praisonaiagents.tools to praisonaiagents.tools.file_tools and removing workspace-based directory binding. Exception handling is expanded to catch AttributeError alongside ImportError. Version incremented to 0.2.25.

Changes

Cohort / File(s) Summary
Motion Graphics Module Updates
praisonai_tools/video/motion_graphics/agent.py, praisonai_tools/video/motion_graphics/team.py
Updated FileTools imports to use praisonaiagents.tools.file_tools instead of praisonaiagents.tools. Removed base_dir parameter from FileTools initialization in agent.py. Expanded exception handling in team.py from ImportError to (ImportError, AttributeError) and ensured fallback sets all tool variables to None.
Project Metadata
pyproject.toml
Version bump from 0.2.24 to 0.2.25.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • PR#27 — Both PRs modify FileTools imports and instantiation in the same motion graphics agent and team modules with similar refactoring patterns.

Poem

🐰 Imports shuffle left and right,
FileTools path adjusted just right,
No workspace bounds to hold us tight,
Version bumps—the code takes flight!

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch hotfix/motion-graphics-import-fix-0.2.25

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

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

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

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 updates the FileTools import path and instantiation across the video motion graphics modules, while also bumping the package version to 0.2.25. A potential issue was identified where removing the base_dir argument from FileTools might lead to file path inconsistencies if the agent does not use absolute paths within the designated workspace.

# Create tools.
# FileTools is a utility class with bound methods; pass the instance so the
# Agent can register read_file/write_file/list_files as callable tools.
file_tools = FileTools()
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

Since FileTools no longer accepts a base_dir in its constructor, it likely defaults to the current working directory for file operations. This poses a risk if the process CWD differs from the intended workspace (which is often a temporary directory), as the agent might write files where the RenderTools (which uses the workspace path) cannot find them. Adding an explicit instruction to the agent to use absolute paths within the workspace helps ensure consistency.

    file_tools = FileTools()\n    base_instructions += f'\\nCRITICAL: All file operations must use absolute paths within the workspace: {workspace}'

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Hotfix to address live-run failures when instantiating the motion graphics team/agent by correcting the FileTools import path and how it is constructed.

Changes:

  • Update FileTools import to praisonaiagents.tools.file_tools.FileTools in motion graphics agent/team.
  • Change FileTools construction in create_motion_graphics_agent() to avoid passing unsupported constructor args.
  • Bump project version to 0.2.25.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
pyproject.toml Bumps package version for the hotfix release.
praisonai_tools/video/motion_graphics/team.py Fixes FileTools import path; adjusts import error handling for search_web.
praisonai_tools/video/motion_graphics/agent.py Fixes FileTools import path and updates instantiation to match upstream API.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +9 to 16
from praisonaiagents.tools.file_tools import FileTools
# search_web is lazily resolved via praisonaiagents.tools.__getattr__
from praisonaiagents.tools import search_web
except (ImportError, AttributeError):
# Fallback for development / partial installs
Agent = None
AgentTeam = None
FileTools = None
Copy link

Copilot AI Apr 19, 2026

Choose a reason for hiding this comment

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

FileTools is imported here but not used anywhere in this module. If it’s not needed for side effects, consider removing the import to reduce confusion and avoid unused-import lint failures in stricter environments.

Suggested change
from praisonaiagents.tools.file_tools import FileTools
# search_web is lazily resolved via praisonaiagents.tools.__getattr__
from praisonaiagents.tools import search_web
except (ImportError, AttributeError):
# Fallback for development / partial installs
Agent = None
AgentTeam = None
FileTools = None
# search_web is lazily resolved via praisonaiagents.tools.__getattr__
from praisonaiagents.tools import search_web
except (ImportError, AttributeError):
# Fallback for development / partial installs
Agent = None
AgentTeam = None

Copilot uses AI. Check for mistakes.
# Create tools.
# FileTools is a utility class with bound methods; pass the instance so the
# Agent can register read_file/write_file/list_files as callable tools.
file_tools = FileTools()
Copy link

Copilot AI Apr 19, 2026

Choose a reason for hiding this comment

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

FileTools() is now instantiated without a workspace/base_dir, but the existing unit tests expect the FileTools instance to be scoped to the agent workspace (see tests/unit/video/test_motion_graphics_agent.py where file_tools.base_dir == str(tmpdir)). This change will break those tests and may also remove the intended sandboxing of file operations to the workspace. Consider configuring the FileTools instance to use workspace via the supported API (e.g., set a base_dir/root attribute after construction or wrap FileTools with a workspace-scoped adapter), and update the related tests accordingly.

Suggested change
file_tools = FileTools()
file_tools = FileTools()
if hasattr(file_tools, "base_dir"):
file_tools.base_dir = str(workspace)

Copilot uses AI. Check for mistakes.
Comment on lines 7 to +13
try:
from praisonaiagents import Agent, AgentTeam
from praisonaiagents.tools import FileTools, search_web
except ImportError:
# Fallback for development
from praisonaiagents.tools.file_tools import FileTools
# search_web is lazily resolved via praisonaiagents.tools.__getattr__
from praisonaiagents.tools import search_web
except (ImportError, AttributeError):
# Fallback for development / partial installs
Copy link

Copilot AI Apr 19, 2026

Choose a reason for hiding this comment

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

Catching AttributeError across the entire import block can accidentally swallow real bugs raised during module import/initialization (not just a missing search_web lazy attribute), and then the code falls back to AgentTeam=None with a misleading "install" error. Consider narrowing the exception handling: keep the praisonaiagents import guarded by ImportError only, and handle search_web resolution in its own guarded block (or via getattr(..., None)) so genuine import-time attribute errors still surface.

Copilot uses AI. Check for mistakes.
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.

2 participants