crewAI icon indicating copy to clipboard operation
crewAI copied to clipboard

feat: enhance string interpolation with nested accessors support

Open tortolero-ruben opened this issue 7 months ago • 3 comments

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

tortolero-ruben avatar Apr 19 '25 23:04 tortolero-ruben

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

lucasgomide avatar Apr 23 '25 21:04 lucasgomide

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

tortolero-ruben avatar Apr 23 '25 21:04 tortolero-ruben

hm gotcha.. Your input is well structured. It's exactly feature-request, right?

lucasgomide avatar Apr 24 '25 21:04 lucasgomide

hm gotcha.. Your input is well structured. It's exactly feature-request, right?

Using Jinja templating would be a great solution although a bit more complex. But yes we are essentially asking for the same.

Oddly enough this feature was working on version 0.108. 0.114 removed it. 🤔

tortolero-ruben avatar May 14 '25 19:05 tortolero-ruben

This PR is stale because it has been open for 45 days with no activity.

github-actions[bot] avatar Jun 29 '25 12:06 github-actions[bot]

Closing as stale

greysonlalonde avatar Sep 28 '25 15:09 greysonlalonde