iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
🍫

Solving Challenges and Implementing AI Agents for the Entertainment Chat App 'Ni-Ichi-Yon'

に公開

Introduction

This article is written for participation in the AI Agent Hackathon with Google Cloud.

Hello, I'm yasuna, an independent developer.
For this hackathon, I have developed "Ni-Ichi-Yon" (2-1-4), an entertainment chat app for enjoying Valentine's Day with three unique high school girls.

Development Period

This app was developed in about 4 weeks starting from the beginning of 2025 (approximately 2-3 hours per day).

Demo Video

https://www.youtube.com/watch?v=GFBH4dtzuZE

Target User

Now, let me explain the target user for this app.

Those who fit the target audience for this app are, quite literally, people of all ages and genders.
Everyone surely wants to feel the excitement of an event like Valentine's Day and enjoy it to the fullest.

The biggest feature of this app is that it pre-sets the specific scene of Valentine's Day.
What kind of scenes does everyone imagine when they think of Valentine's?

"Will I actually be able to get any chocolate?"
"Who is that girl going to give her chocolate to?"
"Did she make chocolate yesterday? If it's handmade, what shape is it?"

Even with the single word "Valentine's," there are various situations and dramas within it.
While many AI-powered apps focus on business efficiency or practical convenience, I specifically wanted to deliver something that users could enjoy as pure entertainment.

Challenges

Target users often face specific challenges. Here, I will highlight three issues encountered by "people who want to enjoy the Valentine's Day of their student days":

Solutions to the Challenges

1. Solution to Positional Constraints

People who want to enjoy the Valentine's Day of their student days include those who are no longer students. To enjoy a situation regardless of age or position, entertainment is necessary.

By creating a virtual profile through this application that transcends actual age and position, users can solve this by fully enjoying Valentine's Day in their student days within the world of Ni-Ichi-Yon.

In fact, many girls also want to enjoy the Valentine's Day of their student days. There is often an atmosphere where girls are the ones giving and boys are the ones receiving. As a woman myself, I wanted to experience the nervousness from a boy's perspective.
Through this application, even if the user is a girl, they might receive "Honmei" (true feeling) chocolate on the day of Valentine's. The issue is solved because social gender and position do not matter in entertainment role-playing.

2. Solution to Encounter Constraints

People who want to enjoy the Valentine's Day of their student days may not actually have someone they are mutually interested in.
Unfortunately, in the real world, a person with mutual interest rarely appears out of the blue just around Valentine's Day.

Therefore, in Ni-Ichi-Yon, you can enjoy conversations on Valentine's Day itself with three characters who have completely different personalities.
Furthermore, not just on the day itself, but you can also read a diary of the school life you spent with them the previous day.

By doing this, rather than an "abrupt meeting," we ensure that a certain level of relationship has been established with you. This creates a natural "encounter" for the conversation on Valentine's Day, thereby solving the encounter constraint.

3. Solution to Empathy Constraints

While you might be able to enjoy Valentine's Day with a character you already know, it is difficult to empathize with a character unless you feel they know something about you as well.

Therefore, there are three solutions for empathy constraints.

First is the user's personality analysis. By entering their name and profile, the user becomes a student attending the same school as the characters.
Then, an AI agent performs a personality analysis based on the user profile, and the characters create a diary of their life with you tailored to that personality.

Second is the character's emotion analysis.
In the chat, the AI determines in real-time how the character felt in response to the words entered by the user.
The numerical values of the character's emotions are reflected in the "Doki-Doki Meter" (Excitement Meter) and "Choco Meter," which are displayed in the UI.

Third is the generation of chat based on emotion analysis results.
Based on the diary and conversations from the personality analysis, the results of the emotion analysis are reflected in the responses in real-time.

Since the responses based on the character's emotions rely heavily on the user, it becomes easier to feel the nervousness of a student-day Valentine's, thus solving the empathy constraint.

System Configuration

This section introduces the system configuration of this application.

  1. Frontend Layer

    React Application (UI)

    Service Layer

    • ChatService (Text Generation Agent)

      • Management of conversation history
      • Generation of prompts
      • Formatting of responses
      • Maintenance of context
    • DiaryService (Diary Generation Agent)

      • Personality analysis based on user profile
      • Thought generation by characters
      • Diary generation by characters
    • EmotionService (Emotion Analysis Service)

      • Real-time emotion analysis
      • Calculation of emotion values
      • Application of character-specific coefficients
      • Threshold management
  2. Backend Layer (Google Cloud)

    Cloud Run

    • Server
      • Processing requests from the frontend
      • Controlling communication with Vertex AI

    Vertex AI (Gemini-1.0-pro)

    • Dialogue generation
    • Emotion analysis
    • Diary generation
  3. Persistence Layer (LocalStorage)

AI Agent Implementation

In this application, I have implemented two AI agents: a Diary Generation Agent and an Emotion-Aware Dialogue Agent.

About the Diary Generation Agent (DiaryService)

The diary is generated through a step-by-step process.

  1. User Analysis (Psychological Counselor)
  2. Thought Generation (Character)
  3. Diary Creation (Character)

These three stages are executed in order.

Each prompt is generated dynamically, and the results are passed sequentially to the next stage.

  1. User Analysis (Psychological Counselor)
As a psychological counselor, please conduct a personality analysis of the following person.
The analysis results will be used later as reference information for a high school girl to write about her unrequited feelings.

Target Person:
Name: ${userProfile.name}
Profile: ${userProfile.description}

Specifically analyze the following items:

1. Personality Traits
- Extroversion/Introversion
- Meticulousness/Broad-mindedness
- Communication style

2. Hobbies/Interests
- Activities they might like
- How they spend their holidays
- Topics they might be interested in

3. School Life
- Relationships with friends
- Attitude during class
- Behavior in club activities or events

4. Romantic Tendencies
- How they interact with the opposite sex
- Their views on romance
- Their reaction when approached

Please summarize the analysis in about 200 characters, including specific episodes.
  1. Thought Generation (Character)
As ${character.name}, please express your unrequited feelings in a monologue format.
Write while keeping the setting of ${character.description} in mind.

Characteristics of the person you have a crush on:
${Profile}

Please write your feelings for each of the following time periods, along with specific scenes and actions:

1. Morning
- Anticipation when going to school
- Morning greetings or passing each other in the hallway
- Appearance during the morning assembly or HR (homeroom)

2. Noon
- Secretly watching them during class
- Scene during lunch break
- Events during collaborative work or duty activities

3. After school
- Interactions during club or committee activities
- Scene when leaving school
- Plan for making Valentine's Day chocolates

Please express the feelings and impressions felt in each scene using a manner of speaking typical of ${character.name}.
Summarize in about 300 characters in total.
  1. Diary Creation (Character)
As ${character.name}, please write a diary for February 13, 2025.
Write while keeping the setting of ${character.description} in mind.

Today's events and feelings:
${thoughts}

Please write the diary including the following elements:

1. Basic Diary Elements
- Date of February 13, 2025
- Weather and mood
- Description of events in chronological order

2. Style and Tone
- Manner of speaking typical of ${character.name}
- An intimate style like talking to oneself
- Delicate emotional expression

3. Content Structure
- Flow of time from morning to night
- Detailed descriptions of school life
- Expression of unrequited feelings
- Anticipation and anxiety for Valentine's Day tomorrow

4. Notes on Expression
- Do not use emojis
- Length of about 300 characters
- Expressions incorporating descriptions of scenes
- Development that shows changes in feelings
- Appropriately use the character's catchphrases or characteristic expressions

When writing the diary, be mindful that it is a special day—the day before Valentine's Day—and write in a way that strongly brings out the character's personality.

By thinking and connecting stages step-by-step, it is possible to create a diary of school life where you and the characters live.

Emotion-Aware Dialogue Agent (ChatService and EmotionService)

Next, I will introduce the flow of the AI agent for the chat portion with the characters.

In this app, by combining chat functionality with emotion analysis,
we have realized a dialogue that recognizes the emotions of both the user and the characters.

This allows for highly empathetic conversations that stir the user's emotions.
The flow from user input to response is as follows:

There are three key points in this agent's flow:

  1. Dual Emotion Analysis
    Emotion analysis is performed on both the user's input messages and the character's responses.

  2. Emphasis on State Management
    Emotion scores and states are continuously updated.

  3. Intelligent Process Control
    Prompts are dynamically generated based on the results of the emotion analysis.

Acknowledgements

Thank you very much for providing such a wonderful opportunity with this hackathon!

In the development of this application, I referred to the following two books!
AITuberを作ってみたらプロンプトエンジニアリングがよくわかった件
LangChainとLangGraphによるRAG・AIエージェント[実践]入門

I plan to release a demo of this application personally on February 14th,
so I would be happy if you could follow me on X.

Thank you for reading this far! Happy Valentine's Day!

https://x.com/yasun_ai/status/1885981953620602884

GitHubで編集を提案

Discussion