Skip to main content

Intelligent Futures

A practical, extensible laboratory for better Python concurrency: a bounded concurrent.futures.Executor, transparent workload measurements, an experimental online scheduler, and a growing library of optimization concepts.

Status: alpha research prototype. No universal speedup is promised. The “intelligence” includes an auditable EWMA latency learner and opt-in hardware-aware predictive admission with bounded runtime profiles, not an LLM, code generator, or automatic proof of process safety.

Public repository: yflop/concurrent-futures-ai.

Start in a minute

Python 3.10 or newer; the core has no runtime dependencies. Install the optional MCP adapter with python -m pip install "intelligent-futures[mcp]".

python -m pip install -e .
python -m unittest discover -s tests -v
python examples/profiling.py
from intelligent_futures import IntelligentExecutor, TaskHints

def square(n):
    return n * n

if __name__ == "__main__":  # required when using spawn-based processes
    with IntelligentExecutor(max_workers=4, process_workers=2,
                             max_pending=32, policy="hints") as executor:
        ordinary = executor.submit(square, 7)  # conservative thread routing
        cpu = executor.submit_task(
            square, 9,
            hints=TaskHints(kind="cpu", key="square", process_safe=True),
        )
        print(ordinary.result(), cpu.result())
    print(executor.snapshot())

Tiny tasks like square generally do not benefit from process overhead. This example demonstrates semantics, not a performance recommendation.

Predictive foundation and actual batching (0.3)

Opt in with IntelligentExecutor(predictive=True): successful thread calls collect wall/current-thread CPU measurements, reusable validated JSON profiles guide cold starts, and admission adapts within hardware/objective/worker budgets. map_batches(batch_fn, iterable) submits actual bounded tuple chunks and adjusts chunk sizes from measured completion time, without replaying work. See the predictive guide and examples/predictive_batches.py. Cross-machine learned transfer, per-task RSS enforcement, and process runtime profiling are not implemented. Tiny-workload measurements show overhead; this experimental foundation does not promise a speedup.

What works today

  • Standard-library Future objects, wait, as_completed, map, exceptions, callbacks, and best-effort queued cancellation
  • Independent thread/process worker budgets; processes disabled by default
  • max_pending bounds all unfinished accepted tasks, queued plus running
  • Blocking backpressure, optional admission timeout, and shutdown wakeup
  • Bounded per-key/backend latency profiles, failures, and aggregate counters
  • Safe hint routing, thread-only mode, custom policies, and a policy factory registry
  • Experimental EWMA latency selection with deterministic exploration
  • Ordered map_bounded for streaming inputs and bounded retained results
  • A dependency-free registered-task framework with bounded JSON task records
  • Optional local stdio MCP tools, restricted to explicitly registered callables
  • Runnable examples, reproducible baseline benchmarks, tests, packaging, and CI

Safety first

submit(fn, *args, **kwargs) keeps the standard keyword contract, including a function argument named hints. Use submit_task to reserve the scheduling hints keyword. Process routing requires both a configured process pool and process_safe=True, even from a custom policy. The flag is your assertion: functions and arguments must be pickleable, importable, and semantically safe in a separate process. Do not rely on mutated thread-shared globals across processes.

No retries, speculative duplicates, hard timeouts, task killing, distributed execution, live pool resizing, or remote AI calls are implemented. Predictive mode can adjust admission within fixed worker capacities. Cancellation never stops a running callable. Context-manager exit waits for work. Blocking nested submissions into a saturated executor can deadlock: orchestrate from outside worker tasks, or use a finite submit_timeout and handle failure.

Optional MCP integration (0.2.0)

Expose a trusted allowlist of Python tasks to an MCP client without changing the executor API. Task submission returns an ID immediately; tools inspect results, cancel queued work, forget completed records, and read metrics and concepts. The provided runner uses stdio and opens no listening port.

See the MCP setup and safety guide, framework API, and changelog. The SDK is optional; registered code still runs with your Python process permissions.

Choose the right policy

Policy Behavior Recommended use
threads Always threads Closures, shared state, general I/O
hints CPU + explicit process consent routes to processes Known workloads, predictable routing
adaptive (default) Eligible workloads can explore both backends and learn EWMA completion latency Controlled experiments with comparable task keys

The learner optimizes observed submission-to-completion latency, including pool queueing and serialization, excluding admission wait. It cannot identify causal backend advantages under arbitrary changing load. Errors are counted but do not train latency. Share keys only across comparable work. Profiles are executor-local, not persisted, and evicted with an LRU bound. The policy's exploration counter is global to that policy instance. Keep stateful policy instances private to one executor.

Browse the concept library

python -m intelligent_futures queue --status planned
python -m intelligent_futures --status experimental --json

The bundled ConceptRegistry validates unique IDs, status labels, and acyclic dependencies. Catalog content never imports or executes plugin code.

API and documents

Appendices separate implemented mechanisms from experimental and planned work. Ideas are extension proposals, not hidden features. Benchmark raw data is the source of performance claims; a measured loss is a useful result too.

Development

PYTHONPATH=src python -m unittest discover -s tests -v
python tools/verify.py --examples
python -m compileall -q src examples benchmarks tests
python -m pip wheel . --no-deps -w dist

See benchmark help for workload sizes, repeated cold/warm comparisons, and JSON output. A hybrid executor may use more total workers than a single baseline pool; compare resource budgets before interpreting a timing ratio.

Measured result

The included five-repeat reference run did not beat the best stdlib pool: for warm CPU, synthetic I/O, and mixed batches, adaptive took approximately 548, 164, and 344 ms versus 256, 122, and 196 ms for the best measured stdlib configuration. Worker allocation and hint information differ; see the full validation record. Treat this as an extensible research baseline with tested contracts, not a performance upgrade by default.

License

Original code and documentation are MIT licensed. Activepieces is a conceptual inspiration, not a dependency or copied implementation. Third-party linked material retains its own license.

Cancellation churn and memory

The admission limit is not a strict physical queue or memory bound. Cancelling a queued Future frees logical admission immediately, but stdlib pools can retain its cancelled work item and arguments until a worker drains the queue. Repeated submit/cancel loops behind blocked workers can therefore accumulate tombstones. Rate-limit producers and cancellation churn; do not treat this executor as a hard memory limiter. A removable bounded physical queue is planned work.

Metadata

Release files for intelligent-futures 0.3.0

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

Source distribution (sdist)

Source distribution for intelligent-futures 0.3.0
File Size Uploaded
intelligent_futures-0.3.0.tar.gz 1.2 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for intelligent-futures 0.3.0
File Interpreter ABI Platform
intelligent_futures-0.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 1.3 MB

Release files / intelligent_futures-0.3.0.tar.gz

Download URL intelligent_futures-0.3.0.tar.gz
Size 1.2 MB
Tags Source
SHA-256 checksum
How to use checksums
b45937a9080ec3576e6534af9a6dea797fe5540b3ad314ceca8d63b1814eef6a
BLAKE2b-256 checksum
How to use checksums
c2fd5bbdc5e4bafe09e2049e8dd2e340bff5c6872b0ccdaa3d34f19064e385ad
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Release files / intelligent_futures-0.3.0-py3-none-any.whl

Download URL intelligent_futures-0.3.0-py3-none-any.whl
Size 49.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1095054655a7c9f3ecfb78319ba14b918975585a3041d31fd75baeb279d83bd7
BLAKE2b-256 checksum
How to use checksums
904ae6536877945f2aa7d54bfdc51c68091e71086151df9a7dc94a9e1046aba1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 release files

0.2.0

2 release files

0.1.0

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