You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Good morning,
First of all, thank you for your effort in creating this amazing library.
I would like to have more information about the use of Modules in DSPy.
In particular, I would like to use DSPy to create agents that can communicate with each other in an automated manner.
Let's take as an example my first attempt to create two agents that communicate with each other to discuss a topic (P.S. I am still new to DSPy. All suggestions are welcome :) ):
fromtypingimportListimportos, dspylm=dspy.LM('openai/gpt-4o-mini', api_key=os.environ['OPENAI_API_KEY'], cache=False)
dspy.configure(lm=lm)
classComment(dspy.Signature):
"""You are partecipating in a conversation. Comment on the given topic and on previous messages. Speak directly to the participants"""name=dspy.InputField(format=str, desc="Your name in the conversation")
participants=dspy.InputField(format=List[str], desc="The participants in the conversation, excluding yourself")
previous_messages=dspy.InputField(format=List[str], desc="The previous messages in the conversation")
opinion=dspy.OutputField(format=str, desc="Your opinion.")
classAgent(dspy.Module):
def__init__(self, name):
self.name=nameself.last_message=Noneself.comment=dspy.Predict(Comment)
defforward(self, previous_messages: List[str]) ->List[str]:
participants=set()
formessageinprevious_messages:
name=message.split(":")[0]
ifname!=self.nameandname!="Topic":
participants.add(name)
result=self.comment(name=self.name, participants=participants, previous_messages=previous_messages)
self.last_message=result.opinionopinion=f"{self.name}: {result.opinion}"returndspy.Prediction(opinion=opinion)
messages= [] # The messages in the conversationtopic='''Best programming language for beginners'''messages.append(f"Topic: {topic}")
agent_1=Agent('Bob')
agent_2=Agent('Alice')
print(f"Topic: {topic}")
foriinrange(3):
# Bob turnlast_message=agent_1(messages).opinionmessages.append(last_message)
print(f"- {last_message}")
# Alice turnlast_message=agent_2(messages).opinionprint(f"- {last_message}")
messages.append(last_message)
print("---------------------- HISTORY ---------------------------")
print(lm.inspect_history(n=1000))
Questions:
Is the above example a proper use of the Module class in an agent-based context? Based on what I have understood from the documentation, a module would be a class that contains more details, going beyond a single call to the LLM. So, in an agent-based context, the module would be used to save information such as "memory," "maximum number of iterations," "possible function calls," "tools," etc. Did I understand correctly?
Is it always necessary to encapsulate interactions between multiple agents in the same module? For example, in the example above, should I place the two agents within the same module if I later want to take advantage of prompt fine-tuning? I don't know if DSPy automatically understands that the Python program (which involves multiple separate modules) needs to be optimized separately across multiple modules or if it requires everything to be in a single module.
Extra question: How does memory management work in DSPy? I saw that lm.history maintains a list of API calls to the selected LLM. Does this history have an impact on future calls (is it used as context) or is it just for logging purposes? And is it possible to return all the logs without having to specify a predefined number?
The text was updated successfully, but these errors were encountered:
Good morning,
First of all, thank you for your effort in creating this amazing library.
I would like to have more information about the use of Modules in DSPy.
In particular, I would like to use DSPy to create agents that can communicate with each other in an automated manner.
Let's take as an example my first attempt to create two agents that communicate with each other to discuss a topic (P.S. I am still new to DSPy. All suggestions are welcome :) ):
Questions:
Is the above example a proper use of the Module class in an agent-based context? Based on what I have understood from the documentation, a module would be a class that contains more details, going beyond a single call to the LLM. So, in an agent-based context, the module would be used to save information such as "memory," "maximum number of iterations," "possible function calls," "tools," etc. Did I understand correctly?
Is it always necessary to encapsulate interactions between multiple agents in the same module? For example, in the example above, should I place the two agents within the same module if I later want to take advantage of prompt fine-tuning? I don't know if DSPy automatically understands that the Python program (which involves multiple separate modules) needs to be optimized separately across multiple modules or if it requires everything to be in a single module.
Extra question: How does memory management work in DSPy? I saw that lm.history maintains a list of API calls to the selected LLM. Does this history have an impact on future calls (is it used as context) or is it just for logging purposes? And is it possible to return all the logs without having to specify a predefined number?
The text was updated successfully, but these errors were encountered: