Embedded Context
In the “Hello World” example, the agent functionality was quite simple and resulted in a very average response using the SendMessage action. Once the Skill Script included the system and assistant blocks and the GetMemory action, we could see a resemblance of a functioning intelligent agent.
Let’s now create a basic, more functional agent for a specific use case like a receptionist agent for a hotel. What else does the Skill Script need to begin answering questions from a user who would like to find out more information on room availability and cost?
The short answer: It needs some context information about the hotel that the agent can use to provide a user with answers to their questions.
This example demonstrates how to create a basic intelligent agent by hardcoding plain text information into the Skill Script to send as a prompt to an LLM.
Goal: Create a basic intelligent agent by hardcoding plain text information into the Skill Script to send as a prompt to an LLM.
Using the same connector, skill, and event setup as with the “Hello World” example, copy the following code into the Skill Script. Alternatively, you can restart the process and create a new agent and flow.
If creating a new agent and flow, go through the steps to create a new Sandbox chat connector with a different name. If you don’t do this, and use an existing connector, when a user sends a message in the Sandbox chat, all flows using this connector will activate simultaneously, which is not ideal.
{{#system~}}
{{set(name='agent_', value=GetAgent())}}
{{set(name='user_', value=GetUser())}}
{{set(name='memory', value=GetMemory(count=40, maxLen=20000))}}
BIOGRAPHY:
You are a receptionist Agent named {{agent_}} for the Hotel called “Carmel Ocean Inn,” talking to User named {{user_}}.
CONTEXT:
**Add information about the hotel related to rooms, availability, and cost.**
EXPLICIT CONSTRAINTS:
- Reply in the language the User is speaking.
- Don’t use emojis.
- Verbosity level: Low verbosity (20 words or less) for a new Instruction step and high verbosity only if the User requests details, more information, or if you are conducting a deep_dive workflow.
- When you write your reply, remember who made the last reply. If you were the last to respond, then write your reply taking into account your last answer (i.e., continue the thought).
AGENT-USER MEMORY:
{{memory}}
{{agent_}}:
{{~/system}}
{{#assistant~}}
{{gen(name='RESULT', temperature=0.75)}}
{{~/assistant}}
Additionally, add any information you’d like to replace the section denoted by ** ** regarding hotel rooms. For example:
Carmel Ocean Inn features individually decorated accommodations with free Wi-Fi. Carmel Beach is less than 1 mile away.
A flat-screen cable TV is provided in each accommodation at Carmel Ocean Inn. Accommodations include Amish-crafted furniture, private entrances, and private bathrooms. Select accommodations offer fully equipped kitchens and gas fireplaces.
Pebble Beach Golf Club is 2 miles away from the property. Monterey Bay Aquarium is a 15-minute drive away. Big Sur is 40 minutes’ drive away.
Couples in particular like the location – they rated it 9.3 for a two-person trip.
THE FOLLOWING ROOMS ARE AVAILABLE
>>>Room Type
Guadalupe Room,
2 twin beds
247 sq.feet Private BathroomFlat-screen TVCoffee machineFree WiFi
Free toiletries Toilet Fireplace Bathtub or shower Towels Linens Sitting area Private entrance TV Refrigerator Telephone Ironing facilities Tea/Coffee maker Iron Heating Hairdryer Carpeted Cable channels Alarm clock Wardrobe or closet Upper floors accessible by stairs only Toilet paper Carbon monoxide detector
Number of guests
2
Price for 1 night
Original price US$292
Current price US$224
+US$48 taxes and fees
Non-refundable
>>>Room Type
Scenic Room, 1 King
1 king bed
280 sq.feet Inner courtyard viewPrivate BathroomFlat-screen TVCoffee machineFree WiFi
Free toiletries Toilet Fireplace Bathtub or shower Towels Linens Desk Sitting area Private entrance TV Refrigerator Telephone Ironing facilities Tea/Coffee maker Iron Heating Hairdryer Carpeted Cable channels Alarm clock Wardrobe or closet Upper floors accessible by stairs only Toilet paper Carbon monoxide detector
Number of guests
2
Price for 1 night
Original price US$378
Current price US$303
+US$51 taxes and fees
Non-refundable
Hotel restaurant is available for booking. There's a fine dining restaurant Fyn or a American restuarant named Sally’s. Both are inside the hotel.
The above text was pulled from a Bookings.com description. Note the formatting is not 100%, which is perfectly okay as the LLM will still be able to understand its meaning. However, although there are no set rules for how you should format plain text within the system block, for the sake of readability, understanding, and potential troubleshooting, here are some general best practices:
- Use all-caps headings to separate segments of information. In this case, we’ve divided sections of text into “BIOGRAPHY,” “CONTEXT,” “EXPLICIT CONSTRAINTS,” and “USER-AGENT MEMORY.” Feel free to play around and experiment with your own unique format.
- Use symbols such as < or > to highlight any text you’d like the LLM to pay closer attention to.
- Add some spacing between different sections.
- Use commas, colons, or dashes to separate list items or indicate lists.
Again, the sky is the limit when it comes to formatting your plain text so do what you think works best.
The set agent and user variables can be used within the plain text (i.e., {{agent_}} and {{user_}}). When the Skill is triggered, these double curly brackets are opened up, and the values stored in these variables are inserted into the text.
Now that you’ve hardcoded information into the Skill Script, let’s continue. Since we are pulling in memory to send to the LLM, let’s create a new user in the Sandbox chat to avoid confusing the LLM with past chat history from previous examples:
- Click the plus icon next to the “User:” section in the Sandbox chat.
- Add a “Name.” In this case, this is the name of a user who will be talking to the agent, which can be your name or a made-up name for testing purposes.
- Click the checkbox if you'd like to create an actor for the user persona. An Actor is someone who communicates through a specific connector. For example, a specific user could communicate via the Sandbox chat (Sandbox chat connector) and over the phone (Twilio connector), which each have identifiers of separate actors. For this case, we are going to create a single actor for Sandbox chat communications (ensure the checkbox is ticked).
- Under the "Actor settings," select “sandbox” for the “Integration” and “connector” for the “Connector.”
- Click Create and apply to save the user.
Click Save and Publish, type “Hello” into the Sandbox chat, and click the send icon. The agent should now respond to you as if you’re conversing. Ask it about the available rooms and the cost of the room.
Now that you have a functioning intelligent agent, play around with it a bit, add more information, and ask the agent more questions. You can also click the > icon next to the agent response and the Show Prompt button to see what information is sent to the LLM.
Updated 7 months ago