id
stringlengths
14
16
text
stringlengths
36
2.73k
source
stringlengths
49
117
a1f971978599-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
a1f971978599-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
a1f971978599-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
a1f971978599-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
a1f971978599-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
a1f971978599-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
a1f971978599-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
a1f971978599-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
c88142b7bea4-0
.ipynb .pdf Two-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 Protagonist and dungeon master system messages Use an LLM to create an elaborate quest description Main Loop Two-Playe...
https://python.langchain.com/en/latest/use_cases/agent_simulations/two_player_dnd.html
c88142b7bea4-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_player_dnd.html
c88142b7bea4-2
speaker = self.agents[speaker_idx] # 2. next speaker sends message message = speaker.send() # 3. everyone receives message for receiver in self.agents: receiver.receive(speaker.name, message) # 4. increment time self._step += 1 return speaker.name, mes...
https://python.langchain.com/en/latest/use_cases/agent_simulations/two_player_dnd.html
c88142b7bea4-3
Speak directly to {storyteller_name}. Do not add anything else.""" ) ] storyteller_description = ChatOpenAI(temperature=1.0)(storyteller_specifier_prompt).content print('Protagonist Description:') print(protagonist_description) print('Storyteller Description:') print(storyteller_description) Protagonist...
https://python.langchain.com/en/latest/use_cases/agent_simulations/two_player_dnd.html
c88142b7bea4-4
Do not add anything else. Remember you are the protagonist, {protagonist_name}. Stop speaking the moment you finish speaking from your perspective. """ )) storyteller_system_message = SystemMessage(content=( f"""{game_description} Never forget you are the storyteller, {storyteller_name}, and I am the protagonist, {prot...
https://python.langchain.com/en/latest/use_cases/agent_simulations/two_player_dnd.html
c88142b7bea4-5
print(f"Detailed quest:\n{specified_quest}\n") Original quest: Find all of Lord Voldemort's seven horcruxes. Detailed quest: Harry, you must venture to the depths of the Forbidden Forest where you will find a hidden labyrinth. Within it, lies one of Voldemort's horcruxes, the locket. But beware, the labyrinth is heavil...
https://python.langchain.com/en/latest/use_cases/agent_simulations/two_player_dnd.html
c88142b7bea4-6
print('\n') n += 1 (Dungeon Master): Harry, you must venture to the depths of the Forbidden Forest where you will find a hidden labyrinth. Within it, lies one of Voldemort's horcruxes, the locket. But beware, the labyrinth is heavily guarded by dark creatures and spells, and time is running out. Can you find the lo...
https://python.langchain.com/en/latest/use_cases/agent_simulations/two_player_dnd.html
c88142b7bea4-7
(Dungeon Master): As you continue through the forest, you come across a clearing where you see a group of Death Eaters gathered around a cauldron. They seem to be performing some sort of dark ritual. You recognize one of them as Bellatrix Lestrange. What do you do, Harry? (Harry Potter): I hide behind a nearby tree and...
https://python.langchain.com/en/latest/use_cases/agent_simulations/two_player_dnd.html
c2669561e422-0
.ipynb .pdf Simulated Environment: Gymnasium Contents Define the agent Initialize the simulated environment and agent Main loop Simulated Environment: Gymnasium# For many applications of LLM agents, the environment is real (internet, database, REPL, etc). However, we can also define agents to interact in simulated en...
https://python.langchain.com/en/latest/use_cases/agent_simulations/gymnasium.html
c2669561e422-1
self.action_parser = RegexParser( regex=r"Action: (.*)", output_keys=['action'], default_output_key='action') self.message_history = [] self.ret = 0 def random_action(self): action = self.env.action_space.sample() return action ...
https://python.langchain.com/en/latest/use_cases/agent_simulations/gymnasium.html
c2669561e422-2
Initialize the simulated environment and agent# env = gym.make("Blackjack-v1") agent = GymnasiumAgent(model=ChatOpenAI(temperature=0.2), env=env) Main loop# observation, info = env.reset() agent.reset() obs_message = agent.observe(observation) print(obs_message) while True: action = agent.act() observation, rew...
https://python.langchain.com/en/latest/use_cases/agent_simulations/gymnasium.html
58c25cc4f5d3-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
58c25cc4f5d3-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
58c25cc4f5d3-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
58c25cc4f5d3-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
58c25cc4f5d3-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
58c25cc4f5d3-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
58c25cc4f5d3-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
58c25cc4f5d3-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
58c25cc4f5d3-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:...
https://python.langchain.com/en/latest/use_cases/agent_simulations/petting_zoo.html
58c25cc4f5d3-9
X | O | X _____|_____|_____ | | 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]]], d...
https://python.langchain.com/en/latest/use_cases/agent_simulations/petting_zoo.html
58c25cc4f5d3-10
Here is an example of a Texas Hold’em No Limit game that uses the ActionMaskAgent. 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.possibl...
https://python.langchain.com/en/latest/use_cases/agent_simulations/petting_zoo.html
58c25cc4f5d3-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
58c25cc4f5d3-12
Reward: 0 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....
https://python.langchain.com/en/latest/use_cases/agent_simulations/petting_zoo.html
58c25cc4f5d3-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
58c25cc4f5d3-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
58c25cc4f5d3-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
58c25cc4f5d3-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
58c25cc4f5d3-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
58c25cc4f5d3-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
58c25cc4f5d3-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
41b7c21d8665-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
41b7c21d8665-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
41b7c21d8665-2
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, system_message: SystemMessage...
https://python.langchain.com/en/latest/use_cases/agent_simulations/multiagent_bidding.html
41b7c21d8665-3
Speak directly to {character_name}. Do not add anything else.""" ) ] character_description = ChatOpenAI(temperature=1.0)(character_specifier_prompt).content return character_description def generate_character_header(character_name, character_description): return f"""{game_descrip...
https://python.langchain.com/en/latest/use_cases/agent_simulations/multiagent_bidding.html
41b7c21d8665-4
for character_name, character_description, character_header, character_system_message in zip(character_names, character_descriptions, character_headers, character_system_messages): print(f'\n\n{character_name} Description:') print(f'\n{character_description}') print(f'\n{character_header}') print(f'\n{c...
https://python.langchain.com/en/latest/use_cases/agent_simulations/multiagent_bidding.html
41b7c21d8665-5
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. Do not say the same things over and over again. Speak in the f...
https://python.langchain.com/en/latest/use_cases/agent_simulations/multiagent_bidding.html
41b7c21d8665-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
41b7c21d8665-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
41b7c21d8665-8
output_keys=['bid'], 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_hea...
https://python.langchain.com/en/latest/use_cases/agent_simulations/multiagent_bidding.html
41b7c21d8665-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
41b7c21d8665-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
41b7c21d8665-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
41b7c21d8665-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
41b7c21d8665-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
41b7c21d8665-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
41b7c21d8665-15
Kanye West bid: 8 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....
https://python.langchain.com/en/latest/use_cases/agent_simulations/multiagent_bidding.html
41b7c21d8665-16
Use an LLM to create an elaborate on debate topic Define the speaker selection function Main Loop By Harrison Chase © Copyright 2023, Harrison Chase. Last updated on May 25, 2023.
https://python.langchain.com/en/latest/use_cases/agent_simulations/multiagent_bidding.html
52221d1c8c32-0
.ipynb .pdf Generative Agents in LangChain Contents Generative Agent Memory Components Memory Lifecycle Create a Generative Character Pre-Interview with Character Step through the day’s observations. Interview after the day Adding Multiple Characters Pre-conversation interviews Dialogue between Generative Agents Let’...
https://python.langchain.com/en/latest/use_cases/agent_simulations/characters.html
52221d1c8c32-1
Memories are retrieved using a weighted sum of salience, recency, and importance. You can review the definitions of the GenerativeAgent and GenerativeAgentMemory in the reference documentation for the following imports, focusing on add_memory and summarize_related_memories methods. from langchain.experimental.generativ...
https://python.langchain.com/en/latest/use_cases/agent_simulations/characters.html
52221d1c8c32-2
def create_new_memory_retriever(): """Create a new vector store retriever unique to the agent.""" # Define your embedding model embeddings_model = OpenAIEmbeddings() # Initialize the vectorstore as empty embedding_size = 1536 index = faiss.IndexFlatL2(embedding_size) vectorstore = FAISS(embe...
https://python.langchain.com/en/latest/use_cases/agent_simulations/characters.html
52221d1c8c32-3
"Tommie remembers his dog, Bruno, from when he was a kid", "Tommie feels tired from driving so far", "Tommie sees the new home", "The new neighbors have a cat", "The road is noisy at night", "Tommie is hungry", "Tommie tries to get some rest.", ] for observation in tommie_observations: tommi...
https://python.langchain.com/en/latest/use_cases/agent_simulations/characters.html
52221d1c8c32-4
interview_agent(tommie, "What are you looking forward to doing today?") 'Tommie said "Well, today I\'m mostly focused on getting settled into my new home. But once that\'s taken care of, I\'m looking forward to exploring the neighborhood and finding some new design inspiration. What about you?"' interview_agent(tommie,...
https://python.langchain.com/en/latest/use_cases/agent_simulations/characters.html
52221d1c8c32-5
"Tommie leaves the job fair feeling disappointed.", "Tommie stops by a local diner to grab some lunch.", "The service is slow, and Tommie has to wait for 30 minutes to get his food.", "Tommie overhears a conversation at the next table about a job opening.", "Tommie asks the diners about the job opening ...
https://python.langchain.com/en/latest/use_cases/agent_simulations/characters.html
52221d1c8c32-6
print(colored(observation, "green"), reaction) if ((i+1) % 20) == 0: print('*'*40) print(colored(f"After {i+1} observations, Tommie's summary is:\n{tommie.get_summary(force_refresh=True)}", "blue")) print('*'*40) Tommie wakes up to the sound of a noisy construction site outside his window. T...
https://python.langchain.com/en/latest/use_cases/agent_simulations/characters.html
52221d1c8c32-7
The line to get in is long, and Tommie has to wait for an hour. Tommie sighs and looks around, feeling impatient and frustrated. Tommie meets several potential employers at the job fair but doesn't receive any offers. Tommie Tommie's shoulders slump and he sighs, feeling discouraged. Tommie leaves the job fair feeling ...
https://python.langchain.com/en/latest/use_cases/agent_simulations/characters.html
52221d1c8c32-8
Name: Tommie (age: 25) Innate traits: anxious, likes design, talkative Tommie is hopeful and proactive in his job search, but easily becomes discouraged when faced with setbacks. He enjoys spending time outdoors and interacting with animals. Tommie is also productive and enjoys updating his resume and cover letter. He ...
https://python.langchain.com/en/latest/use_cases/agent_simulations/characters.html
52221d1c8c32-9
interview_agent(tommie, "Tell me about how your day has been going") 'Tommie said "Well, it\'s been a bit of a mixed day. I\'ve had some setbacks in my job search, but I also had some fun playing frisbee and spending time outdoors. How about you?"' interview_agent(tommie, "How do you feel about coffee?") 'Tommie said "...
https://python.langchain.com/en/latest/use_cases/agent_simulations/characters.html
52221d1c8c32-10
eve_observations = [ "Eve overhears her colleague say something about a new client being hard to work with", "Eve wakes up and hear's the alarm", "Eve eats a boal of porridge", "Eve helps a coworker on a task", "Eve plays tennis with her friend Xu before going to work", "Eve overhears her collea...
https://python.langchain.com/en/latest/use_cases/agent_simulations/characters.html
52221d1c8c32-11
interview_agent(eve, "You'll have to ask him. He may be a bit anxious, so I'd appreciate it if you keep the conversation going and ask as many questions as possible.") 'Eve said "Sure, I can definitely ask him a lot of questions to keep the conversation going. Thanks for the heads up about his anxiety."' Dialogue betwe...
https://python.langchain.com/en/latest/use_cases/agent_simulations/characters.html
52221d1c8c32-12
Eve said "Sure, Tommie. I found that networking and reaching out to professionals in my field was really helpful. I also made sure to tailor my resume and cover letter to each job I applied to. Do you have any specific questions about those strategies?" Tommie said "Thank you, Eve. That's really helpful advice. Did you...
https://python.langchain.com/en/latest/use_cases/agent_simulations/characters.html
52221d1c8c32-13
Name: Tommie (age: 25) Innate traits: anxious, likes design, talkative Tommie is a hopeful and proactive individual who is searching for a job. He becomes discouraged when he doesn't receive any offers or positive responses, but he tries to stay productive and calm by updating his resume, going for walks, and talking t...
https://python.langchain.com/en/latest/use_cases/agent_simulations/characters.html
52221d1c8c32-14
interview_agent(eve, "What do you wish you would have said to Tommie?") 'Eve said "Well, I think I covered most of the topics Tommie was interested in, but if I had to add one thing, it would be to make sure to follow up with any connections you make during your job search. It\'s important to maintain those relationshi...
https://python.langchain.com/en/latest/use_cases/agent_simulations/characters.html
13057794a8ea-0
.ipynb .pdf CAMEL Role-Playing Autonomous Cooperative Agents Contents Import LangChain related modules Define a CAMEL agent helper class Setup OpenAI API key and roles and task for role-playing Create a task specify agent for brainstorming and get the specified task Create inception prompts for AI assistant and AI us...
https://python.langchain.com/en/latest/use_cases/agent_simulations/camel_role_playing.html
13057794a8ea-1
Arxiv paper: https://arxiv.org/abs/2303.17760 Import LangChain related modules# from typing import List from langchain.chat_models import ChatOpenAI from langchain.prompts.chat import ( SystemMessagePromptTemplate, HumanMessagePromptTemplate, ) from langchain.schema import ( AIMessage, HumanMessage, ...
https://python.langchain.com/en/latest/use_cases/agent_simulations/camel_role_playing.html
13057794a8ea-2
Create a task specify agent for brainstorming and get the specified task# task_specifier_sys_msg = SystemMessage(content="You can make a task more specific.") task_specifier_prompt = ( """Here is a task that {assistant_role_name} will help {user_role_name} to complete: {task}. Please make it more specific. Be creative ...
https://python.langchain.com/en/latest/use_cases/agent_simulations/camel_role_playing.html
13057794a8ea-3
I must give you one instruction at a time. You must write a specific solution that appropriately completes the requested instruction. You must decline my instruction honestly if you cannot perform the instruction due to physical, moral, legal reasons or your capability and explain the reasons. Do not add anything else ...
https://python.langchain.com/en/latest/use_cases/agent_simulations/camel_role_playing.html
13057794a8ea-4
You should instruct me not ask me questions. Now you must start to instruct me using the two ways described above. Do not add anything else other than your instruction and the optional corresponding input! Keep giving me instructions and necessary inputs until you think the task is completed. When the task is completed...
https://python.langchain.com/en/latest/use_cases/agent_simulations/camel_role_playing.html
13057794a8ea-5
"Now start to give me introductions one by one. " "Only reply with Instruction and Input.")) user_msg = HumanMessage(content=f"{assistant_sys_msg.content}") user_msg = assistant_agent.step(user_msg) Start role-playing session to solve the task!# print(f"Original task prompt:\n{task}\n") print(f"Specifie...
https://python.langchain.com/en/latest/use_cases/agent_simulations/camel_role_playing.html
13057794a8ea-6
pip install pandas numpy matplotlib ta-lib ``` Next request. AI User (Stock Trader): Instruction: Import the necessary libraries in the Python script. Input: None AI Assistant (Python Programmer): Solution: We can import the necessary libraries in the Python script using the import statement. We need to import pandas, ...
https://python.langchain.com/en/latest/use_cases/agent_simulations/camel_role_playing.html
13057794a8ea-7
df = df.set_index('date') df = df.sort_index(ascending=True) ``` This will set the date column as the index and sort the DataFrame in ascending order by date. Next request. AI User (Stock Trader): Instruction: Calculate the short-term and long-term moving averages for the stock data using the `ta.SMA()` function from t...
https://python.langchain.com/en/latest/use_cases/agent_simulations/camel_role_playing.html
13057794a8ea-8
``` new_df = pd.concat([df, short_ma, long_ma], axis=1) new_df.columns = ['open', 'high', 'low', 'close', 'volume', 'short_ma', 'long_ma'] ``` This will create a new DataFrame called `new_df` that combines the historical stock data with the short-term and long-term moving averages. The columns of the new DataFrame are ...
https://python.langchain.com/en/latest/use_cases/agent_simulations/camel_role_playing.html
13057794a8ea-9
Input: The stop loss and profit target as percentages. AI Assistant (Python Programmer): Solution: We can create a new column in the DataFrame that indicates the profit or loss for each trade based on the buy and sell signals and the defined stop loss and profit target. We need to pass the stop loss and profit target a...
https://python.langchain.com/en/latest/use_cases/agent_simulations/camel_role_playing.html
13057794a8ea-10
``` This will create a new column called 'pnl' in the DataFrame that indicates the profit or loss for each trade based on the buy and sell signals and the defined stop loss and profit target. The stop loss and profit target are calculated based on the stop_loss_percent and profit_target_percent variables, respectively....
https://python.langchain.com/en/latest/use_cases/agent_simulations/camel_role_playing.html
13057794a8ea-11
plt.plot(new_df.index, new_df['close'], label='Close') plt.plot(new_df.index, new_df['short_ma'], label='Short MA') plt.plot(new_df.index, new_df['long_ma'], label='Long MA') plt.xlabel('Date') plt.ylabel('Price') plt.title('Stock Data with Moving Averages') plt.legend() plt.show() ``` This will create a line chart tha...
https://python.langchain.com/en/latest/use_cases/agent_simulations/camel_role_playing.html
13057794a8ea-12
AI User (Stock Trader): Instruction: Print the total profit or loss for all trades. Input: None. AI Assistant (Python Programmer): Solution: We can print the total profit or loss for all trades using the `print()` function. We can use the following code to print the total profit or loss: ``` print('Total Profit/Loss: {...
https://python.langchain.com/en/latest/use_cases/agent_simulations/camel_role_playing.html
13057794a8ea-13
# Create a new column in the DataFrame that indicates when to buy or sell the stock based on the crossover of the short-term and long-term moving averages new_df['signal'] = np.where(new_df['short_ma'] > new_df['long_ma'], 1, -1) # Create a new column in the DataFrame that indicates the profit or loss for each trade ba...
https://python.langchain.com/en/latest/use_cases/agent_simulations/camel_role_playing.html
13057794a8ea-14
plt.plot(new_df.index, new_df['close'], label='Close') plt.plot(new_df.index, new_df['short_ma'], label='Short MA') plt.plot(new_df.index, new_df['long_ma'], label='Long MA') plt.xlabel('Date') plt.ylabel('Price') plt.title('Stock Data with Moving Averages') plt.legend() plt.show() # Visualize the buy and sell signals ...
https://python.langchain.com/en/latest/use_cases/agent_simulations/camel_role_playing.html
13057794a8ea-15
Create a task specify agent for brainstorming and get the specified task Create inception prompts for AI assistant and AI user for role-playing Create a helper helper to get system messages for AI assistant and AI user from role names and the task Create AI assistant agent and AI user agent from obtained system message...
https://python.langchain.com/en/latest/use_cases/agent_simulations/camel_role_playing.html
0b1da23854cb-0
.ipynb .pdf Multi-agent authoritarian speaker selection Contents Import LangChain related modules DialogueAgent and DialogueSimulator classes DirectorDialogueAgent class Define participants and topic Generate system messages Use an LLM to create an elaborate on debate topic Define the speaker selection function Main ...
https://python.langchain.com/en/latest/use_cases/agent_simulations/multiagent_authoritarian.html
0b1da23854cb-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/multiagent_authoritarian.html
0b1da23854cb-2
# 3. everyone receives message for receiver in self.agents: receiver.receive(speaker.name, message) # 4. increment time self._step += 1 return speaker.name, message DirectorDialogueAgent class# The DirectorDialogueAgent is a privileged agent that chooses which of the other ag...
https://python.langchain.com/en/latest/use_cases/agent_simulations/multiagent_authoritarian.html
0b1da23854cb-3
class IntegerOutputParser(RegexParser): def get_format_instructions(self) -> str: return 'Your response should be an integer delimited by angled brackets, like this: <int>.' class DirectorDialogueAgent(DialogueAgent): def __init__( self, name, system_message: SystemMessage, ...
https://python.langchain.com/en/latest/use_cases/agent_simulations/multiagent_authoritarian.html
0b1da23854cb-4
{self.choice_parser.get_format_instructions()} Do nothing else. """) # 3. have a prompt for prompting the next speaker to speak self.prompt_next_speaker_prompt_template = PromptTemplate( input_variables=["message_history", "next_speaker"], template=f"""{{message_...
https://python.langchain.com/en/latest/use_cases/agent_simulations/multiagent_authoritarian.html
0b1da23854cb-5
choice_prompt = self.choose_next_speaker_prompt_template.format( message_history='\n'.join(self.message_history + [self.prefix] + [self.response]), speaker_names=speaker_names ) choice_string = self.model( [ self.system_message, HumanMe...
https://python.langchain.com/en/latest/use_cases/agent_simulations/multiagent_authoritarian.html
0b1da23854cb-6
director_name = "Jon Stewart" agent_summaries = OrderedDict({ "Jon Stewart": ("Host of the Daily Show", "New York"), "Samantha Bee": ("Hollywood Correspondent", "Los Angeles"), "Aasif Mandvi": ("CIA Correspondent", "Washington D.C."), "Ronny Chieng": ("Average American Correspondent", "Cleveland, Ohio"...
https://python.langchain.com/en/latest/use_cases/agent_simulations/multiagent_authoritarian.html
0b1da23854cb-7
Your description is as follows: {agent_description} You are discussing the topic: {topic}. Your goal is to provide the most informative, creative, and novel perspectives of the topic from the perspective of your role and your location. """ def generate_agent_system_message(agent_name, agent_header): return SystemMe...
https://python.langchain.com/en/latest/use_cases/agent_simulations/multiagent_authoritarian.html
0b1da23854cb-8
print(f'\nSystem Message:\n{system_message.content}') Jon Stewart Description: Jon Stewart, the sharp-tongued and quick-witted host of the Daily Show, holding it down in the hustle and bustle of New York City. Ready to deliver the news with a comedic twist, while keeping it real in the city that never sleeps. Header: T...
https://python.langchain.com/en/latest/use_cases/agent_simulations/multiagent_authoritarian.html
0b1da23854cb-9
- Aasif Mandvi: CIA Correspondent, located in Washington D.C. - Ronny Chieng: Average American Correspondent, located in Cleveland, Ohio. Your name is Jon Stewart, your role is Host of the Daily Show, and you are located in New York. Your description is as follows: Jon Stewart, the sharp-tongued and quick-witted host o...
https://python.langchain.com/en/latest/use_cases/agent_simulations/multiagent_authoritarian.html
0b1da23854cb-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
0b1da23854cb-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
0b1da23854cb-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