classGenerativeAgent(BaseModel):"""A character with memory and innate characteristics."""
このクラスは以下のパラメータを持っており、これがキャラクターの振る舞いや言動に影響を与えます。
実際に利用する際は以下のように呼び出します。
tommie = GenerativeAgent(
name="Tommie",
age=25,
traits="anxious, likes design",
status="looking for a job",
memory_retriever=create_new_memory_retriever(),
llm=LLM,
daily_summaries=[
"Drove across state to move to a new town but doesn't have a job yet."
],
reflection_threshold=8,
)
tommie_memories = [
"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 memory in tommie_memories:
tommie.add_memory(memory)
definterview_agent(agent: GenerativeAgent, message: str) -> str:"""Help the notebook user interact with the agent."""
new_message = f"{USER_NAME} says {message}"return agent.generate_dialogue_response(new_message)[1]
interview_agent(tommie, "What do you like to do?")
interview_agent(tommie, "What are you looking forward to doing today?")
eve = GenerativeAgent(
name="Eve",
age=34,
traits="curious, helpful",
status="N/A",
memory_retriever=create_new_memory_retriever(),
llm=LLM,
daily_summaries=[
("Eve started her new job as a career counselor last week and received her first assignment, a client named Tommie.")
],
reflection_threshold=5,
)
イヴにも記憶の初期値を設定します。
eve_memories = [
"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 colleague say something about Tommie being hard to work with",
]
for memory in eve_memories:
eve.add_memory(memory)
イヴの現在の状況を見てみましょう。
print(eve.get_summary())
イヴに対し、天の声によってトミーが休職しているという情報を与えます。
interview_agent(eve, "How are you feeling about today?")
interview_agent(eve, "What do you know about Tommie?")
interview_agent(eve, "Tommie is looking to find a job. What are are some things you'd like to ask him?")
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.")
agents = [tommie, eve]
run_conversation(agents, "Tommie said: Hi, Eve. Thanks for agreeing to share your story with me and give me advice. I have a bunch of questions.")