crewAI
crewAI copied to clipboard
feat: enhance string interpolation with nested accessors support
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 do you mind to share a real case that it address?
@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.
hm gotcha.. Your input is well structured. It's exactly feature-request, right?
hm gotcha.. Your
inputis 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. 🤔
This PR is stale because it has been open for 45 days with no activity.
Closing as stale