AD SPACE AVAILABLE · BRAND PARTNERS WELCOME

How Developers Build Enterprise AI Applications with the Open-Source Writer Framework and Palmyra Models

Ong Lay Hoon · 365Finds Editorial
Indexed 88,650 Wiki articles

Put 365 Wiki to work with your AI

Copy the prompt below, paste it into the AI you already use, then ask your question.

Download full Skill

Try it with the prompt first. If you use 365 Wiki often, install the full 365Wiki Skill so you do not have to paste it again. No regular AI? Gemini or Microsoft Copilot on the web will work.

365Wiki Skill

Enterprise software engineers frequently run into a wall when moving generative AI projects out of prototype status. Cloud-based visual builders like Writer AI Studio make prompt experimentation and workflow prototyping rapid for non-technical teams, but production enterprise applications require code-level version control, strict local state management, custom layouts, CI/CD automation, and private deployment boundaries. Conversely, standard Python dashboard tools like Streamlit re-execute entire scripts from top to bottom whenever a user clicks a button, creating unpredictable execution loops and heavy backend latency when coordinating multi-turn agent interactions.

At 365Finds, we look closely at how developer tooling balances developer velocity against engineering rigor. The open-source Writer Framework (formerly known as Streams) bridges this gap with a distinct architectural split: visual UI composition saved as structured JSON/JSONL, coupled with standard Python backend logic driven by bi-directional WebSocket state synchronization. Paired with Writer's proprietary Palmyra LLM family (such as Palmyra-X-004 and the long-context Palmyra X5), developers can assemble responsive, auditable, and production-ready enterprise AI tools without needing to build a full React frontend stack.


The Architecture: Why Writer Framework Differs from Traditional Stacks

The primary architectural bottleneck in Python AI app development has always been state persistence and reactivity. To understand where the Writer Framework fits, consider how it differs from traditional Python dashboard libraries and headless backend setups:

Architectural LayerStreamlit / GradioFull-Stack (FastAPI + React)Open-Source Writer Framework
UI DefinitionImperative Python code; re-rendered top-to-bottom on state changeJSX/React components, compiled bundleVisual drag-and-drop Builder; serializes to .wf/ JSON structures
State ExecutionScript rerun per interaction; requires manual cache decoratorsREST / WebSockets; manual redux/zustand state managementEvent-driven Python handlers; automatic delta sync via WebSockets
Concurrency ModelProcess-blocking unless heavily tuned; costly rerunsAsynchronous microservices; independent frontend threadsMulti-threaded backend event workers; non-blocking token streaming
Version ControlPython script only; UI and business logic tangled togetherSeparate frontend and backend repositoriesClean separation: main.py (logic) and .wf/ (UI layout schema)
LLM IntegrationGeneric API wrappers; manual streaming buffer managementCustom WebSocket streaming endpointsBuilt-in writer.ai primitives and native writer-sdk bindings

In the Writer Framework, the frontend does not recalculate UI trees through Python reruns. Instead, a local web builder allows engineers to drag, arrange, and configure UI components. When an end-user triggers an interaction—such as submitting an enterprise search query—the browser sends an event payload across an open WebSocket connection. The backend executes a targeted Python handler, updates a shared application state dictionary, and transmits only the modified state deltas back to the DOM.


Step 1: Environment Setup and Project Initialization

Getting started requires Python 3.9 through 3.12. The developer installs the framework CLI alongside the official Writer client SDK:

pip install writer writer-sdk

Authenticate your local environment with your Writer API credentials:

export WRITER_API_KEY="your-enterprise-writer-api-key"

To initialize a new standalone application directory, execute:

writer create enterprise_doc_auditor
cd enterprise_doc_auditor

This scaffolding produces a compact directory structure:


Step 2: Designing the UI with the Visual Builder

Rather than writing repetitive HTML or nested Python layout blocks, developers launch the local visual designer:

writer edit enterprise_doc_auditor

This starts a local development server (typically at http://localhost:3005 or http://localhost:3006) presenting a visual drag-and-drop canvas.

Key aspects of this workflow include:

  1. Component Placement: Engineers drag headers, multi-column containers, data tables, chat boxes, and file uploaders onto the canvas.
  2. State Binding: Components bind dynamically to application state keys using the @{key_name} syntax. For example, a text display component's content field is set to @{audit_summary}.
  3. Event Binding: Interactive elements like buttons and input fields wire their actions directly to Python function names. Setting a button's wf-click property to handle_audit ensures clicking the button triggers the handle_audit(state) function in main.py.
  4. Git-Friendly Serialization: As changes are made on screen, the framework continuously updates the files inside .wf/. Engineers can inspect, review, and commit these UI definitions through standard Git pull requests without merge conflicts obscuring the Python logic.

Step 3: Managing State and Handling Events in Python

In main.py, state initialization defines the application schema across all user sessions. Each connected browser session receives an isolated instance of this state dictionary.

Sensitive variables—such as database connection strings, internal service tokens, or private prompt templates—can be prefixed with an underscore (_). The Writer Framework guarantees that keys beginning with _ remain strictly on the backend and are never transmitted to the browser client over the WebSocket wire.

import writer as wf
from writerai import Writer

# Initialize the reactive application state
initial_state = wf.init_state({
    "document_title": "Q3 Compliance Audit",
    "raw_text": "",
    "audit_summary": "Upload a document to begin analysis.",
    "is_processing": False,
    "severity_level": "Normal",
    "_internal_audit_id": None,
})

def handle_audit(state):
    """
    Event handler triggered by the UI button.
    Mutates the session state directly.
    """
    user_text = state.get("raw_text", "").strip()
    if not user_text:
        state["audit_summary"] = "Please supply text before running analysis."
        return

    # Trigger UI loading indicator
    state["is_processing"] = True
    state["audit_summary"] = "Connecting to Palmyra model..."

    try:
        # Initialize the Writer client
        client = Writer()

        # Stream response chunks from Palmyra-X-004
        response_stream = client.chat.chat(
            model="palmyra-x-004",
            messages=[
                {
                    "role": "system",
                    "content": (
                        "You are a regulatory compliance auditor. Analyze the following enterprise text, "
                        "identify liability risks, and highlight contractual discrepancies."
                    ),
                },
                {"role": "user", "content": user_text},
            ],
            stream=True,
            temperature=0.2,
        )

        # Clear placeholder text and stream tokens reactively to the frontend
        state["audit_summary"] = ""
        for chunk in response_stream:
            content = chunk.choices[0].delta.content
            if content:
                # Appending directly to state pushes immediate WebSocket diffs to the browser
                state["audit_summary"] += content

    except Exception as exc:
        state["audit_summary"] = f"Error during model inference: {str(exc)}"
    finally:
        state["is_processing"] = False

Because Writer Framework processes handlers inside background worker threads, iterating through token streams does not lock the WebSocket connection. The browser view renders incoming tokens in real time, delivering a smooth streaming interface.


Step 4: Selecting the Right Palmyra Model

Writer's proprietary Palmyra model series is tailored specifically for enterprise instruction-following, tabular comprehension, and deterministic tool execution. In code-level development, selecting the appropriate model variant dictates performance and token expenditure:

Palmyra-X-004

Palmyra X5

For specialized domains, developers can also target Palmyra-Med for clinical and healthcare documentation or Palmyra-Fin for automated financial disclosure analysis by adjusting the model parameter in client.chat.chat().


Step 5: Enterprise Deployment and Containerization

When shifting from local development to internal enterprise deployment, engineers run the application in production mode via:

writer run enterprise_doc_auditor --port 8080 --host 0.0.0.0

Because the application is standard Python without third-party cloud runtime dependencies, containerization via Docker is straightforward:

FROM python:3.11-slim

WORKDIR /app

# Install dependencies
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

# Copy application code and UI definition files
COPY main.py .
COPY .wf/ .wf/
COPY resources/ resources/

EXPOSE 8080

CMD ["writer", "run", ".", "--port", "8080", "--host", "0.0.0.0"]

This container can be deployed to any enterprise container orchestrator—including Amazon ECS/EKS, Google Kubernetes Engine, Azure Container Apps, or an on-premises Kubernetes cluster. Placing it behind an enterprise reverse proxy (such as Nginx or AWS ALB) allows engineers to terminate SSL, enforce corporate SSO (Okta, Azure AD), and map traffic via private VPC endpoints.


The 365Finds Take: Strengths, Tradeoffs, and Final Assessment

365Finds considers the open-source Writer Framework one of the most practically grounded architectures available for internal enterprise AI tools. It resolves the fundamental engineering flaw of Streamlit—uncontrolled procedural re-runs—without forcing data science and machine learning teams to take on the massive overhead of maintaining custom React, Vite, and CSS toolchains.

The advantages are tangible:

However, developers must recognize the framework's boundaries:

For enterprise engineering teams looking to build robust, multi-turn AI applications and internal tools with minimal frontend friction, the combination of Writer Framework and Palmyra delivers a production-grade foundation that bridges rapid prototyping and enterprise rigor.


References