Skip to main content

Modular AI subagents for document processing - DOCX editing, PDF filling, and more

Project description

morphllm

Modular AI subagents for document processing. Built for use with OpenAI-compatible APIs.

How It Works

Subagents follow the "Agents as Tools" pattern—specialized secondary agents that your main agent delegates to for domain-specific tasks:

                              ┌─────────────────────┐
                              │     MAIN AGENT      │
                              │                     │
                              │  • Orchestrates     │
                              │  • Plans            │
                              │  • Delegates        │
                              └──────────┬──────────┘
                                         │
            ┌────────────────────────────┼────────────────────────────┐
            │                            │                            │
            ▼                            ▼                            ▼
   ┌─────────────────┐          ┌─────────────────┐          ┌─────────────────┐
   │   DOCX AGENT    │          │   PDF AGENT     │          │   YOUR AGENT    │
   │                 │          │                 │          │                 │
   │  "Review this   │          │  "Fill out      │          │  Domain-specific│
   │   contract"     │          │   this form"    │          │  capabilities   │
   └────────┬────────┘          └────────┬────────┘          └────────┬────────┘
            │                            │                            │
            ▼                            ▼                            ▼
   ┌─────────────────┐          ┌─────────────────┐          ┌─────────────────┐
   │  Track changes  │          │  Form filling   │          │  Custom tools   │
   │  Comments       │          │  Annotations    │          │  & APIs         │
   │  Document edits │          │  (Coming soon)  │          │                 │
   └─────────────────┘          └─────────────────┘          └─────────────────┘

Installation

pip install morphllm

With OpenAI support:

pip install morphllm[openai]

Available Subagents

Subagent Description Status
DOCX Track changes, comments, and document editing Available
PDF Form filling and annotations Coming Soon

Quick Start

DOCX Client (Direct API Access)

from subagents.docx import DocxClient

client = DocxClient()

# Upload a document
doc_id = client.upload("contract.docx", user_id="user1", chat_id="chat1")

# Read content
content = client.read(doc_id)

# Add comments and track changes
client.edit(doc_id, "add_comment", para_text="Introduction", comment="Needs citation")
client.edit(doc_id, "insert_text", para_text="Introduction", after=".", new_text=" [1]")

# Download the edited document
client.download(doc_id, "contract_edited.docx")

DOCX Agent (AI-Powered)

from subagents.docx import DocxAgent

agent = DocxAgent(api_key="sk-...")
agent.set_document("userId/chatId/docId")

# Simple completion
response = agent.complete("Review this contract and flag any issues")
print(response)

# Full chat with history
result = agent.chat([
    {"role": "user", "content": "Add comments to unclear sections"},
])
print(result["choices"][0]["message"]["content"])

# Streaming
for chunk in agent.chat_stream([
    {"role": "user", "content": "Summarize the document"},
]):
    delta = chunk.get("choices", [{}])[0].get("delta", {})
    if "content" in delta:
        print(delta["content"], end="", flush=True)

With OpenAI SDK

from openai import OpenAI
from subagents.docx import DocxAgent

agent = DocxAgent()
openai = OpenAI(**agent.openai_config())

response = openai.chat.completions.create(
    model="morph-docx",
    messages=[{"role": "user", "content": "Hello!"}],
)

Building Custom Subagents

Extend the base classes:

from subagents.core import BaseClient, BaseAgent

class MyClient(BaseClient):
    def _default_api_url(self) -> str:
        return "https://my-api.example.com"

    def my_method(self):
        return self._get("/my-endpoint")

class MyAgent(BaseAgent):
    def _default_model(self) -> str:
        return "gpt-4"

    def _default_instructions(self) -> str:
        return "You are a helpful assistant."

    def _get_tools(self) -> list:
        return [...]

    def _execute_tool(self, name: str, args: dict) -> str:
        ...

Environment Variables

Variable Description Default
DOCX_API_URL DOCX service URL https://api.subagents.com/v1/morph-docx
MORPH_API_URL Chat completions base URL https://api.subagents.com/v1
MORPH_API_KEY API key (optional)

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

morphllm-0.1.0.tar.gz (8.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

morphllm-0.1.0-py3-none-any.whl (10.8 kB view details)

Uploaded Python 3

File details

Details for the file morphllm-0.1.0.tar.gz.

File metadata

  • Download URL: morphllm-0.1.0.tar.gz
  • Upload date:
  • Size: 8.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for morphllm-0.1.0.tar.gz
Algorithm Hash digest
SHA256 56d0b7f7535e0f4a0b0e53137b51587c1110f1fec57b1cb51e73b46cd409feef
MD5 14d52a3e2c9a13b8f0dd23ccd2de1295
BLAKE2b-256 9725964712aab0153fec6b9923550f60f5791ec0fe804a2514dd29cb98e417fc

See more details on using hashes here.

File details

Details for the file morphllm-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: morphllm-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 10.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for morphllm-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a80bde8b0911166d9b76ba465f1c581aef3cbce5d89d5f06ea4186a49621bc6a
MD5 83bff3d1f01b148a65cc4136bfef96ae
BLAKE2b-256 6651f733b8d3eb8cdc706252d6e67278ae05331a67b878cc52ebc0c4a10da07f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page