Skip to content

feat: enhance string interpolation with nested accessors support #2648

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

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

Conversation

tortolero-ruben
Copy link

This PR adds support for dictionaries and lists as variables.

Changes:

  • expanded the regex pattern to capture dictionaries and lists
  • added helper function to handle chained accessors like list_of_dictionaries[0].first_key
  • comments to make explain the flow

@@ -1,82 +1,307 @@
# /home/ruby/PycharmProjects/crewAI/src/crewai/utilities/string_utils.py
Copy link
Contributor

Choose a reason for hiding this comment

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

drop this comment pls

@lucasgomide
Copy link
Contributor

@tortolero-ruben do you mind to share a real case that it address?

removed comment
@tortolero-ruben
Copy link
Author

@tortolero-ruben do you mind to share a real case that it address?

No problem.

I have a task that I'm defining like:

description:
  <inputs>
    <documentation>
      {documentation[0].context_for_this_task}
    </documentation>
    <examples>
      <example1>{documentation[0].example}</example1>
      <example2>{documentation[1].example}</example2>
    </examples>
  </inputs>

Where documentation is a list of dictionaries/pydantic objects containing, in my case documentation and different types of examples for the flow. However, not all documentation and examples are needed for all tasks. Some tasks only need some of the documentation or some examples. So being able to pass a "container" variable like documentation and access the items it's pretty nice.

I understand I could simply define more variables and pass values to those but that becomes burdensome if I have a lot of variables.

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