Hi, I like to have an agent that can query a SQL database for the required values then run these values through a custom formula. I gave it two tools
sql_database = SQLDatabase(engine, include_tables=table_names)
sql_query_engine = NLSQLTableQueryEngine(sql_database=sql_database)
sql_tool = QueryEngineTool.from_defaults(
query_engine=sql_query_engine,
description=(
"Useful for translating a natural language query into an SQL query over tables containing:"
"exam_scores, containing information about student's grades in an exam. "
# and descriptions of more tables...
),
)
and a custom formula
def alpha(num_unique_subjects: int) -> int:
return num_unique_subjects * num_unique_subjects
alpha_tool = FunctionTool.from_defaults(fn=alpha)
and used a gpt-4 agent
query_engine_tools = [sql_tool, alpha_tool]
agent = OpenAIAgent.from_tools(query_engine_tools, verbose=True)
agent.chat_repl()
However, when I ask the agent to give the alpha value of a particular student, it appear to immediately use the
alpha
formula passing in a hallucinated value for
num_unique_subjects
.
The agent has no problem answering a question on the number of unique subjects for a particular student.
How do you get the agent to do this in 2 steps? First query the SQL database, then pass those values into the alpha FunctionTool?
Thank you