Skip to content

Instantly share code, notes, and snippets.

@johnjosephhorton
Created April 13, 2024 12:24
Show Gist options
  • Save johnjosephhorton/7e92cd492133303055e6427012c6b871 to your computer and use it in GitHub Desktop.
Save johnjosephhorton/7e92cd492133303055e6427012c6b871 to your computer and use it in GitHub Desktop.
Creating a simple dialog between two agents
(venv) john@Johns-MacBook-Air agent_dialog % python -i AgentDialog.py
John: Hello Robin, I was thinking about going hiking today. Are you interested in joining me?
Robin: Hello John, hiking sounds like a great idea! I was actually hoping to go biking today, but a hike could be a nice compromise. Where were you thinking of hiking?
John: That's great to hear, Robin! I was thinking of hitting the trails at the Green Mountain Forest. There are some fantastic views and the terrain is just right for a good day's hike. How does that sound to you?
Robin: Green Mountain Forest sounds wonderful, John! I've heard the trails there are quite scenic. And you're right, it seems like the perfect place for a good day's hike. Let's do it! What time were you thinking of starting?
John: I'm glad you're on board, Robin! How about we start early to make the most of the day? Meeting at 8:00 AM would give us plenty of time to enjoy the trails. Does that work for you?
Robin: That sounds like a plan, John! Meeting at 8:00 AM works for me. It'll be nice to get an early start. Should we meet at the trailhead or somewhere else before we head to Green Mountain Forest?
John: Meeting at the trailhead sounds good, Robin. It's direct and we won't lose any time. I'll bring some snacks and water. Do you want to bring anything else we might need for the hike?
Robin: Sure, John, I can bring a first-aid kit and a couple of extra trail maps in case we need them. It's always good to be prepared! I'll also pack some sunscreen and bug spray – you can never be too careful. Is there anything specific you'd like me to bring?
John: That sounds fantastic, Robin! You've thought of everything. Maybe just add a light rain jacket or a poncho in case the weather turns; the forecast mentioned a slight chance of rain. Other than that, I think we're all set. Looking forward to hitting the trails with you!
Robin: I'll make sure to pack a rain jacket, John. It's always smart to be prepared for unexpected showers. I'm really looking forward to our hike. See you at the trailhead at 8:00 AM sharp! It's going to be a great day on the trails.
John: See you then, Robin! It's definitely going to be an amazing day. Don't forget to wear comfortable hiking shoes. Drive safely, and I'll meet you at the trailhead at 8:00 AM!
Robin: Will do, John! I'll have my comfy hiking boots on and ready to go. Thanks for the reminder. Take care and I'll see you bright and early at the trailhead. Safe travels!
John: Thanks, Robin! I'll see you tomorrow, bright and early. Have a good night and rest up for our adventure. Goodbye!
Robin: Goodnight, John! I'll be sure to get a good night's sleep for our hike. See you tomorrow at the trailhead. Goodbye!
John: Goodbye, Robin! Looking forward to our hiking adventure. See you at the trailhead at 8:00 AM. Goodnight!
Robin: Goodnight, John! Excited for our adventure too. See you at 8:00 AM at the trailhead. Goodnight!
John: Goodnight, Robin! We've got an exciting day ahead of us. Sleep well!
Robin: Goodnight, John! I'll be sure to get plenty of rest. We do have an exciting day ahead. See you in the morning!
John: Goodnight, Robin! Rest well for the hike. See you in the morning at the trailhead!
Robin: Goodnight, John! I'll be well-rested for our hiking journey. See you at the trailhead in the morning!
>>>
from textwrap import dedent
from itertools import cycle
from edsl import Agent
from edsl import Scenario
from edsl.questions import QuestionFreeText
MAX_TURNS = 20
q = QuestionFreeText(question_text = dedent("""\
You are {{ agent_name }}.
You are talking to {{ other_agent_name }}.
The transcript so far is:
{{ transcript }}
It is your turn to speak.
"""),
question_name = "response"
)
s = Scenario({'agent_name': 'John', 'other_agent_name': 'Robin'})
agents = [
Agent(name = "John", instruction = "You really want to go hiking and will not go biking."),
Agent(name = "Robin", instruction = "You really want to go biking but will go hiking as a compromise.")
]
num_turns = 0
transcript = []
for index in cycle([0,1]):
agent1, agent2 = agents[index], agents[(index+1)%2]
s = Scenario({'agent_name': agent1.name,
'other_agent_name': agent2.name,
'transcript': transcript})
response = q.by(agent1).by(s).run().select('response').first()
print(f"{agent1.name}: {response}")
transcript.append({agent1.name: response})
num_turns += 1
if num_turns >= MAX_TURNS:
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment