February 5th, 2025

Turning AI Prompts into Playing Cards: A Platform Engineering Experiment

The inspiration for this project came from my desire to leverage AI to create a tangible product that you can hold, touch, and share.  Cardmaker showcases the capabilities of modern AI as a tool to help its user craft a custom card deck.  But that’s not all.  It also provides a unique and tangible product that can be used for educational purposes, marketing, or personal enjoyment.  I’ll let cardmaker introduce itself by showcasing the initial greeting it provides for the user:

cardmaker console greeting

The Process

My first challenge was deciding what theme to use and what content would go on the cards.  This is important because LLMs require grounding to generate high quality completions, and therefore it is advantageous to choose a domain you are well versed in and have content available to ground the model.  I chose Platform Engineering as a theme for the deck.

Step 1: ⛳Grounding the assistant

Advanced models such as GPT-4o are fully aware of concepts like Platform Engineering, however, they will approach it in the most general, non-specific way.  Recent tools and ideas in the domain may not be known to the model based on the date it was last trained. To leverage generative AI in a fast-changing domain like technology, you must ground your agents with fresh context.

To ensure high-quality completions, I grounded my assistant using the Microsoft Platform engineering guide.  The guide is too long to fit within GPT-4o’s context window, so I condensed the full guide into a much shorter document with its key principles and roles.  Then I used these raw ingredients to create cardmaker:

The cardmaker agent’s system prompt can be found here: (cardmaker/Resources/Agent_Prompt_v2.md at master · tacowan/cardmaker)

📝TIP: Use the AI Foundry playground to refine your prompts and summarize grounding documents to fit within the token context window.

Step 2: Giving the 🃏cards structure

Printing requires merging data with a template, requiring structured content.  Generative AI excels at creating structured data.  Here’s how I prompted my agent, instructing it how to store and save it’s work:

Instructions for mapping to a deck of cards:

There are 54 cards in a standard poker deck.
There are 4 suits, ♠️,♣️,♦️, and ♥️'s.
There are 13 card values in each suit, Aces to Kings.
There are 3 face cards in each suit, Jack, Queen, and King.
There are 2 jokers in a deck.
Abreviations:
King = K
Queen = Q
Jack = J
Ace = A

JSON format for a deck of cards, including the specified fields:

```json
[
{
"id": 1,
"suit": "♥️",
"value": "A",
"suit_theme": "Self-Service and Automation",
"@card_image": "Azure-Deployment-Environments-Icon.png",
"role": "Azure Deployment Environments",
"text": "Provides self-service, project-based templates for deploying environments, improving productivity and reducing cognitive load.",
"bing_query": "How do Azure Deployment Environments achieve self-service and automation?",
"@qrcode": "C:/location/1.png",
"quote": "lorem ipsum"
}

Step 3: ⛵Launching the Assistant on a Mission

The vision for Cardmaker is to have AI drive the process and write the content for each card, transforming a laborious, time-consuming task into one managed by generative AI. While not fully autonomous, I wanted the agent to take ownership of writing content and choosing what appears on each card. The user acts as the project director, approving ideas and initiating the next phase. This required a very goal-oriented prompt. Just as with grounding, AI can assist in the creation of a system prompt. Here’s the final and most important piece of the assistant’s system prompt:

System: You are a Command Line Interface (CLI) tool designed to help users understand Platform Engineering concepts through a deck of cards. Your task is to build a deck of cards by mapping Platform Engineering goals, roles, and tooling to the facets of a card deck, including suits, value cards, face cards, and jokers.
   -Goal: Build a deck of cards by mapping Platform Engineering goals, Platform Engineering roles, and Platform Engineering tooling to facets of a card deck (suits, value cards, face cards, and jokers).
   -Context: The user wants to teach platform engineering concepts through a deck of cards,e.g., the deck's face cards, suits, and value cards can represent goals, themes, roles, and tools of Platform Engineering.
   -Source: Use any relevant sources or examples that can help in accurately mapping the goals, roles, and tooling to the card deck.
   -Expectations: Create a fully completed deck with each suit saved to a file. Each card should have a detailed description explaining its relevance to Platform Engineering concepts.
   -Tools: use any tools you need to complete the task, such as the guest_quote() tool.

1. Summarize your objective and ask if they want approach suggestions. 
2. If yes, offer three mapping ideas. 
3. Once they choose, outline a strategy that includes face cards, value cards and suits.
4. Confirm they're ready, and then create the first 13-card suit, saving it to a file.
4. Pause, confirm they want to continue, and repeat for all four suits. 
5. Finally, confirm the deck is complete.

The prompt encourages the Agent to drive towards a task.  This is slightly different than chat interfaces like Microsoft 365 Copilot or Chat GPT in being purpose fit with narrow focus.  If you don’t want a deck of cards, chatting with this Agent might be frustrating as it will drive towards its goal with unstoppable momentum.  Here’s an example of the agent providing several ideas to the user:

Image console3

 

📝TIP: favor Agents that have a narrow focus for best results.  Instead of creating cards, which is too broad, my agent only creates Platform Engineering themed cards, and only poker cards for that matter.

Giving the cardmaker Agent some special skills

You can supplement AI with tools that enable it to query for information or invoke native functions.  Cardmaker uses Semantic Kernel and openAI function calling in several areas.

Alternate Personas 🧙‍♂️

Initially I planned to include an AI-generated explanation of why a particular software engineering tool was chosen for the card, however, I found the content cold and lacking in serendipity or playfulness. My second idea was to have each card feature its own developer quote, but I realized that curating and collecting them for 52 cards would be a monumental task. Instead of using real quotes, I decided to have generative AI craft fictional quotes!  This approach avoided many challenges, such as choosing the quotes, ensuring they are accurately attributed, and aligning them to each card.

I realized that it’s easier to avoid imitating real people, as it may be misconstrued as a real quote, and instead opted for a fictional character with a very distinctive style of speaking: Gandalf. This is often called a persona in generative AI application development.  See my full persona prompt for Gandalf here: cardmaker/Resources/Persona_Prompt.yaml at master · tacowan/cardmaker

The Gandalf persona exists in the application as a “semantic function”. The AI model recognizes this function (see Plugins in Semantic Kernel | Microsoft Learn) and applies it to generate quotes when prompted.  Semantic Kernel helps by injecting context into the prompt, which in this case is the card’s suit theme and tool. This makes it appear as if Gandalf himself reviewed the card and commented on it.

Practical Task Skills

Another skill given to the Agent is the ability to save a file.  This comes into play when the agent has completed 13 cards of a suit.  By saving the file, the user can easily transfer that as input to their data merge and generate image files.  Giving this skill to the Agent is surprisingly simple using Semantic Kernel.  Do this by annotating your C# code appropriately, and the Agent will use the function when it’s needed.  Here is the implementation of this function:

    [KernelFunction("save_cards")]
    [Description("Save the card suit to a local file.")]
    [return: Description("The full card suit in JSON format.")]
    public async Task<string> save_cards(string json_document, [Description("card suit name, such as hearts, clubs, spades, or diamonds")] string suit)
    {
        string filePath = $"{suit}_cards.json";
        await File.WriteAllTextAsync(filePath, json_document);
        var d = Directory.GetCurrentDirectory();
        return "File successfully created at " + d + Path.DirectorySeparatorChar +  filePath;
    }

Functions are useful for things that are difficult for a generative AI model to accomplish.  OpenAI’s function calling feature gives developers the best of both worlds, world class AI chat completion along with your own C# imperative programming wizardry.  Here are the rest of the special skills I gave my Agent:

  • copy_to_clipboard : utility that lets the Agent copy it’s last completion to the clipboard
  • load_cards : load a previous session’s card deck and make modifications
  • create_qr_code: uses a popular C# library to generate a QR code for a card.

Card Design

Cardmaker is a content creation tool, specialized to automate the 1st and most difficult part of creating a themed deck.  Without AI, I would not have undertaken the task.  It’s simply too manual and tedious to write and correlate content for 52 cards.  With AI the task became enjoyable, enabling me to craft several different decks in one sitting.  Here’s an example card after data merge:

 

example card layout, Ace of clubs

This deck used Platform Engineering themes for the suit, mapping “Improve Application Quality” as the theme for clubs.  Unsurprisingly, AI chose application insights as the Ace of clubs.  AI also generates a make-believe quote matching the card’s them and tool.  There are some non-AI assets, for example the Application Insights icon borrowed from the Azure Symbols library.  AI still plays a role as it chooses the images based on the card’s tool and the image name.  I designed my cards using Adobe Illustrator.  Illustrator was useful for two reasons:

  1. the printing service provided poker card sized templates in Illustrator format, making it easier to proof and adjust my template.
  2. Illustrator has a data merge feature, when given a CSV file, it iterates over each row creating an image.

Github Project

You may find cardmaker on github at https://github.com/tacowan/cardmaker

There are three main ingredients in the architecture: GPT-4o model hosted in AI Foundry, the Semantic Kernel framework for orchestration, and a console application.  Most of the logic for the application is located within the prompts.  The application itself provides tools to the agent as semantic kernel plugins.  To suit different domains, all you need to do is modify the agent and persona prompts.

Image cardmaker architecture

📝TIP: To generate cards themed in a different domain, replace Agent_Prompt_v2.md found in the project’s Resources directory.

Conclusion and learning

Creating a custom deck of cards using generative AI has been an enlightening and rewarding experience. This project showcases the capabilities of modern AI and leverages technology to create a tangible, meaningful product. By grounding the AI with relevant context and providing it with specific goals, I was able to produce a deck that is both educational and engaging.  I use these cards daily, as a conversation starter about AI, or as a way to kick off a discussion on tooling in Platform Engineering.

Image cardmaker deck

Generative AI excels at creating variations on a theme, and with the right prompts and tools, it can generate publishable content that is both creative and accurate. This project highlights the importance of grounding AI with up-to-date information and the benefits of using specialized personas to add a unique touch to the generated content.

 

Author

0 comments

Leave a comment

Your email address will not be published. Required fields are marked *