Skip to content

Latest commit

 

History

History
151 lines (125 loc) · 7.98 KB

README.md

File metadata and controls

151 lines (125 loc) · 7.98 KB

Processing

Processing edits tables and workbooks in a persistent file workspace. A single agent inspects inputs, executes Python and spreadsheet operations, and submits files. ProcessingClaudeSDKEntry is the public API name retained for caller compatibility. The execution loop is adapted from MIT-licensed SWE-agent and integrated with Processing's workspace, tools and provider accounting.

Install and run

Use Python 3.11+ and install from the repository root:

pip install -e .
pip install -r src/tableflow/processing/requirements.txt

Python file processing works without Excel. Native workbook objects and recalculation require Windows, Microsoft Excel and an interactive user session. The loop and provider message conversion live in agents/, step/history records in runtime/, and structured-call parsing in tools/. Processing does not require the SWE-agent package, SWE-ReX containers or upstream command-line/UI components. The original MIT notice covers the adapted source portions.

from pathlib import Path
from tableflow.processing import (
    ProcessingClaudeSDKConfig, ProcessingClaudeSDKEntry,
    ProcessingTask, OutputArtifactContract,
)

config = ProcessingClaudeSDKConfig(
    swe_provider_protocol="openai_responses",  # or openai_chat / anthropic_messages
    chat_reasoning_effort="medium",           # when supported by the provider
    swe_allow_paid=True,
    swe_budget_ledger=Path("runs/processing-credits.sqlite"),
    swe_max_total_credits=10,
    swe_credit_rates=(1, 4, 0.02, 1),  # EXAMPLE: replace with the provider tariff
)
task = ProcessingTask(
    "Apply the requested workbook changes.", [Path("book.xlsx")], Path("delivered"),
    output_artifact_contract=OutputArtifactContract("workbook", ("result.xlsx",)),
)
result = ProcessingClaudeSDKEntry(config).run_task(task)
print(result.success, result.selected_artifacts)

Rates are input, output, cache-read and cache-write credits per million tokens. The ledger cap is cumulative across concurrent tasks. Paid calls require explicit admission, rates and a ledger; confirmed spending, unknown usage and reservations are recorded separately. Retries consume call slots and retain uncertain costs.

The model, key and endpoint default to the shared DF_MODEL, DF_API_KEY and DF_API_URL configuration. Set these once through the environment or the root config.local.py; see the global configuration. Processing needs no second credential setup. Optional constructor arguments model_name, api_key and base_url override these defaults for a direct caller.

For router/Web use, set Processing's execution policy before starting the server:

DF_PROCESSING_ALLOW_PAID=1
DF_PROCESSING_SWE_PROVIDER_PROTOCOL=anthropic_messages
DF_PROCESSING_BUDGET_LEDGER=/absolute/private/path/credits.sqlite
DF_PROCESSING_MAX_TOTAL_CREDITS=10
DF_PROCESSING_CREDIT_RATES=[1,4,0.02,1]
DF_PROCESSING_SDK_RUN_ROOT=/absolute/private/path/processing-runs

Explicit constructor settings override environment defaults. Messages is the default transport; select Chat or Responses for the corresponding endpoint. Shared DF_API_KEY/DF_API_URL settings take priority over legacy DF_LAB_* fallbacks. An endpoint still needs to support the selected provider protocol. Provider, budget and execution policy remain operator-owned. Direct callers pass files and preservation/output contracts through ProcessingTask. The system adapter supplies the caller's contracts, original request and document context, then hands the explicitly selected output folder to downstream stages.

Workspace and observations

Inputs are copied to input/; edits belong in work/ or output/. Files persist between calls, while Python variables and shell state do not. This workspace is for trusted-host execution and does not provide OS isolation.

Tool Use
view_xlsx List saved sheets or inspect a coordinate-labelled cell/style rectangle.
run_python General table inspection, computation, formula and cell editing.
shell Noninteractive commands in the advertised shell dialect.
table_native Excel objects, workbook operations and explicit calculation.
table_observe Read or search saved output; optionally issue enabled precise queries.
table_help Detailed native contracts and environment information.
submit Validate and seal selected files.

view_xlsx reads at most 50 rows by 20 columns and reports remaining ranges. Formula text, stored caches and freshly calculated values remain distinct; missing caches remain unknown. Repeated formulas use reversible row patterns. mode="styles" groups identical saved base formats and shares typed style components, preserving coordinates, blanks, exceptions and row/column defaults. It does not evaluate conditional/table formatting or named-style inheritance. These representations describe stored facts and imply no requested edit.

Large output retains its full saved text, with a 10,000-character head/tail preview. handle:start:end cursors traverse the unseen middle; legacy offset cursors, explicit offsets and literal search remain supported. Calculated-cell pages read the same immutable workbook without recalculating or rerunning code. Ordinary Python output is retained. Conversation history is append-only.

Precise queries, literal-label location and named scripts are separate settings:

Config field / environment Default Effect
swe_precise_queries / DF_PROCESSING_PRECISE_QUERIES off Expose registered workbook queries and their help/admission contracts.
swe_label_locator / DF_PROCESSING_LABEL_LOCATOR off Enable bounded literal-text location with view_xlsx(find=...).
swe_named_scripts / DF_PROCESSING_NAMED_SCRIPTS off Enable run_python(save_as=...); subsequent script execution is explicit.
swe_formula_patterns / DF_PROCESSING_FORMULA_PATTERNS on Use exact reversible formula patterns when smaller.

Set environment switches to 0 or 1. Precise queries being off does not disable ordinary Python, native reads, output continuation or workbook library APIs. Changing the model surface during a task invalidates continuation binding.

Excel, delivery and continuation

Each task may reuse one verified private Excel application. Transactions use fresh private file copies, reset calculation settings and close their workbooks; only application startup is shared. Process identity and cleanup are checked. Uncertain ownership blocks reuse; native edits are not replayed implicitly. TABLEFLOW_EXCEL_TASK_REUSE=0 selects a per-call application lifecycle with the same calculation and validation contracts. Excel execution and queue timing are recorded separately. Calculation copies can retry classified transient COM faults only after confirmed cleanup and restoration of their original bytes.

Accepted files are sealed and atomically copied to task.output_dir/output/<run-id>/. selected_output_dir identifies this folder; only sealed files enter the downstream handoff. Keep the private run root outside that public delivery tree. With swe_recover_submission=True (default), a task ending without submit may recover its last saved file after the same input, package, preservation, cleanup and hash checks. Ambiguous or invalid outputs remain private. Recovery makes no model request and is labelled separately from explicit submission. Neither delivery nor successful recalculation proves business correctness.

swe_max_calls defaults to 50. swe_resume_from requires matching task, model, surface, accounting and checkpoint hashes plus confirmed cleanup; calls and costs are cumulative. Responses checkpoints retain the reasoning/tool chain. Input token allowance is a local estimate; leave headroom for provider context limits.

Tool contracts

The system policy and tool definitions are the instruction sources. Native methods retain their full runtime validation. Use table_help to discover advanced options.