prompty
prompty copied to clipboard
Cannot use sub-object in prompty template
Hi! We're using prompty templates with SemanticKernel (C#), but running into difficulties when trying to use a sub-object in our templates. I'll give an example.
We have classes like
public class Context
{
public PagesContext Pages { get; set; }
}
public class PagesContext
{
public required IEnumerable<Page> OpenPages { get; set; }
public required IEnumerable<Page> BookmarkedPages { get; set; }
}
public class Page
{
public required string Id { get; set; }
public required string Name { get; set; }
}
We have an instance of the Context class, key named "context", in the KernelArguments we pass to IPromptTemplate.RenderAsync
And in our prompty template, we try to do something like this:
{% for page in context.Pages.BookmarkedPages %}
- Name: {{ page.name }}, ID: {{ page.id }}
{% endfor %}
We've tried these three syntaxes:
context.PagesContext.BookmarkedPagescontext["PagesContext"]["BookmarkedPages"]context['PagesContext']['BookmarkedPages']
None seem to work.
So is what we want possible, and if so, how do we do it?
We are currently reworking the .NET runtime as we speak (well @markwallace-microsoft and I). We have an updated schema to support new agentic scenarios and are working to get the runtime up to speed.
FYI, we've been able to update to SemanticKernel 1.40.1.
OH! Did that fix it?