What the agent does
This is for a company that sells software to small residential property managers: a firm looking after 200 flats for private landlords, a family business with a few dozen houses, a manager of student lets. The software handles rent and maintenance, but many of its customers keep the signed leases where they always have, as PDFs and Word files in a Leases folder in OneDrive, one subfolder per property. The dates that matter live inside those files: when each tenancy ends, and how much notice the lease asks for before it does. A manager who finds out in week three of the last month that a lease ends has lost the chance to offer a renewal, raise the rent on time or market the unit early. The software adds a monthly renewals list built from each customer's own leases.
The company saves the agent once as a template with POST /o/{org}/agents, naming onedrive in connections, after connecting a OneDrive of its own. When a customer turns renewals on, the backend calls POST /o/{org}/agents {"template": "<template id>", "name": "renewals-<customer id>"}, then POST /o/{org}/agents/{agent}/connections {"type": "app", "name": "onedrive"}, and opens the authorize_url in a popup while the manager is signed in to the software. The manager signs in on Microsoft's own page; the software also asks for the path of their leases folder and passes it in each run's prompt. The OneDrive sign-in asks Microsoft for Files.ReadWrite.All, which can change files, so the template's instructions forbid writing, moving or deleting anything, and the software says so on its connect screen.
On a run the agent lists the leases folder with GET /me/drive/root:/{path}:/children, walking each property subfolder and following @odata.nextLink when a folder has more items than one page. It keeps PDF and Word files whose lastModifiedDateTime is after the date of the last run the prompt gives, plus any file the previous result could not read, and downloads each with GET /me/drive/items/{item-id}/content. Microsoft's docs say that call answers with a redirect to a short-lived download URL, so the agent follows it at once. A manager who also files leases elsewhere can have the agent run GET /me/drive/root/search(q='lease'), which Microsoft's docs say matches file names, metadata and content.
From each lease it reads the property and unit, the tenants' names as written, the start and end dates, the rent and the notice clause, quoted word for word with its page number. It then combines what it read this month with the software's stored list from last month, which the prompt passes in, and lists every tenancy whose end date falls in the next 90 days, soonest first, with the date by which notice is due under the quoted clause. A scanned lease it cannot read, or one with no end date such as a rolling tenancy, goes on a separate list for a person to look at.
Start it with one API call
POST https://api.phoenix.so/o/{org}/sessions with this body:
{
"agent": "<agent id>",
"input": "Monthly lease renewals for this customer. Today: 2026-12-01. Leases folder: /Leases (one subfolder per property). Last run: 2026-11-01. Previous result is attached as the JSON below; re-read only files changed since the last run, and any file listed in its unreadable list. Read only. 1) List /Leases and each subfolder with GET /me/drive/root:/Leases:/children (and the subfolders' children), following @odata.nextLink. 2) For each PDF or Word file with lastModifiedDateTime after 2026-11-01, download it with GET /me/drive/items/{item-id}/content. 3) From each lease extract: property, unit, tenant names as written, start date, end date, monthly rent, and the notice clause quoted exactly with its page number. If two files are versions of the same lease, keep the most recently signed and note the other. 4) Merge with the previous result. 5) Return JSON only: {as_of, ending_within_90_days: [{property, unit, tenants, end_date, days_left, notice_clause, notice_page, notice_due_by, file_url}], unreadable: [{file_url, reason}], leases: [all leases with the fields above]}. Work out notice_due_by only from the quoted clause and say 'unclear' when the clause does not give a period. Do not write, rename, move, share or delete any file. Previous result: {\"as_of\": \"2026-11-01\", \"unreadable\": [], \"leases\": []}"
}- Get an API key. In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
- Send the request. POST the body in request.json to https://api.phoenix.so/o/{org}/sessions. The run starts in its own cloud sandbox.
- Read what came back. Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.
What comes back
What comes back is the JSON in the session's result, which the software receives on its webhook and stores against the customer: the tenancies ending within 90 days with their notice clauses and the date notice is due, a list of files the agent could not read, and the full set of leases it now knows about, which the next month's run starts from. The software shows the first list as the manager's renewals screen, each row linking to the lease file in OneDrive.
What the manager checks before acting on a row: the end date and notice clause against the lease itself, by opening the linked file, since a hand-amended date or an addendum filed separately can change the answer; and every file on the unreadable list. Working out what notice the law requires is the manager's job, and the software says so; the agent only quotes what the lease says.
Run it on every first of the month
The software's scheduler sends POST /o/{org}/sessions with {"agent": "<agent id>", "input": "…"} for each customer on the first of the month, putting the last run's date and stored result in the prompt and a request_id made as a UUID v5 of the customer id and month, so a retried call returns the run it already started.
When a manager uploads a batch of new leases after a busy letting season, a "Refresh renewals" button starts the same agent with today's date, and only the new files are read.
The use case this job follows, with its automation and trigger: Run an agent per customer task.
Why run it on Rush?
Each manager's OneDrive sign-in is held in Rush's connection under that customer's own agent, so one customer's run never sees another customer's files, and the software stores agent ids rather than Microsoft tokens. When a customer leaves, deleting their agent disconnects their OneDrive with it.
Each run has its own computer, so lease PDFs are downloaded and read in that run's sandbox rather than on the software's servers, and the session keeps a record of every file the agent listed and opened. To charge customers for renewals, the company lists each one's runs with GET /o/{org}/sessions?agent=<agent id> and adds up total_cost_usd.
Frequently asked questions
Why re-read only changed files?
A manager with 300 leases changes a handful a month. Passing last month's result in the prompt and reading only files modified since keeps each run short, and a lease whose end date was already known stays on the list without being opened again.
Can the agent tell the manager how much notice the law requires?
No. It quotes the lease's own notice clause and works out a date only from what the clause says. What notice a jurisdiction requires is for the manager or their adviser to decide.
Our customers keep leases in SharePoint, not OneDrive. Does this work?
The OneDrive sign-in reads the signed-in person's own drive through Microsoft Graph. Leases kept in a SharePoint document library are not what this page covers, so test with one customer's real folder before offering it.
More OneDrive jobs
More jobs like this: Run an agent per customer task
- What's Still Open Before the Wedding? A Planner App Drafts Each Couple's Weekly Checklist From the Planner's ClickUp (ClickUp)
- Match Signed Rate Confirmations in Each Freight Broker's Outlook to Their Loads (Outlook)
- Turn Tenant Emails in Each Property Manager's Outlook Into Maintenance Requests (Outlook)