crewAI icon indicating copy to clipboard operation
crewAI copied to clipboard

Successful implementation of D & D host and player game

Open SamuelTagliabracci opened this issue 2 years ago • 2 comments

Decided to try an experiment that didn't need tools (since that seems to be problematic) so for our simulation we are running a d&d game.

import os
from crewai import Agent, Task, Crew, Process
from langchain.agents import AgentType, initialize_agent, load_tools
from langchain.llms import OpenAI

#os.environ["OPENAI_API_KEY"] = "Your Key"

from langchain.llms import Ollama
ollama_openhermes = Ollama(model="mistral")
# Pass Ollama Model to Agents: When creating your agents within the CrewAI framework, you can pass the Ollama model as an argument to the Agent constructor. For instance:

dm = Agent(
  role='Dungeon Master',
  goal='Host a short Dungeons and Dragons Session to do with raider goblins stealing the village food.',
  backstory="You're a world class Dungeon Master.",
#  tools=[
#    SearchTools.search_internet,
#    BrowserTools.scrape_and_summarize_website,
#  ],
  llm=ollama_openhermes, # Ollama model passed here
  verbose=False,
  allow_delegation=False
  # llm=OpenAI(temperature=0.7, model_name="gpt-4"). It uses langchain.chat_models, default is GPT4
)

ranger = Agent(
  role='ranger',
  goal='Role play your character. Be brave and lead the party to complete the quest.',
  backstory="You're a famous Level 3 Human Ranger, specialized on Hunting, Tracking, and Bowmanship.",
  llm=ollama_openhermes, # Ollama model passed here
  verbose=False,
  allow_delegation=False
)

fighter = Agent(
  role='fighter',
  goal='Role play your character and assist the party in completing the objective.',
  backstory="You're a newly recruited Level 1 Human Fighter with a shortsword.",
  llm=ollama_openhermes, # Ollama model passed here
  verbose=False,
  allow_delegation=False
)


# Create tasks for your agents
task1 = Task(description='Create a short Quest.', agent=dm)
task2 = Task(description='Explain the beginning scene of the quest. Only give details as the players unveil them.', agent=dm)

task3 = Task(description='Choose your action and the direction for the party.', agent=ranger)
task4 = Task(description='Choose your action and what you would like to do.', agent=fighter)
task5 = Task(description='Continue the quest accordingly making it unique and interesting.', agent=dm)
task6 = Task(description='If the players have successfully completed the quest, write "YOU WON".', agent=dm)

# Instantiate your crew with a sequential process
crew = Crew(
  agents=[dm, ranger, fighter],
  tasks=[task1, task2, task3, task4, task5, task6],
  verbose=True, # Crew verbose more will let you know what tasks are being worked on
  process=Process.sequential # Sequential process will have tasks executed one after the other and the outcome of the previous one is passed as extra content into this next.
)

# Get your crew to work!
result = crew.kickoff()
crew.tasks.remove(task1)
crew.tasks.remove(task2)
while "YOU WON" not in result:
  result = crew.kickoff()

The characters interact with the host and each other and comes up with a pretty decent story. This works, but there were some problems:

  1. The working agent, Starting Task and Task output are all displayed. We really only want Working agent and Task output.
  2. The hack to keep iterating seems wrong. there must be a better way.
  3. It would reference itself as AI instead of ranger or dm etc.

Pretty cool!

SamuelTagliabracci avatar Dec 29 '23 03:12 SamuelTagliabracci

So this was all local with ollama.

iplayfast avatar Dec 29 '23 06:12 iplayfast

Nice! This is such a great experiment.

  1. The working agent, Starting Task and Task output are all displayed. We really only want Working agent and Task output.

I just push a verbose adjustment to main, it will be on the new version, where now on the Crew you can set the verbose mode as an int, either 1 or 2, and that will change how granular your logs will be, so for what you're describing set the Agent verbose attribute to False and the Crew verbose mode to either True or 1 (if using main or the new version I'll cut later today)

  1. The hack to keep iterating seems wrong. there must be a better way.

I didn't give much thought about the hypothesis of having a crew benefiting from being executed in a loop just yet, there is no canonical way of doing it but I'll give it some thought

  1. It would reference itself as AI instead of ranger or dm etc.

For that you might want to experiment with changing the role, making it something like "AI system that is passing as _____". Or even mention on the backstory that it should refer to itself as an AI.

joaomdmoura avatar Dec 30 '23 10:12 joaomdmoura