Use FileReadTool from crewai-tools to allow the agent to inspect local documents in summarize.py:
summarize.py
1# summarize.py23from crewai import Agent, Crew, Task
4from crewai_tools import FileReadTool
5from dotenv import load_dotenv
67load_dotenv()89read_file = FileReadTool()1011summarizer = Agent(12 role="Contract summarizer",13 goal="Turn long contracts into short, accurate summaries that cite the section each point comes from",14 backstory=(15"You prepare one-page contract briefs for a finance team. You never "16"guess: every point in your brief comes from the contract text, with "17"its section number."18),19 tools=[read_file],20 verbose=True,21)2223summarize_contract = Task(24 description=(25"Read the contract at {contract_path} and summarize it for the customer. "26"Cover the term and renewal, fees and payment, service levels, data, "27"termination, and liability."28),29 expected_output="A bulleted summary with one bullet per topic. Each bullet ends with its section number, like (Section 2.2).",30 agent=summarizer,31)3233crew = Crew(agents=[summarizer], tasks=[summarize_contract], verbose=True)3435if __name__ =="__main__":36 result = crew.kickoff(inputs={"contract_path":"contracts/acme-saas-agreement.md"})37print(result.raw)
Key implementation points:
Tool assignment: Passing read_file to tools=[read_file] grants the agent permission to invoke the file reader.
Autonomous execution: The task specifies the target path {contract_path}; the agent decides when and how to call the tool.
Citation enforcement: The expected_output requires section numbers for every bullet, ensuring full auditability.
Run the script:
Terminal
1(env)$ python summarize.py
The execution log displays a tool execution step calling read_a_files_content, followed by the structured summary:
Output
...### Data- Customer owns all data uploaded to the Service (Section 5.1).- Provider may only use Customer Data to provide the Service (Section 5.2).- After termination, Customer may export data for 30 days; Provider will delete it within 90 days of export completion (Section 5.3).
Compare the data bullet with Section 5.3 of the contract:
Contract text: Data deletion occurs within 90 days after the 30-day export period ends (120 days total).
Agent summary: Data deletion occurs within 90 days of export completion.
While subtle, the summary misstates the customer's legal retention window. A single agent drafting a summary rarely catches its own omissions. The next chapter introduces a multi-agent review team to verify claims independently.