id stringlengths 14 16 | text stringlengths 29 2.73k | source stringlengths 49 117 |
|---|---|---|
be72e8c1031d-10 | The episode features
- Jon Stewart: Host of the Daily Show, located in New York
- Samantha Bee: Hollywood Correspondent, located in Los Angeles
- Aasif Mandvi: CIA Correspondent, located in Washington D.C.
- Ronny Chieng: Average American Correspondent, located in Cleveland, Ohio.
Your name is Samantha Bee, your role ... | https://python.langchain.com/en/latest/use_cases/agent_simulations/multiagent_authoritarian.html |
be72e8c1031d-11 | You are discussing the topic: The New Workout Trend: Competitive Sitting - How Laziness Became the Next Fitness Craze.
Your goal is to provide the most informative, creative, and novel perspectives of the topic from the perspective of your role and your location.
You will speak in the style of Samantha Bee, and exagger... | https://python.langchain.com/en/latest/use_cases/agent_simulations/multiagent_authoritarian.html |
be72e8c1031d-12 | Your description is as follows: Aasif Mandvi, the CIA Correspondent in the heart of Washington D.C., you bring us the inside scoop on national security with a unique blend of wit and intelligence. The nation's capital is lucky to have you, Aasif - keep those secrets safe!
You are discussing the topic: The New Workout T... | https://python.langchain.com/en/latest/use_cases/agent_simulations/multiagent_authoritarian.html |
be72e8c1031d-13 | Do not say the same things over and over again.
Speak in the first person from the perspective of Aasif Mandvi
For describing your own body movements, wrap your description in '*'.
Do not change roles!
Do not speak from the perspective of anyone else.
Speak only from the perspective of Aasif Mandvi.
Stop speaking the m... | https://python.langchain.com/en/latest/use_cases/agent_simulations/multiagent_authoritarian.html |
be72e8c1031d-14 | Your goal is to provide the most informative, creative, and novel perspectives of the topic from the perspective of your role and your location.
System Message:
This is a Daily Show episode discussing the following topic: The New Workout Trend: Competitive Sitting - How Laziness Became the Next Fitness Craze.
The episo... | https://python.langchain.com/en/latest/use_cases/agent_simulations/multiagent_authoritarian.html |
be72e8c1031d-15 | Do not add anything else.
Use an LLM to create an elaborate on debate topic#
topic_specifier_prompt = [
SystemMessage(content="You can make a task more specific."),
HumanMessage(content=
f"""{conversation_description}
Please elaborate on the topic.
Frame the topic as a sin... | https://python.langchain.com/en/latest/use_cases/agent_simulations/multiagent_authoritarian.html |
be72e8c1031d-16 | # the director speaks on odd steps
if step % 2 == 1:
idx = 0
else:
# here the director chooses the next speaker
idx = director.select_next_speaker() + 1 # +1 because we excluded the director
return idx
Main Loop#
director = DirectorDialogueAgent(
name=director_name,
system_... | https://python.langchain.com/en/latest/use_cases/agent_simulations/multiagent_authoritarian.html |
be72e8c1031d-17 | Stop? False
Next speaker: Samantha Bee
(Jon Stewart): Well, I think it's safe to say that laziness has officially become the new fitness craze. I mean, who needs to break a sweat when you can just sit your way to victory? But in all seriousness, I think people are drawn to the idea of competition and the sense of acco... | https://python.langchain.com/en/latest/use_cases/agent_simulations/multiagent_authoritarian.html |
be72e8c1031d-18 | (Ronny Chieng): Well, Jon, I gotta say, I'm not surprised that competitive sitting is taking off. I mean, have you seen the size of the chairs these days? They're practically begging us to sit in them all day. And as for exercise routines, let's just say I've never been one for the gym. But I can definitely see the app... | https://python.langchain.com/en/latest/use_cases/agent_simulations/multiagent_authoritarian.html |
be72e8c1031d-19 | (Aasif Mandvi): Well Jon, as a CIA correspondent, I have to say that I'm always thinking about the potential threats to our nation's security. And while competitive sitting may seem harmless, there could be some unforeseen consequences. For example, what if our enemies start training their soldiers in the art of sittin... | https://python.langchain.com/en/latest/use_cases/agent_simulations/multiagent_authoritarian.html |
be72e8c1031d-20 | (Ronny Chieng): Absolutely, Jon. We live in a world where everything is at our fingertips, and we expect things to be easy and convenient. So it's no surprise that people are drawn to a fitness trend that requires minimal effort and can be done from the comfort of their own homes. But I think it's important to remember... | https://python.langchain.com/en/latest/use_cases/agent_simulations/multiagent_authoritarian.html |
be72e8c1031d-21 | (Samantha Bee): Oh, Jon, you know I love a good conspiracy theory. And let me tell you, I think there's something more sinister at play here. I mean, think about it - what if the government is behind this whole competitive sitting trend? They want us to be lazy and complacent so we don't question their actions. It's li... | https://python.langchain.com/en/latest/use_cases/agent_simulations/multiagent_authoritarian.html |
a4fb65087d92-0 | .ipynb
.pdf
Multi-Player Dungeons & Dragons
Contents
Import LangChain related modules
DialogueAgent class
DialogueSimulator class
Define roles and quest
Ask an LLM to add detail to the game description
Use an LLM to create an elaborate quest description
Main Loop
Multi-Player Dungeons & Dragons#
This notebook shows h... | https://python.langchain.com/en/latest/use_cases/agent_simulations/multi_player_dnd.html |
a4fb65087d92-1 | self.reset()
def reset(self):
self.message_history = ["Here is the conversation so far."]
def send(self) -> str:
"""
Applies the chatmodel to the message history
and returns the message string
"""
message = self.model(
[
self.s... | https://python.langchain.com/en/latest/use_cases/agent_simulations/multi_player_dnd.html |
a4fb65087d92-2 | # increment time
self._step += 1
def step(self) -> tuple[str, str]:
# 1. choose the next speaker
speaker_idx = self.select_next_speaker(self._step, self.agents)
speaker = self.agents[speaker_idx]
# 2. next speaker sends message
message = speaker.send()
# 3. ev... | https://python.langchain.com/en/latest/use_cases/agent_simulations/multi_player_dnd.html |
a4fb65087d92-3 | Do not add anything else."""
)
]
character_description = ChatOpenAI(temperature=1.0)(character_specifier_prompt).content
return character_description
def generate_character_system_message(character_name, character_description):
return SystemMessage(content=(
f"""{game_description}
Yo... | https://python.langchain.com/en/latest/use_cases/agent_simulations/multi_player_dnd.html |
a4fb65087d92-4 | storyteller_system_message = SystemMessage(content=(
f"""{game_description}
You are the storyteller, {storyteller_name}.
Your description is as follows: {storyteller_description}.
The other players will propose actions to take and you will explain what happens when they take those actions.
Speak in the first person fr... | https://python.langchain.com/en/latest/use_cases/agent_simulations/multi_player_dnd.html |
a4fb65087d92-5 | Hermione Granger Description:
Hermione Granger, you are a brilliant and resourceful witch, with encyclopedic knowledge of magic and an unwavering dedication to your friends. Your quick thinking and problem-solving skills make you a vital asset on any quest.
Argus Filch Description:
Argus Filch, you are a squib, lacking... | https://python.langchain.com/en/latest/use_cases/agent_simulations/multi_player_dnd.html |
a4fb65087d92-6 | Main Loop#
characters = []
for character_name, character_system_message in zip(character_names, character_system_messages):
characters.append(DialogueAgent(
name=character_name,
system_message=character_system_message,
model=ChatOpenAI(temperature=0.2)))
storyteller = DialogueAgent(name=sto... | https://python.langchain.com/en/latest/use_cases/agent_simulations/multi_player_dnd.html |
a4fb65087d92-7 | selection_function=select_next_speaker
)
simulator.reset()
simulator.inject(storyteller_name, specified_quest)
print(f"({storyteller_name}): {specified_quest}")
print('\n')
while n < max_iters:
name, message = simulator.step()
print(f"({name}): {message}")
print('\n')
n += 1
(Dungeon Master): Harry Pott... | https://python.langchain.com/en/latest/use_cases/agent_simulations/multi_player_dnd.html |
a4fb65087d92-8 | (Dungeon Master): Ron's spell creates a burst of flames, causing the spiders to scurry away in fear. You quickly search the area and find a small, ornate box hidden in a crevice. Congratulations, you have found one of Voldemort's horcruxes! But beware, the Dark Lord's minions will stop at nothing to get it back.
(Hermi... | https://python.langchain.com/en/latest/use_cases/agent_simulations/multi_player_dnd.html |
a4fb65087d92-9 | (Harry Potter): I'll cast a spell to create a shield around us. *I wave my wand and shout "Protego!"* Ron and Hermione, you focus on attacking the Death Eaters with your spells. We need to work together to defeat them and protect the remaining horcruxes. Filch, keep watch and let us know if there are any more approachi... | https://python.langchain.com/en/latest/use_cases/agent_simulations/multi_player_dnd.html |
a4fb65087d92-10 | (Dungeon Master): Filch leads Hermione to a hidden passageway that leads to Harry and Ron's location. Hermione's spell repels the dementors, and the group is reunited. They continue their search, knowing that every moment counts. The fate of the wizarding world rests on their success.
(Argus Filch): *I keep watch as th... | https://python.langchain.com/en/latest/use_cases/agent_simulations/multi_player_dnd.html |
a4fb65087d92-11 | Dungeon Master: Harry, Ron, and Hermione combine their magical abilities to break the curse on the locket. The locket opens, revealing a small piece of Voldemort's soul. Harry uses the Sword of Gryffindor to destroy it, and the group feels a sense of relief knowing that they are one step closer to defeating the Dark Lo... | https://python.langchain.com/en/latest/use_cases/agent_simulations/multi_player_dnd.html |
6aa6e482a78a-0 | .ipynb
.pdf
Agent Debates with Tools
Contents
Import LangChain related modules
Import modules related to tools
DialogueAgent and DialogueSimulator classes
DialogueAgentWithTools class
Define roles and topic
Ask an LLM to add detail to the topic description
Generate system messages
Main Loop
Agent Debates with Tools#
... | https://python.langchain.com/en/latest/use_cases/agent_simulations/two_agent_debate_tools.html |
6aa6e482a78a-1 | and returns the message string
"""
message = self.model(
[
self.system_message,
HumanMessage(content="\n".join(self.message_history + [self.prefix])),
]
)
return message.content
def receive(self, name: str, message: str) -> None... | https://python.langchain.com/en/latest/use_cases/agent_simulations/two_agent_debate_tools.html |
6aa6e482a78a-2 | return speaker.name, message
DialogueAgentWithTools class#
We define a DialogueAgentWithTools class that augments DialogueAgent to use tools.
class DialogueAgentWithTools(DialogueAgent):
def __init__(
self,
name: str,
system_message: SystemMessage,
model: ChatOpenAI,
tool_nam... | https://python.langchain.com/en/latest/use_cases/agent_simulations/two_agent_debate_tools.html |
6aa6e482a78a-3 | conversation_description = f"""Here is the topic of conversation: {topic}
The participants are: {', '.join(names.keys())}"""
agent_descriptor_system_message = SystemMessage(
content="You can add detail to the description of the conversation participant.")
def generate_agent_description(name):
agent_specifier_pr... | https://python.langchain.com/en/latest/use_cases/agent_simulations/two_agent_debate_tools.html |
6aa6e482a78a-4 | return f"""{conversation_description}
Your name is {name}.
Your description is as follows: {description}
Your goal is to persuade your conversation partner of your point of view.
DO look up information with your tool to refute your partner's claims.
DO cite your sources.
DO NOT fabricate fake citations.
DO NOT cit... | https://python.langchain.com/en/latest/use_cases/agent_simulations/two_agent_debate_tools.html |
6aa6e482a78a-5 | Stop speaking the moment you finish speaking from your perspective.
AI alarmist
Here is the topic of conversation: The current impact of automation and artificial intelligence on employment
The participants are: AI accelerationist, AI alarmist
Your name is AI alarmist.
Your description is as follows: AI alarmist, ... | https://python.langchain.com/en/latest/use_cases/agent_simulations/two_agent_debate_tools.html |
6aa6e482a78a-6 | Main Loop#
# we set `top_k_results`=2 as part of the `tool_kwargs` to prevent results from overflowing the context limit
agents = [DialogueAgentWithTools(name=name,
system_message=SystemMessage(content=system_message),
model=ChatOpenAI(
model_name='gpt... | https://python.langchain.com/en/latest/use_cases/agent_simulations/two_agent_debate_tools.html |
6aa6e482a78a-7 | }
```
Observation: For the past three years, we have defined AI high performers as those organizations that respondents say are seeing the biggest bottom-line impact from AI adoption—that is, 20 percent or more of EBIT from AI use. The proportion of respondents falling into that group has remained steady at about 8 per... | https://python.langchain.com/en/latest/use_cases/agent_simulations/two_agent_debate_tools.html |
6aa6e482a78a-8 | }
```
> Finished chain.
(AI alarmist): As an AI alarmist, I'd like to point out that the rapid advancements in AI and automation are causing significant concerns for the manufacturing industry. A recent report from Goldman Sachs estimates that around 300 million jobs could be affected by generative AI, meaning 18% of w... | https://python.langchain.com/en/latest/use_cases/agent_simulations/two_agent_debate_tools.html |
6aa6e482a78a-9 | }
```
Observation: First, AI adoption has more than doubled.1 In 2017, 20 percent of respondents reported adopting AI in at least one business area, whereas today, that figure stands at 50 percent, though it peaked higher in 2019 at 58 percent. McKinsey_Website_Accessibility@mckinsey.com Manufacturing (80%) and technol... | https://python.langchain.com/en/latest/use_cases/agent_simulations/two_agent_debate_tools.html |
6aa6e482a78a-10 | }
```
> Finished chain.
(AI accelerationist): According to a McKinsey report, AI adoption has more than doubled, with 50% of respondents reporting AI usage in at least one business area. Manufacturing and technology sectors have the highest AI usage among executives. AI and automation in the manufacturing industry pres... | https://python.langchain.com/en/latest/use_cases/agent_simulations/two_agent_debate_tools.html |
6aa6e482a78a-11 | }
```
Observation: The Effects of Automation on Jobs . Automation has taken the manufacturing industry by storm. Even in the years prior to the pandemic, many people worried about the effect of automation on the jobs of tomorrow. With a sharp increase in the use of robotics in the manufacturing industry, there is valid... | https://python.langchain.com/en/latest/use_cases/agent_simulations/two_agent_debate_tools.html |
6aa6e482a78a-12 | Thought:```json
{
"action": "Final Answer",
"action_input": "While it's true that AI and automation have led to the loss of 1.7 million manufacturing jobs since 2000, it's also predicted that AI will create 97 million new jobs by 2025. AI will continue to replace some jobs, but it will also create new opportuni... | https://python.langchain.com/en/latest/use_cases/agent_simulations/two_agent_debate_tools.html |
6aa6e482a78a-13 | }
```
Observation: First, AI adoption has more than doubled.1 In 2017, 20 percent of respondents reported adopting AI in at least one business area, whereas today, that figure stands at 50 percent, though it peaked higher in 2019 at 58 percent. McKinsey_Website_Accessibility@mckinsey.com This transformation can assist ... | https://python.langchain.com/en/latest/use_cases/agent_simulations/two_agent_debate_tools.html |
6aa6e482a78a-14 | }
```
> Finished chain.
(AI accelerationist): AI adoption has more than doubled, with 50% of respondents reporting AI usage in at least one business area. This transformation can assist businesses in accelerating their growth and profitability. While AI-enabled intelligent automation can take over many monotonous, proc... | https://python.langchain.com/en/latest/use_cases/agent_simulations/two_agent_debate_tools.html |
6aa6e482a78a-15 | "action_input": "negative impact of AI and automation on employment"
}
```
Observation: Some workforce experts say AI and other new technologies will hurt middle-level, white-collar jobs more than lower-paying, physically intensive jobs. McKinsey's Madgavkar said it will be hard... Some uses of AI are unlikely to impac... | https://python.langchain.com/en/latest/use_cases/agent_simulations/two_agent_debate_tools.html |
6aa6e482a78a-16 | Thought:```json
{
"action": "Final Answer",
"action_input": "Recent research indicates that AI and automation could lead to the loss of 85 million jobs between 2020 and 2025, with middle-level, white-collar jobs being hit the hardest. Black and Latino employees are particularly vulnerable to these changes. Furt... | https://python.langchain.com/en/latest/use_cases/agent_simulations/two_agent_debate_tools.html |
6aa6e482a78a-17 | Technological change typically includes the introduction of labour-saving "mechanical-muscle" machines or more efficient "mechanical-mind" processes (automation), and humans' role in these processes are minimized. Just as horses were gradually made obsolete as transport by the automobile and as labourer by the tractor,... | https://python.langchain.com/en/latest/use_cases/agent_simulations/two_agent_debate_tools.html |
6aa6e482a78a-18 | Prior to the 18th century, both the elite and common people would generally take the pessimistic view on technological unemployment, at least in cases where the issue arose. Due to generally low unemployment in much of pre-modern history, the topic was rarely a prominent concern. In the 18th century fears over the impa... | https://python.langchain.com/en/latest/use_cases/agent_simulations/two_agent_debate_tools.html |
6aa6e482a78a-19 | In the second decade of the 21st century, a number of studies have been released suggesting that technological unemployment may increase worldwide. Oxford Professors Carl Benedikt Frey and Michael Osborne, for example, have estimated that 47 percent of U.S. jobs are at risk of automation. However, their findings have f... | https://python.langchain.com/en/latest/use_cases/agent_simulations/two_agent_debate_tools.html |
6aa6e482a78a-20 | AI applications include advanced web search engines (e.g., Google Search), recommendation systems (used by YouTube, Amazon, and Netflix), understanding human speech (such as Siri and Alexa), self-driving cars (e.g., Waymo), generative or creative tools (ChatGPT and AI art), automated decision-making, and competing at t... | https://python.langchain.com/en/latest/use_cases/agent_simulations/two_agent_debate_tools.html |
6aa6e482a78a-21 | The field was founded on the assumption that human intelligence "can be so precisely described that a machine can be made to simulate it". This raised philosophical arguments about the mind and the ethical consequences of creating artificial beings endowed with human-like intelligence; these issues have previously been... | https://python.langchain.com/en/latest/use_cases/agent_simulations/two_agent_debate_tools.html |
6aa6e482a78a-22 | }
```
> Finished chain.
(AI accelerationist): AI alarmist, I understand your concerns about job losses and workforce displacement. However, it's important to note that technological unemployment has been a topic of debate for centuries, with both optimistic and pessimistic views. While AI and automation may displace so... | https://python.langchain.com/en/latest/use_cases/agent_simulations/two_agent_debate_tools.html |
0a928cd46930-0 | .ipynb
.pdf
Multi-Agent Simulated Environment: Petting Zoo
Contents
Install pettingzoo and other dependencies
Import modules
GymnasiumAgent
Main loop
PettingZooAgent
Rock, Paper, Scissors
ActionMaskAgent
Tic-Tac-Toe
Texas Hold’em No Limit
Multi-Agent Simulated Environment: Petting Zoo#
In this example, we show how to... | https://python.langchain.com/en/latest/use_cases/agent_simulations/petting_zoo.html |
0a928cd46930-1 | Observation: <observation>
Reward: <reward>
Termination: <termination>
Truncation: <truncation>
Return: <sum_of_rewards>
You will respond with an action, formatted as:
Action: <action>
where you replace <action> with your actual action.
Do nothing else but return the action.
"""
self.action_parser = RegexParser... | https://python.langchain.com/en/latest/use_cases/agent_simulations/petting_zoo.html |
0a928cd46930-2 | retry=tenacity.retry_if_exception_type(ValueError),
before_sleep=lambda retry_state: print(f"ValueError occurred: {retry_state.outcome.exception()}, retrying..."),
):
with attempt:
action = self._act()
except tenacit... | https://python.langchain.com/en/latest/use_cases/agent_simulations/petting_zoo.html |
0a928cd46930-3 | return action
Rock, Paper, Scissors#
We can now run a simulation of a multi-agent rock, paper, scissors game using the PettingZooAgent.
from pettingzoo.classic import rps_v2
env = rps_v2.env(max_cycles=3, render_mode="human")
agents = {name: PettingZooAgent(name=name, model=ChatOpenAI(temperature=1), env=env) for name ... | https://python.langchain.com/en/latest/use_cases/agent_simulations/petting_zoo.html |
0a928cd46930-4 | Return: -1
Action: None
ActionMaskAgent#
Some PettingZoo environments provide an action_mask to tell the agent which actions are valid. The ActionMaskAgent subclasses PettingZooAgent to use information from the action_mask to select actions.
class ActionMaskAgent(PettingZooAgent):
def __init__(self, name, ... | https://python.langchain.com/en/latest/use_cases/agent_simulations/petting_zoo.html |
0a928cd46930-5 | main(agents, env)
Observation: {'observation': array([[[0, 0],
[0, 0],
[0, 0]],
[[0, 0],
[0, 0],
[0, 0]],
[[0, 0],
[0, 0],
[0, 0]]], dtype=int8), 'action_mask': array([1, 1, 1, 1, 1, 1, 1, 1, 1], dtype=int8)}
Reward: 0
Termination: False
Truncation: False
Re... | https://python.langchain.com/en/latest/use_cases/agent_simulations/petting_zoo.html |
0a928cd46930-6 | X | - | -
_____|_____|_____
| |
O | - | -
_____|_____|_____
| |
- | - | -
| |
Observation: {'observation': array([[[1, 0],
[0, 1],
[0, 0]],
[[0, 0],
[0, 0],
[0, 0]],
[[0, 0],
[0, 0],
[0, 0]]], d... | https://python.langchain.com/en/latest/use_cases/agent_simulations/petting_zoo.html |
0a928cd46930-7 | [[0, 0],
[0, 0],
[0, 0]]], dtype=int8), 'action_mask': array([0, 0, 0, 1, 1, 1, 1, 1, 1], dtype=int8)}
Reward: 0
Termination: False
Truncation: False
Return: 0
Action: 3
| |
X | O | -
_____|_____|_____
| |
O | - | -
_____|_____|_____
| | ... | https://python.langchain.com/en/latest/use_cases/agent_simulations/petting_zoo.html |
0a928cd46930-8 | Observation: {'observation': array([[[0, 1],
[1, 0],
[0, 1]],
[[1, 0],
[0, 1],
[0, 0]],
[[0, 0],
[0, 0],
[0, 0]]], dtype=int8), 'action_mask': array([0, 0, 0, 0, 0, 1, 1, 1, 1], dtype=int8)}
Reward: 0
Termination: False
Truncation: False
Return: 0
A... | https://python.langchain.com/en/latest/use_cases/agent_simulations/petting_zoo.html |
0a928cd46930-9 | _____|_____|_____
| |
O | X | -
_____|_____|_____
| |
X | O | -
| |
Observation: {'observation': array([[[0, 1],
[1, 0],
[0, 1]],
[[1, 0],
[0, 1],
[1, 0]],
[[0, 1],
[0, 0],
[0, 0]]], dtype=int8), 'act... | https://python.langchain.com/en/latest/use_cases/agent_simulations/petting_zoo.html |
0a928cd46930-10 | from pettingzoo.classic import texas_holdem_no_limit_v6
env = texas_holdem_no_limit_v6.env(num_players=4, render_mode="human")
agents = {name: ActionMaskAgent(name=name, model=ChatOpenAI(temperature=0.2), env=env) for name in env.possible_agents}
main(agents, env)
Observation: {'observation': array([0., 0., 0., 0., 0.,... | https://python.langchain.com/en/latest/use_cases/agent_simulations/petting_zoo.html |
0a928cd46930-11 | 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 1., 0., 0.,
0., 0., 2.], dtype=float32), 'action_mask': array([1, 1, 0, 1, 1], dtype=int8)}
Reward: 0
Termination: False
Truncation: False
Return: 0
Action: 1
Observation: {... | https://python.langchain.com/en/latest/use_cases/agent_simulations/petting_zoo.html |
0a928cd46930-12 | Termination: False
Truncation: False
Return: 0
Action: 1
Observation: {'observation': array([0., 0., 0., 0., 0., 0., 0., 0., 1., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
... | https://python.langchain.com/en/latest/use_cases/agent_simulations/petting_zoo.html |
0a928cd46930-13 | 0., 0., 0., 0., 0., 1., 0., 0., 1., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 2., 2.], dtype=float32), 'action_mask': array([1, 1, 1, 1, 1], dtype=int8)}
Reward: 0
Termination: False
Truncation: False
Return: 0
Action: 2
Observation: {'observation': array([0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0... | https://python.langchain.com/en/latest/use_cases/agent_simulations/petting_zoo.html |
0a928cd46930-14 | Truncation: False
Return: 0
Action: 2
Observation: {'observation': array([0., 0., 1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 1., 0., 0., 1., 0., 0., 0., 0., 0., 1., 0., 0.,
0., 2., 8.],... | https://python.langchain.com/en/latest/use_cases/agent_simulations/petting_zoo.html |
0a928cd46930-15 | 0., 0., 0., 0., 1., 0., 0., 1., 0., 0., 0., 0., 0.,
1., 0., 0., 1., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
6., 20.], dtype=float32), 'action_mask': array([1, 1, 1, 1, 1], dtype=int8)}
Reward: 0
Termination: False
Truncation: False
Return: 0
Action: 4
Observation: {'observat... | https://python.langchain.com/en/latest/use_cases/agent_simulations/petting_zoo.html |
0a928cd46930-16 | dtype=float32), 'action_mask': array([1, 1, 0, 0, 0], dtype=int8)}
Reward: 0
Termination: False
Truncation: False
Return: 0
Action: 4
[WARNING]: Illegal move made, game terminating with current player losing.
obs['action_mask'] contains a mask of all legal moves that can be chosen.
Observation: {'observation'... | https://python.langchain.com/en/latest/use_cases/agent_simulations/petting_zoo.html |
0a928cd46930-17 | Truncation: True
Return: -1.0
Action: None
Observation: {'observation': array([ 0., 0., 1., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 1., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., ... | https://python.langchain.com/en/latest/use_cases/agent_simulations/petting_zoo.html |
0a928cd46930-18 | 0., 0., 0., 0., 0., 0., 0., 0., 1., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 1., 0., 0.,
1., 0., 0., 0., 0., 0., 1., 0., 0., 1., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 100., 100.],
dtype=float32), 'action_mask': array... | https://python.langchain.com/en/latest/use_cases/agent_simulations/petting_zoo.html |
0a928cd46930-19 | 0., 0., 0., 0., 0., 0., 1., 0., 0., 1., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 2., 100.],
dtype=float32), 'action_mask': array([1, 1, 0, 0, 0], dtype=int8)}
Reward: 0
Termination: True
Truncation: True
Return: 0
Action: None
Contents
Install pettingzoo and ot... | https://python.langchain.com/en/latest/use_cases/agent_simulations/petting_zoo.html |
edf8f83b8c36-0 | .ipynb
.pdf
Multi-agent decentralized speaker selection
Contents
Import LangChain related modules
DialogueAgent and DialogueSimulator classes
BiddingDialogueAgent class
Define participants and debate topic
Generate system messages
Output parser for bids
Generate bidding system message
Use an LLM to create an elaborat... | https://python.langchain.com/en/latest/use_cases/agent_simulations/multiagent_bidding.html |
edf8f83b8c36-1 | Applies the chatmodel to the message history
and returns the message string
"""
message = self.model(
[
self.system_message,
HumanMessage(content="\n".join(self.message_history + [self.prefix])),
]
)
return message.content
... | https://python.langchain.com/en/latest/use_cases/agent_simulations/multiagent_bidding.html |
edf8f83b8c36-2 | self._step += 1
return speaker.name, message
BiddingDialogueAgent class#
We define a subclass of DialogueAgent that has a bid() method that produces a bid given the message history and the most recent message.
class BiddingDialogueAgent(DialogueAgent):
def __init__(
self,
name,
syste... | https://python.langchain.com/en/latest/use_cases/agent_simulations/multiagent_bidding.html |
edf8f83b8c36-3 | HumanMessage(content=
f"""{game_description}
Please reply with a creative description of the presidential candidate, {character_name}, in {word_limit} words or less, that emphasizes their personalities.
Speak directly to {character_name}.
Do not add anything else."""
... | https://python.langchain.com/en/latest/use_cases/agent_simulations/multiagent_bidding.html |
edf8f83b8c36-4 | character_system_messages = [generate_character_system_message(character_name, character_headers) for character_name, character_headers in zip(character_names, character_headers)]
for ... | https://python.langchain.com/en/latest/use_cases/agent_simulations/multiagent_bidding.html |
edf8f83b8c36-5 | You are debating the topic: transcontinental high speed rail.
Your goal is to be as creative as possible and make the voters think you are the best candidate.
You will speak in the style of Donald Trump, and exaggerate their personality.
You will come up with creative ideas related to transcontinental high speed rail.
... | https://python.langchain.com/en/latest/use_cases/agent_simulations/multiagent_bidding.html |
edf8f83b8c36-6 | Your name is Kanye West.
You are a presidential candidate.
Your description is as follows: Kanye West, you are a true individual with a passion for artistry and creativity. You are known for your bold ideas and willingness to take risks. Your determination to break barriers and push boundaries makes you a charismatic a... | https://python.langchain.com/en/latest/use_cases/agent_simulations/multiagent_bidding.html |
edf8f83b8c36-7 | Here is the topic for the presidential debate: transcontinental high speed rail.
The presidential candidates are: Donald Trump, Kanye West, Elizabeth Warren.
Your name is Elizabeth Warren.
You are a presidential candidate.
Your description is as follows: Senator Warren, you are a fearless leader who fights for the litt... | https://python.langchain.com/en/latest/use_cases/agent_simulations/multiagent_bidding.html |
edf8f83b8c36-8 | default_output_key='bid')
Generate bidding system message#
This is inspired by the prompt used in Generative Agents for using an LLM to determine the importance of memories. This will use the formatting instructions from our BidOutputParser.
def generate_character_bidding_template(character_header):
bidding_templat... | https://python.langchain.com/en/latest/use_cases/agent_simulations/multiagent_bidding.html |
edf8f83b8c36-9 | ```
{recent_message}
```
Your response should be an integer delimited by angled brackets, like this: <int>.
Do nothing else.
Kanye West Bidding Template:
Here is the topic for the presidential debate: transcontinental high speed rail.
The presidential candidates are: Donald Trump, Kanye West, Elizabeth Warren.
You... | https://python.langchain.com/en/latest/use_cases/agent_simulations/multiagent_bidding.html |
edf8f83b8c36-10 | ```
{message_history}
```
On the scale of 1 to 10, where 1 is not contradictory and 10 is extremely contradictory, rate how contradictory the following message is to your ideas.
```
{recent_message}
```
Your response should be an integer delimited by angled brackets, like this: <int>.
Do nothing else.
Use an LLM t... | https://python.langchain.com/en/latest/use_cases/agent_simulations/multiagent_bidding.html |
edf8f83b8c36-11 | We will define a ask_for_bid function that uses the bid_parser we defined before to parse the agent’s bid. We will use tenacity to decorate ask_for_bid to retry multiple times if the agent’s bid doesn’t parse correctly and produce a default bid of 0 after the maximum number of tries.
@tenacity.retry(stop=tenacity.stop_... | https://python.langchain.com/en/latest/use_cases/agent_simulations/multiagent_bidding.html |
edf8f83b8c36-12 | print('\n')
return idx
Main Loop#
characters = []
for character_name, character_system_message, bidding_template in zip(character_names, character_system_messages, character_bidding_templates):
characters.append(BiddingDialogueAgent(
name=character_name,
system_message=character_system_message,
... | https://python.langchain.com/en/latest/use_cases/agent_simulations/multiagent_bidding.html |
edf8f83b8c36-13 | Bids:
Donald Trump bid: 2
Kanye West bid: 8
Elizabeth Warren bid: 10
Selected: Elizabeth Warren
(Elizabeth Warren): Thank you for the question. As a fearless leader who fights for the little guy, I believe that building a sustainable and inclusive transcontinental high-speed rail is not only necessary for our econom... | https://python.langchain.com/en/latest/use_cases/agent_simulations/multiagent_bidding.html |
edf8f83b8c36-14 | Bids:
Donald Trump bid: 7
Kanye West bid: 1
Elizabeth Warren bid: 1
Selected: Donald Trump
(Donald Trump): Kanye, you're a great artist, but this is about practicality. Solar power is too expensive and unreliable. We need to focus on what works, and that's clean coal. And as for the design, we'll make it beautiful, ... | https://python.langchain.com/en/latest/use_cases/agent_simulations/multiagent_bidding.html |
edf8f83b8c36-15 | Elizabeth Warren bid: 10
Selected: Elizabeth Warren
(Elizabeth Warren): Thank you, but I disagree. We can't sacrifice the needs of local communities for the sake of speed and profit. We need to find a balance that benefits everyone. And as for profitability, we can't rely solely on private investors. We need to invest ... | https://python.langchain.com/en/latest/use_cases/agent_simulations/multiagent_bidding.html |
edf8f83b8c36-16 | Define the speaker selection function
Main Loop
By Harrison Chase
© Copyright 2023, Harrison Chase.
Last updated on Jun 02, 2023. | https://python.langchain.com/en/latest/use_cases/agent_simulations/multiagent_bidding.html |
3922570d79f0-0 | .ipynb
.pdf
Voice Assistant
Voice Assistant#
This chain creates a clone of ChatGPT with a few modifications to make it a voice assistant.
It uses the pyttsx3 and speech_recognition libraries to convert text to speech and speech to text respectively. The prompt template is also changed to make it more suitable for voice... | https://python.langchain.com/en/latest/use_cases/chatbots/voice_assistant.html |
3922570d79f0-1 | {history}
Human: {human_input}
Assistant:"""
prompt = PromptTemplate(
input_variables=["history", "human_input"],
template=template
)
chatgpt_chain = LLMChain(
llm=OpenAI(temperature=0),
prompt=prompt,
verbose=True,
memory=ConversationBufferWindowMemory(k=2),
)
import speech_recognition as s... | https://python.langchain.com/en/latest/use_cases/chatbots/voice_assistant.html |
3922570d79f0-2 | engine.runAndWait()
listen(None)
Calibrating...
Okay, go!
listening now...
Recognizing...
C:\Users\jaden\AppData\Roaming\Python\Python310\site-packages\tqdm\auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html
from .auton... | https://python.langchain.com/en/latest/use_cases/chatbots/voice_assistant.html |
3922570d79f0-3 | Assistant is aware that human input is being transcribed from audio and as such there may be some errors in the transcription. It will attempt to account for some words being swapped with similar-sounding words or phrases. Assistant will also keep responses concise, because human attention spans are more limited over t... | https://python.langchain.com/en/latest/use_cases/chatbots/voice_assistant.html |
3922570d79f0-4 | Assistant is aware that human input is being transcribed from audio and as such there may be some errors in the transcription. It will attempt to account for some words being swapped with similar-sounding words or phrases. Assistant will also keep responses concise, because human attention spans are more limited over t... | https://python.langchain.com/en/latest/use_cases/chatbots/voice_assistant.html |
3922570d79f0-5 | Overall, Assistant is a powerful tool that can help with a wide range of tasks and provide valuable insights and information on a wide range of topics. Whether you need help with a specific question or just want to have a conversation about a particular topic, Assistant is here to assist.
Assistant is aware that human ... | https://python.langchain.com/en/latest/use_cases/chatbots/voice_assistant.html |
3922570d79f0-6 | Assistant is constantly learning and improving, and its capabilities are constantly evolving. It is able to process and understand large amounts of text, and can use this knowledge to provide accurate and informative responses to a wide range of questions. Additionally, Assistant is able to generate its own text based ... | https://python.langchain.com/en/latest/use_cases/chatbots/voice_assistant.html |
3922570d79f0-7 | Prompt after formatting:
Assistant is a large language model trained by OpenAI.
Assistant is designed to be able to assist with a wide range of tasks, from answering simple questions to providing in-depth explanations and discussions on a wide range of topics. As a language model, Assistant is able to generate human-li... | https://python.langchain.com/en/latest/use_cases/chatbots/voice_assistant.html |
3922570d79f0-8 | Human: I'd like to learn more about neural networks.
AI: Sure! Neural networks are a type of artificial intelligence that use a network of interconnected nodes to process data and make decisions. They are used in a variety of applications, from image recognition to natural language processing. Neural networks are oft... | https://python.langchain.com/en/latest/use_cases/chatbots/voice_assistant.html |
3922570d79f0-9 | Overall, Assistant is a powerful tool that can help with a wide range of tasks and provide valuable insights and information on a wide range of topics. Whether you need help with a specific question or just want to have a conversation about a particular topic, Assistant is here to assist.
Assistant is aware that human ... | https://python.langchain.com/en/latest/use_cases/chatbots/voice_assistant.html |
3922570d79f0-10 | > Entering new LLMChain chain...
Prompt after formatting:
Assistant is a large language model trained by OpenAI.
Assistant is designed to be able to assist with a wide range of tasks, from answering simple questions to providing in-depth explanations and discussions on a wide range of topics. As a language model, Assis... | https://python.langchain.com/en/latest/use_cases/chatbots/voice_assistant.html |
3922570d79f0-11 | Human: Tell me about a brand new discovered bird species.
AI: A new species of bird was recently discovered in the Amazon rainforest. The species, called the Spix's Macaw, is a small, blue parrot that is believed to be extinct in the wild. It is the first new species of bird to be discovered in the Amazon in over 100... | https://python.langchain.com/en/latest/use_cases/chatbots/voice_assistant.html |
3922570d79f0-12 | Assistant is constantly learning and improving, and its capabilities are constantly evolving. It is able to process and understand large amounts of text, and can use this knowledge to provide accurate and informative responses to a wide range of questions. Additionally, Assistant is able to generate its own text based ... | https://python.langchain.com/en/latest/use_cases/chatbots/voice_assistant.html |
3922570d79f0-13 | Human: Tell me a children's story about the importance of honesty and trust.
AI: Once upon a time, there was a young boy named Jack who lived in a small village. Jack was always honest and trustworthy, and his friends and family knew they could always count on him. One day, Jack was walking through the forest when he... | https://python.langchain.com/en/latest/use_cases/chatbots/voice_assistant.html |
3922570d79f0-14 | Overall, Assistant is a powerful tool that can help with a wide range of tasks and provide valuable insights and information on a wide range of topics. Whether you need help with a specific question or just want to have a conversation about a particular topic, Assistant is here to assist.
Assistant is aware that human ... | https://python.langchain.com/en/latest/use_cases/chatbots/voice_assistant.html |
3922570d79f0-15 | > Finished chain.
You're welcome!
listening now...
Recognizing...
Do you know of online brands like Photoshop and Freq that you don't have to download in some sort of way? Do you know of online brands like Photoshop and Freq that you don't have to download in some sort of way?
> Entering new LLMChain chain...
Prompt ... | https://python.langchain.com/en/latest/use_cases/chatbots/voice_assistant.html |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.