Skip to content

[FEATURE] Improve agent/task templating with Jinja2 #2651

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

Closed

Conversation

devin-ai-integration[bot]
Copy link
Contributor

[FEATURE] Improve agent/task templating with Jinja2

Description

This PR implements the feature request from issue #2650 to improve agent/task templating with more flexible templating options. It adds support for:

  • Container types (List, Dict, Set)
  • Standard objects (datetime, time)
  • Custom objects
  • Conditional and loop statements
  • Filtering options

The implementation uses Jinja2 for templating while maintaining backward compatibility with the existing {var} syntax.

Changes

  • Add new jinja_templating.py file with functions to convert and render templates
  • Update string_utils.py to use Jinja2 templating while maintaining backward compatibility
  • Update Task class to use the new templating methods
  • Add comprehensive tests for the new functionality
  • Add documentation with examples

Testing

  • Added unit tests for the new templating functions
  • Added integration tests for the Task and Agent classes
  • Verified backward compatibility with existing templates
  • Ran all existing tests to ensure nothing is broken

Related Issues

Fixes #2650

Link to Devin run

https://app.devin.ai/sessions/7801774af00441378d6665e30ecb3929

Requested by

Joe Moura (joao@crewai.com)

Fixes #2650

- Add support for container types (List, Dict, Set)
- Add support for standard objects (datetime)
- Add support for custom objects
- Add support for conditional and loop statements
- Add support for filtering options
- Maintain backward compatibility with existing templates
- Add comprehensive tests
- Add documentation with examples

Co-Authored-By: Joe Moura <joao@crewai.com>
Copy link
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

devin-ai-integration bot and others added 4 commits April 20, 2025 14:40
Co-Authored-By: Joe Moura <joao@crewai.com>
Co-Authored-By: Joe Moura <joao@crewai.com>
Co-Authored-By: Joe Moura <joao@crewai.com>
Co-Authored-By: Joe Moura <joao@crewai.com>
@fmatray
Copy link

fmatray commented Apr 20, 2025

The autodetection is not necessarily a good idea.
For example, what happen if we have and error like {variable}}. It won't be detected correctly.
Moreover, it's not a good idea to mix between different templating engines (crewAI and jinja2)

It's better to have a configuration to switch between "crewAI" and "Jinja2" templating for the whole project.

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] Improve agent/task templating
2 participants