Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/vrashmanyu605-eng/Agentic_Sales-Markerting/llms.txt

Use this file to discover all available pages before exploring further.

The Google Sheets tool lets the crm_update_agent persist structured lead data to a spreadsheet at the end of each pipeline run. It authenticates with a service account, then uses the Sheets API v4 to append rows — never overwriting existing data. All connection errors and missing credential failures are returned as strings rather than raised exceptions, so agents can handle failures gracefully.
credentials.json must be present in the project root directory. If the file is missing, update_google_sheet() returns an error string immediately without making any network call or raising an exception.

Source code

google_sheets_tool.py
import os
import json
from google.oauth2.service_account import Credentials
from googleapiclient.discovery import build

def update_google_sheet(spreadsheet_id, range_name, values):
    """
    Updates a Google Sheet with the provided values.
    Requires a 'credentials.json' file in the root directory.
    """
    SCOPES = ['https://www.googleapis.com/auth/spreadsheets']
    
    creds_path = 'credentials.json'
    
    if not os.path.exists(creds_path):
        return "Error: credentials.json not found. Please provide Google Cloud service account credentials."

    try:
        creds = Credentials.from_service_account_file(creds_path, scopes=SCOPES)
        service = build('sheets', 'v4', credentials=creds)

        body = {
            'values': values
        }
        
        result = service.spreadsheets().values().append(
            spreadsheetId=spreadsheet_id,
            range=range_name,
            valueInputOption='RAW',
            body=body
        ).execute()

        return f"{result.get('updates').get('updatedCells')} cells updated."

    except Exception as e:
        return f"Error updating Google Sheet: {str(e)}"

update_google_sheet()

Appends one or more rows to a Google Sheet using a service account.

Parameters

spreadsheet_id
string
required
The ID of the target Google Sheet. Found in the sheet URL: https://docs.google.com/spreadsheets/d/<spreadsheet_id>/edit.
range_name
string
required
The A1 notation range where data should be appended, e.g. "Sheet1!A1". The API uses this range to determine the table and appends after the last row with data.
values
list[list]
required
A list of rows to write. Each inner list represents one row; each element in the inner list is one cell value. Example: [["Acme Corp", "Discovery call completed", "Cloud migration", "$50,000", "Schedule demo"]].

Return value

result
string
On success: a string in the format "N cells updated." where N is the number of cells written.
On missing credentials: "Error: credentials.json not found. Please provide Google Cloud service account credentials."
On API error: "Error updating Google Sheet: <exception message>".

Authentication

The tool authenticates using a Google Cloud service account key file.
SettingValue
Credentials filecredentials.json (project root)
Auth scopehttps://www.googleapis.com/auth/spreadsheets
APIGoogle Sheets API v4
Write modeAppend — does not overwrite existing rows

CRM column layout

The crm_update_agent writes the following columns in order when it calls this tool:
ColumnFieldDescription
Aclient_nameCompany name of the lead
Bmeeting_summarySummary of the qualification and research findings
Cclient_requirementsKey requirements identified during research
Dopportunity_valueEstimated deal value
Enext_stepsRecommended next actions for the sales team

Example call

from tools.google_sheets_tool import update_google_sheet

result = update_google_sheet(
    spreadsheet_id="1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgVE2upms",
    range_name="Sheet1!A1",
    values=[
        [
            "Acme Corp",
            "Qualified lead — engineering team of 200, active cloud migration project.",
            "Scalable data pipeline, real-time analytics, SOC 2 compliance",
            "$120,000",
            "Schedule technical discovery call with CTO Jane Doe"
        ]
    ]
)

print(result)  # "5 cells updated."
For instructions on creating a service account and sharing your sheet, see the Google Sheets setup guide.

Build docs developers (and LLMs) love