Skip to content

feat: flows + magic apex layer (PR5 of OpenAI Agents SDK migration) - #76

Merged
keli-wen merged 1 commit into
masterfrom
feat/flows-and-magic
May 7, 2026
Merged

feat: flows + magic apex layer (PR5 of OpenAI Agents SDK migration)#76
keli-wen merged 1 commit into
masterfrom
feat/flows-and-magic

Conversation

@keli-wen

@keli-wen keli-wen commented May 7, 2026

Copy link
Copy Markdown
Contributor

Summary

PR5 lands the apex layer of the OpenAI Agents SDK migration:

  • quantmind/flows/paper_flow, batch_run + BatchResult, plus the internal _runner that wires RunConfig from BaseFlowCfg and composes multiple RunHooks into the single instance the SDK accepts.
  • quantmind/magic.pyresolve_magic_input(natural_language, *, target_flow, ...) introspects a flow's input and cfg parameter annotations, builds a parameterized ResolvedFlowConfig[InputT, CfgT], and runs a lightweight resolver Agent. preview_resolve is the debug pretty-printer.
  • Deletes the transitional packages now that the apex consumes them: quantmind/{flow,llm,config,models}/ and tests/{config,models}/.

After this PR the codebase has converged to the five permanent module roots (flows/, configs/, knowledge/, preprocess/, mind/) plus magic.py and utils/.

Highlights

paper_flow dispatchisinstance chain on PaperInput's discriminated-union variants. Both HTTP and local-file branches share _format_by_content_type, which routes by Fetched.content_type (PDF / HTML / markdown / plain-text). DOI variant raises NotImplementedError pointing at the existing unpaywall follow-up — CrossrefMetadata does not expose a usable PDF URL.

batch_runasyncio.Semaphore-bounded fan-out, deterministic error ordering, on_error: "raise" | "skip", on_progress callback. memory= is rejected at the signature layer (design doc §4.3.5) — for memory-accumulating workflows users write a serial loop themselves. BatchResult keeps parallel-arrays as primary representation and exposes successes / failures properties for the partitioned view; tokens_total / cost_estimate_usd defaults are placeholders that PR6's MemoryRunHooks will populate.

memory: object | None placeholderpaper_flow accepts the parameter today but the runtime is a no-op for any non-None value. PR6 narrows the type to a Memory Protocol and fills _collect_hooks + _archive_run_artifacts without changing the signature, batch_run, or magic.py introspection.

magic.py schema rendering_pydantic_schema_str handles Annotated[X, ...] via __metadata__ (version-stable), unwraps Union[...] into oneOf, and gracefully degrades when a model holds non-JSON-schema fields (e.g. agents.ModelSettings carries callables). Falling back to a {title, fields} summary keeps the resolver useful.

Toolchain alignment

  • [tool.basedpyright].exclude reduced to __pycache__ / .venv / build only.
  • [tool.coverage.run].omit emptied; --cov-fail-under bumped from 65 to 75.
  • Removed the two pydantic.* deprecation suppressors (they only covered the deleted models).
  • Existing four import-linter contracts dropped references to the deleted packages.
  • New fifth contract pins flows + magic as the apex layer; the deleted package names (quantmind.config, quantmind.flow, quantmind.llm, quantmind.models) are listed in forbidden_modules as a tripwire against accidental re-introduction.

Verify

[1/5] ruff format --check    OK
[2/5] ruff check             OK
[3/5] basedpyright           0 errors
[4/5] lint-imports           5 contracts KEPT
[5/5] pytest --cov           233 passed; coverage 89.48% (floor 75%)

Test plan

  • bash scripts/verify.sh exits 0 with branch coverage ≥ 75 %
  • grep -rn 'from quantmind\.\(flow\|llm\|config\|models\)' quantmind/ tests/ returns 0 hits
  • All five import-linter contracts KEPT
  • python -c "from quantmind.flows import paper_flow, batch_run, BatchResult, UnsupportedContentTypeError" succeeds
  • python -c "from quantmind.magic import resolve_magic_input, preview_resolve, ResolvedFlowConfig" succeeds
  • README runbook examples updated for paper_flow, batch_run, resolve_magic_input
  • CLAUDE.md "Current Repository State" + "Roadmap" + "Things NOT to Do" rows refreshed

Follow-ups (not blocking this PR)

  • quantmind/utils/logger.py reports 0 % coverage now that the transitional packages no longer import it. Add a smoke-test file under tests/utils/ whenever the logger gains a real consumer (PR6's memory layer is the first candidate).
  • DOI → OA-PDF resolution (the NotImplementedError in paper_flow._fetch_and_format) needs the unpaywall fallback; tracked under PR4's deferred list.

Part of #71

🤖 Generated with Claude Code

Land the apex layer that composes configs / knowledge / preprocess on
top of the OpenAI Agents SDK:

  quantmind/flows/
    paper_flow(input, *, cfg, ...) -> Paper       — async; isinstance-
        dispatched fetch + format on PaperInput, builds Agent with
        output_type=Paper, runs through run_with_observability.
        DOI variant raises NotImplementedError pointing to the
        unpaywall follow-up issue.
    batch_run(flow_fn, inputs, *, ...) -> BatchResult — bounded
        concurrency, "raise" / "skip" error policy, on_progress hook;
        memory= rejected at the signature layer per design §4.3.5.
    BatchResult — parallel-arrays primary + successes/failures
        properties; tokens_total / cost_estimate_usd defaults left
        for PR6's MemoryRunHooks to populate.
    _runner — RunConfig wiring from cfg, _compose_hooks /
        _CompositeRunHooks fan-out (SDK takes only one hooks
        instance), _archive_run_artifacts no-op stub for PR6.

  quantmind/magic.py
    resolve_magic_input(natural_language, *, target_flow, ...) — type
        introspection + ResolvedFlowConfig[InputT, CfgT] generic +
        lightweight resolver Agent; preview_resolve debug helper;
        _pydantic_schema_str gracefully degrades when a model holds
        non-JSON-schema fields (e.g. agents.ModelSettings).

Deletes the transitional packages now that the apex consumes them:

  quantmind/{flow,llm,config,models}/   — superseded by
    flows/ + agents SDK + configs/ + knowledge/.
  tests/{config,models}/                — paired tests.

Toolchain alignment:

  pyproject.toml — basedpyright excludes only __pycache__/.venv/build;
    coverage.run.omit emptied; --cov-fail-under bumped 65 -> 75; the
    pydantic.* deprecation suppressors removed (they only covered
    the deleted models). Existing import-linter contracts dropped
    references to the deleted packages; new 5th contract pins
    flows + magic as apex with the deleted package names listed as
    a tripwire.

Docs:

  README.md  — new runbook examples for paper_flow, batch_run, and
    resolve_magic_input; "Future Conceptual Example" updated to
    note FilesystemMemory lands in PR6.
  CLAUDE.md  — Current Repository State, "Things NOT to Do", and
    Roadmap rows refreshed.

Verify: 233 tests pass; branch coverage 89.48% (floor 75%); five
import-linter contracts KEPT.

Part of #71

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@keli-wen keli-wen self-assigned this May 7, 2026
@keli-wen keli-wen added the type: feature Adds a new capability or observable behavior label May 7, 2026
@keli-wen
keli-wen merged commit 8e21888 into master May 7, 2026
2 checks passed
@keli-wen
keli-wen deleted the feat/flows-and-magic branch May 7, 2026 16:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: feature Adds a new capability or observable behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant