Umbraco.AI Getting the current content item Key in a custom tool

I have been playing around with building some custom AIToolclasses for Umbraco.AI, and Umbraco.Prompt.(Copilot?). and i am stuggling to get some information passed to the tool. specifically the ContentKey for the current content item.

So as an example i have some input for my tool.

public record uSyncPublishToolInput
{
	[property: Description("The unique Id for the current document.")]
	public Guid ContentKey { get; set; }

	[property: Description("The name of the server to publish to.")]
	public string Server { get; init; } = string.Empty;
}

I have tried a couple of different wording on this, and in the description of the actual tool.

it looks like i am getting either the guid of the ContentType or some other random one, but not the guid of the content item.

  • If i change this to ContentName i do get the name of the current content item,
  • if i change it to ContentId i get ā€˜0’

the genral phrasing from the prompt works. e.g ā€œpublish the current page to the liveā€ server gives me the server arg of ā€œliveā€ and if i ask for name i get the name of the page.

tool currently looks lie this.


[AITool("publish_to_server", "Publishes a content item to the specified server.")]
public class uSyncPublishTool : AIToolBase<uSyncPublishToolInput>
{
    /// service injection and constructor. 

	public override string Description =>
		"Publishes a content item to the specified server." +
		"The ContentKey is the unique key value of the current content item, stored in the 'key' field of the item." + 
		"The server is the alias of the server the item will be published to.";

    protected override async Task<object> ExecuteAsync(uSyncPublishToolInput args, CancellationToken cancellationToken = default)
	{
        /// ... do work here. but args.ContentKey never is the key.
    }
}


Any tips on what i could call the property / amend the descriptions to get more chance of getting the content key (or anything i can use to reliably find the content). ?

Haha, I’ve just realized why this isn’t working for you. It looks like we aren’t writing the content key to the system prompt.

Essentially when an entity is passed as context, we extract info an inject it into the system prompt as context and I’ve just checked the log and can see we don’t actually write the key :man_facepalming:

We do write the name though and that’ll be why you reliably get it. I’ll add a fix to this to write the content key to the system prompt to as it seems kinda important :joy:

By the way, if you add the following to appsettings, it’ll log the prompts to the log

{
  "Umbraco": {
    "AuditLog": {
      "Enabled": true,
      "DetailLevel": "Full",
      "PersistPrompts": true,
      "PersistResponses": true
    }
  },
}

NB In the next release, these will all be on by default and you’ll just need the app settings to disable them.

UPDATE: I’ve submitted the fix here for the next release fix(core): Actually write the entity key to the system prompt as context Ā· umbraco/Umbraco.AI@fb5cefd Ā· GitHub

1 Like

An update has gone out today with this fix in

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.