- Who can access specific information, and who can update it?
- Which version is current?
- How do you review agent-generated changes?
- Can an answer be traced back to the source material it came from?
- You organize content into a domain-based structure - one curated knowledge base per domain - with a staging area for new files and an approved area for trusted ones.
- When a file lands in staging, you use Box AI to review it: summarize it, score its content health, suggest a domain and tags, and flag issues like missing owners or stale guidance.
- You record that review as Box metadata so every file carries its governance status, and you promote approved content into a Box Hub - the trusted destination that agents query.
- Humans and agents query the brain through Box AI, getting answers grounded in approved, permission-controlled content, with citations back to the source.
What you are building
By the end of this tutorial, you have a working Python project that:- Provisions a governed folder structure - the company brain - organized by domain, each with a staging and an approved area.
- Uses a dedicated service account as the shared, governed identity that both your automation and your agents act through.
- Reviews staged files with Box AI, producing a summary, a suggested domain, tags, and a content health score, then flags quality issues.
- Writes the review back to each file as a governance metadata instance, so status and ownership are searchable and auditable.
- Publishes approved content to a domain Box Hub and answers natural-language questions grounded in that trusted content.
- Gives your local and cloud agents a safe, permission-aware way to work from the same source of truth.
Prerequisites
Before you start, make sure you have the following:- A , or a with Box AI and Box Hubs enabled. See .
- A Box platform application configured with Client Credentials Grant authentication.
- Admin access to create a metadata template (Step 2), or a Box administrator who can create one for you.
- Python 3.11 or higher.
- The following scopes enabled on your platform app:
- Read and write all files and folders stored in Box
- Manage AI
- Manage enterprise properties (required to create and write metadata)
Step-by-step process
A company brain is built from four Box Platform capabilities working together. Each one maps to a requirement that a shared, trusted knowledge layer must meet.Design your company brain structure
_staging area; only approved files move to the approved area that agents are pointed at.Create a folder structure in Box similar to the following:Company Brain folder, and the ID of one domain’s _staging folder (for example, security/_staging). You use these in later steps. The folder ID is the number at the end of the folder’s URL: https://app.box.com/folder/123456789 means the folder ID is 123456789.security). Once the pattern works, repeat it per domain. Adding a domain is easy: a new folder pair and a new Hub, owned by the team closest to the work.Create the knowledge governance metadata template
- Open the Box Admin Console and select Metadata.
- Click New and name the template
Knowledge Governance. - Add the following fields:
- Click Save.
- Click back into your newly created template and copy the template key shown under the template name. You need it in a later step.
Content Health Score becomes contentHealthScore. The code in Step 6 uses these keys. If you rename a field, confirm its key in the Admin Console and update the code to match. For a detailed walkthrough, see .Set up the development environment
- Open your terminal and create a new project directory:
- Create and activate a Python virtual environment:
(.venv) at the beginning. This confirms you are working inside the virtual environment.source .venv/bin/activate from the project directory. If you see ModuleNotFoundError when running commands, it usually means the venv is not activated.- Install the required packages:
- Create a
.envfile to store your credentials, then add the following content. Replace the placeholder values with your actual credentials from the Box Developer Console:
.env file stores sensitive values (your actual credentials). Your Python code reads these values by referencing their names using os.getenv("VARIABLE_NAME"). When you copy the code in the following steps, keep the quoted variable names exactly as shown. Do not replace them with your actual credentials.Authenticate as a service account
box_client.py and add the following code:Review staged content with Box AI
review.py:Record the review as governance metadata
intake.py. It reviews every file in a domain’s staging folder and stamps each one with governance metadata:_staging folder in Box, then run:staged governance record.status to staged and owner to unassigned on purpose. A file being uploaded does not make it trusted knowledge. A human still decides what gets approved and who owns it - the next step.Approve content and publish it to a domain Hub
publish.py. It marks a file as approved, moves it into the domain’s approved folder, and ensures a domain Hub exists and contains that folder:Query the company brain
ask.py:YOUR_HUB_ID with the hub ID from the previous step, then run:Connect your agents to the company brain
- Local agents (for example, a coding agent working against synced files) reach the brain through Box Drive or the , treating it like a local repository. Authenticate the CLI as the service account from Step 4 so the agent inherits exactly the access you granted the brain. More information is available on how to .
- Cloud agents (for example, an assistant in a chat app) reach the same content through the , with permission-aware access and admin controls. See more information on how to .
operating-rules folder so every agent reads the current version from the brain itself. For example:Keep the brain healthy
staged after too long:from value must include your enterprise ID. Use enterprise_{BOX_ENTERPRISE_ID}.{template_key} - for example, enterprise_123456789.knowledgeGovernance.Troubleshooting
ModuleNotFoundError: No module named '...'
ModuleNotFoundError: No module named '...'
source .venv/bin/activate from the project directory before running any python3 commands. Each new terminal tab needs its own activation.invalid_client: The client credentials are invalid
invalid_client: The client credentials are invalid
.env file:- Verify
BOX_CLIENT_IDandBOX_CLIENT_SECRETmatch the values in Developer Console > Configuration. - Confirm
BOX_ENTERPRISE_IDis your enterprise ID (Admin Console > Account & Billing, or Developer Console > icon in the top-right > Copy Enterprise ID). - Ensure your app is authorized in the Developer Console and uses Client Credentials Grant.
404 Not Found
404 Not Found
Company Brain folder. Because subfolders inherit collaboration, this grants access to every domain, staging, and approved folder inside it.metadata_template must have both scope and template_key
metadata_template must have both scope and template_key
BOX_METADATA_TEMPLATE_KEY value in your .env file is missing or empty. Add the template key you copied when creating the Knowledge Governance template in Step 2.Metadata write fails with 400 bad_request: Request contains invalid parameters
Metadata write fails with 400 bad_request: Request contains invalid parameters
404, not 400), but one of the keys in the payload is not a field in the template, or a value breaks a field’s type. The most common cause is a field name mismatch - for example, if the first field was created as Domain in the Admin Console, Box generates the key domain, but if it was named anything else the key differs and the domain key the code sends is rejected.Every key in build_governance (domain, owner, status, contentHealthScore, summary, tags, reviewNotes) must exactly match a field key in your template. Print the actual keys and types to compare:build_governance to match what the template actually uses. A Number field also rejects non-numeric values, so make sure the health score is sent as a number.Box AI returns empty or irrelevant answers
Box AI returns empty or irrelevant answers
- Wait a few minutes after publishing before querying. Indexing is not instantaneous.
- Verify the approved folder contains files (not just subfolders) and that they contain text (scanned image PDFs without OCR are not searchable).
- Confirm you are querying the correct hub ID from Step 7.
Scaling to production
Automate the intake and approval loop
Automate the intake and approval loop
intake.py by hand, trigger the review when a file lands in a _staging folder and route the result to the right owner as an approval task. See for event-driven workflows, or register a on each staging folder.One hub per domain, combined per task
One hub per domain, combined per task
Support conversational follow-ups
Support conversational follow-ups
POST /2.0/ai/ask endpoint accepts a dialogue_history parameter carrying previous question-and-answer pairs. Maintain a list of exchanges and pass it with each request so users can ask follow-ups without losing context. See for a conversational implementation.Govern content lifecycle
Govern content lifecycle
