Skip to main content

Agent Office Python SDK

Python SDK for the Agent Office API - AI-powered document editing for agentic workflows.

Installation

pip install agent-office

Quick Start

from agent_office import AgentOffice
from uuid import uuid4

# Initialize the client
client = AgentOffice(api_key="sk_ao_your_api_key")  # Get your key from https://agentoffice.dev

# Upload a document
doc = client.documents.create(
    file="document.docx",
    return_markdown=True
)
print(f"Uploaded: {doc.doc_id}")

# Edit the document
edit = client.edit(
    doc_id=doc.doc_id,
    edit_uid=str(uuid4()),
    edit_instructions="Change the title to 'My New Title'",
    tracked_changes=False
)
print(f"Edit applied: {edit.edit_applied}")

# Download the edited document
result = client.documents.download(doc_id=doc.doc_id)
print(f"Download URL: {result.download_url}")

# You can then download the file using requests
import requests
response = requests.get(result.download_url)
with open(f"edited_{doc.name}", "wb") as f:
    f.write(response.content)

Features

  • 📝 Upload and convert documents (DOCX, PDF, etc.)
  • ✏️ AI-powered document editing
  • 📖 Read document content as Markdown
  • 💾 Download edited documents
  • 🔄 Track changes support

API Reference

Client Initialization

client = AgentOffice(
    api_key="sk_ao_your_api_key",  # Required: Your API key
    base_url="https://api.agentoffice.dev",  # Optional: API base URL
    timeout=60  # Optional: Request timeout in seconds
)

Documents

Create Document

doc = client.documents.create(
    file="path/to/document.docx",  # File path or file-like object
    return_markdown=True,  # Return markdown content
    ttl_seconds=3600  # Time to live in seconds (300-21600)
)

Create Document from URL

doc = client.documents.create_from_url(
    file_url="https://example.com/document.docx",
    ttl_seconds=3600
)

List Documents

docs = client.documents.list()
for doc in docs.documents:
    print(f"{doc.name}: {doc.doc_id}")

Download Document

result = client.documents.download(
    doc_id="doc-id",
    expires_in=3600  # Presigned URL expiration in seconds
)
print(result.download_url)

Check Document Exists

result = client.documents.exists(doc_id="doc-id")
if result.exists:
    print(f"Document exists: {result.document.name}")

Edit Document

edit = client.edit(
    doc_id="doc-id",
    edit_uid=str(uuid4()),  # Unique identifier for the edit
    edit_instructions="Change the title to 'My New Title'",  # Natural language instructions
    lookup_text="Section 1",  # Optional: Text to locate edit position
    tracked_changes=False,  # Enable track changes
    use_large_model=False  # Use larger AI model
)

Read Document

result = client.read(doc_id="doc-id")
print(result.markdown)

Error Handling

The SDK provides specific exception types for different error conditions:

from agent_office import (
    AgentOffice,
    AgentOfficeError,
    AuthenticationError,
    NotFoundError,
    ValidationError,
    RateLimitError,
    ServerError,
)

client = AgentOffice(api_key="sk_ao_your_api_key")

try:
    doc = client.documents.create("document.docx")
except AuthenticationError:
    print("Invalid API key")
except NotFoundError:
    print("Document not found")
except ValidationError as e:
    print(f"Validation error: {e.message}")
except RateLimitError:
    print("Rate limit exceeded")
except ServerError:
    print("Server error")
except AgentOfficeError as e:
    print(f"General error: {e.message}")

Development

Install from source

git clone https://github.com/agentoffice/python-sdk.git
cd python-sdk
pip install -e .

Install development dependencies

pip install -e ".[dev]"

License

MIT

Support

Release files for agent-office 0.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for agent-office 0.0.4
File Size Uploaded
agent_office-0.0.4.tar.gz 9.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for agent-office 0.0.4
File Interpreter ABI Platform
agent_office-0.0.4-py3-none-any.whl Python 3 none any Details

Total release size: 22.0 kB

Release files / agent_office-0.0.4.tar.gz

Download URL agent_office-0.0.4.tar.gz
Size 9.7 kB
Tags Source
SHA-256 checksum
How to use checksums
ff6009f8915837919e01e42b64ddbd5d5e3b9c724d6dd2280a1c6e8681042149
BLAKE2b-256 checksum
How to use checksums
ba38f48ac98f50a9528fcc0a3c926000f26fbb5b7920a1783684d262a3c38d3d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.7

Release files / agent_office-0.0.4-py3-none-any.whl

Download URL agent_office-0.0.4-py3-none-any.whl
Size 12.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cc567027a2b7d161df038b3a0a1674e69da71055c5854004cc1e69b06879ef7c
BLAKE2b-256 checksum
How to use checksums
c80d34030685b5fdbbc706cf9998fb06e59057aef25b807c829a3efeb113ae8e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.7

Release history Release notifications | RSS feed

This release

0.0.4 This release

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page