Hello all, I have created an ReAct agent and given some tools to it. Now I will like to include a parser such that the response is always just a python dictionary instead of a sentence. Does anyone know how can I do that?
ReActAgent.from_tools
has a
output_parser
argument however I had no luck with it.
This is current set up and I will be adding on more tools to extract more data:
recursive_query_engine = recursive_index.as_query_engine(
similarity_top_k=5,
node_postprocessors=[reranker],
verbose=True
)
class DocumentTypeResponse(BaseModel):
"""Data model for the document type"""
document_type: str
document_type_identifier = QueryEngineTool(
query_engine=recursive_query_engine,
metadata=ToolMetadata(
name='document_type',
description=(
"Only use this tool when required. "
"Answer to question relating to document type. "
"Identify document types as either purchase order or invoice. "
),
fn_schema=DocumentTypeResponse
)
)
context_document_agent = """\
You are an expert administraive assistant who specialized in answering questions about document.
The questions mainly revolves around extracting key information from either an invoice or purchase order.
Only use the necessary tool to answer the questions. Only use more tools when needed.
"""
document_agent = ReActAgent.from_tools(
tools=document_type_identifier,
verbose=True,
context=context_document_agent,
)