Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I pass retriever as a tool for a ReAct agent #1144

Closed
ArslanS1997 opened this issue Jun 13, 2024 · 1 comment
Closed

How do I pass retriever as a tool for a ReAct agent #1144

ArslanS1997 opened this issue Jun 13, 2024 · 1 comment

Comments

@ArslanS1997
Copy link

ArslanS1997 commented Jun 13, 2024

Hi I am building an agent that does data visualizations.

It has two tools at its disposal one which retrieves information about the relevant column_names and the column's min/max ranges
the other tool has instructions on how style the graph, like for a line graph I need this etc. I have been able to make this structure, where I am using llama index retrievers. Here is the signature and module code, when I ask it a query it does not give Plotly code at all

class AgentSig(dspy.Signature):
    """
    You are AI agent who uses the query to generate data visualizations in Plotly.
    You have to find the relevant column_names and data from the dataframe_index
    You have to use styling information from styling_index to make the chart aesthetically pleasing
    
    """

    dataframe_context = dspy.InputField(desc=" Provides information about the data in the data frame in json. Only use column names in this context")
    styling_context = dspy.InputField(desc='Provides instructions on how to style your Plotly plots')
    query = dspy.InputField(desc="user query which includes information about data and chart they want to plot")
    code = dspy.OutputField(desc="Plotly code that visualizes what the user needs according to the query")
class AI_data_viz_agent(dspy.Module):
    def __init__(self):
        super().__init__()

        self.dataframe_index = dataframe_index
        self.style_index = style_index
        self.agent = dspy.ReAct(AgentSig)
    
    def forward(self, query):
        dataframe_context = self.dataframe_index.as_retriever(similarity_top_k=1).retrieve(query)[0].text
        # print(dataframe_context)
        styling_context = self.style_index.as_retriever(similarity_top_k=1).retrieve(query)[0].text
        # print(styling_context)
        prediction = self.agent(dataframe_context=dataframe_context,styling_context=styling_context,query=query)
        # return prediction
        return dspy.Prediction(dataframe_context=dataframe_context,styling_context=styling_context,code=prediction.code)
@tom-doerr
Copy link
Contributor

Like this:

agent = dspy.ReAct("question -> answer", tools=[dspy.Retrieve(k=1)])

Notebook on ReAct: https://github.com/stanfordnlp/dspy/blob/main/examples/agents/multi_agent.ipynb
Documentation: https://dspy-docs.vercel.app/api/modules/ReAct

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants