Skip to main content

Rust runtime for Python AI apps. Drop-in for openai/anthropic SDKs with native SSE streaming, an agent loop with concurrent tool dispatch, and Logfire-compatible OTel emission.

Project description

f3dx

The Rust runtime your Python imports. Drop-in for openai and anthropic SDKs with native SSE streaming, an agent loop with concurrent tool dispatch, and Logfire-compatible OTel emission. PyO3 + abi3 wheels for ubuntu/macos/windows. Built for pydantic-ai.

The intellectual frame is Cruz's "AI Runtime Infrastructure" (arXiv:2603.00495, Feb 2026): a distinct execution-time layer above the model and below the application that observes, reasons over, and intervenes in agent behavior at runtime. f3dx is that layer, in Rust, for Python apps.

pip install f3dx
import f3dx

# 5x faster streaming, drop-in for openai SDK
client = f3dx.OpenAI(api_key="...", base_url="https://api.openai.com/v1")
for chunk in client.chat_completions_create_stream({"model": "gpt-4", "messages": [...]}):
    print(chunk["choices"][0]["delta"].get("content", ""), end="")

# Drop-in for anthropic SDK with native Messages event handling
client = f3dx.Anthropic(api_key="...")
for event in client.messages_create_stream({"model": "claude-3-5-sonnet", "max_tokens": 1024, "messages": [...]}):
    if event.get("type") == "content_block_delta":
        print(event["delta"].get("text", ""), end="")

# 5-10x faster agent runtime via concurrent tool dispatch
agent = f3dx.AgentRuntime(system_prompt="...", concurrent_tool_dispatch=True)
result = agent.run(user_prompt, tools={...}, mock_responses=[...])

# Tool-call streaming reassembly: skip the accumulate-fragments boilerplate
for ev in client.chat_completions_create_stream_assembled({...}):
    if ev["type"] == "tool_call":
        result = dispatch(ev["name"], ev["arguments"])  # arguments is parsed dict, ready

# Validated structured output: skip accumulate-then-json.loads at end
for ev in client.chat_completions_create_stream_assembled(req, validate_json=True):
    if ev["type"] == "validated_output":
        process(ev["data"])  # already parsed
    elif ev["type"] == "validation_error":
        log.warning("model emitted invalid JSON: %s", ev["error"])

# Logfire-compatible OTel spans by default — gen_ai.* semconv
f3dx.configure_otel(
    endpoint="https://logfire-api.pydantic.dev/v1/traces",
    headers={"Authorization": f"Bearer {LOGFIRE_TOKEN}"},
)
# Every Agent.run + every chat_completions / messages call now emits
# spans with gen_ai.system, gen_ai.request.model, gen_ai.usage.{input,output}_tokens, etc.

Why

Compound AI systems (Zaharia BAIR 2024, Mei AIOS arXiv:2403.16971) are the dominant production pattern. The orchestration + HTTP layer is now the bottleneck, not the model. Every other AI infra layer is non-Python by 2026 (vLLM C++, TGI Rust, mistral.rs Rust, Outlines-core Rust, XGrammar C++). Orchestration is the last lane; f3dx ships it.

Bench results (reproducible from bench/)

What vs Speedup
f3dx.AgentRuntime concurrent dispatch pure-python sequential agent loop 5-10x at 5-10 tools/turn
f3dx.OpenAI streaming openai Python SDK 5.10x at 1000 chunks
f3dx.Anthropic streaming anthropic Python SDK 2.9-5.2x at 50-1000 events
Tool-call assembled stream raw fragment iteration 17 chunks -> 2 events
validate_json=True accumulate + json.loads + try/except one extra event, zero user code

All benches live under bench/, all use the stdlib mock servers in the same dir, all single-thread.

Architecture

Cargo workspace, four crates, one PyPI package:

f3dx/
  crates/
    f3dx-py/      PyO3 bridge cdylib (the only crate with #[pymodule])
    f3dx-rt/      agent runtime + concurrent tool dispatch
    f3dx-http/    LLM HTTP client (reqwest + native SSE + streaming JSON validation)
    f3dx-trace/   OpenTelemetry span emission (Logfire-compatible, gen_ai.* semconv)

OpenAI-compatible endpoints (vLLM, Mistral, xAI, Groq, Together, Fireworks) all work via f3dx.OpenAI by setting base_url.

Observability

Configure once with f3dx.configure_otel(endpoint, headers, service_name, stdout). Every AgentRuntime.run emits a root span with gen_ai.system="f3dx" + gen_ai.prompt.length_chars + f3dx.{concurrent_tool_dispatch,iterations,tool_calls_executed,duration_ms,output.length_chars}.

Every chat_completions_create* / messages_create* emits a SpanKind::Client span:

gen_ai.system               openai | anthropic
gen_ai.operation.name       chat | messages
gen_ai.request.model        from request
gen_ai.request.{temperature, top_p, max_tokens, stream}
gen_ai.response.{id, model, finish_reasons}
gen_ai.usage.{input_tokens, output_tokens}

Streaming spans hold open until terminal chunk; usage attrs land when the closing chunk carries them (auto-injects stream_options.include_usage=true for OpenAI; reads message_start.message.usage + message_delta.usage for Anthropic).

Status: Ok on success, Status::error("<msg>") on HTTP failure.

Layout

f3dx/
  bench/                            reproducible benches + verify scripts + stdlib mock servers
  crates/                           cargo workspace member crates
  python/f3dx/__init__.py           core Python wrapper (AgentRuntime, OpenAI, Anthropic, configure_otel)
  python/f3dx/compat/               opt-in subclass shims (f3dx[openai-compat])
  python/f3dx/pydantic_ai/          pydantic-ai integration (f3dx[pydantic-ai])
  python/f3dx/langchain/            langchain-openai integration (f3dx[langchain])
  pyproject.toml                    maturin build, optional extras
  Cargo.toml                        cargo workspace root + workspace lints
  rust-toolchain.toml               pinned to 1.86.0 for reproducible builds
  .github/workflows/ci.yml          ubuntu/macos/windows + clippy gate + built-wheel install
  .github/workflows/release.yml     glibc/musl x86_64+aarch64 wheels + macos x86_64+aarch64 + windows + sdist + OIDC PyPI publish

What this is not

f3dx is a Python-from-Rust runtime — a Rust core that ships as a Python wheel via PyO3. If you're building a pure Rust application and want an agent framework in your binary, look at AutoAgents (Rust agent framework with role-based multi-agent), rig (provider abstraction + RAG primitives in Rust), or mistral.rs (local inference engine). Different audience, different scope.

f3dx is not an inference engine. Use vLLM, TGI, mistral.rs, llama.cpp, or any OpenAI-compatible endpoint underneath; f3dx talks to them.

f3dx is not a multi-agent orchestration framework. It is the runtime layer below frameworks like pydantic-ai, LangChain, LlamaIndex, CrewAI, AutoGen.

Adapter packages

# pip install f3dx[openai-compat]
from f3dx.compat import OpenAI, AsyncOpenAI    # subclass openai.OpenAI / openai.AsyncOpenAI
import openai
client = OpenAI(api_key=...)
isinstance(client, openai.OpenAI)               # True — passes isinstance checks in
                                                # instructor, litellm, smolagents, langchain
out = client.chat.completions.create(...)       # routes through Rust, returns
                                                # openai.types.chat.ChatCompletion

# pip install f3dx[pydantic-ai]
from f3dx.pydantic_ai import openai_model, F3dxCapability
from pydantic_ai import Agent
cap = F3dxCapability()
agent = Agent(openai_model('gpt-4', api_key=...), capabilities=[cap])
result = await agent.run('hi')                  # f3dx-routed HTTP, capability counts requests

# pip install f3dx[langchain]
from f3dx.langchain import ChatOpenAI
llm = ChatOpenAI(model='gpt-4', api_key=...)    # subclass of langchain_openai.ChatOpenAI
msg = llm.invoke('hi')                          # sync + ainvoke both routed via f3dx

What's not here yet

  • Gemini adapter (Phase C.2)
  • f3dx.pydantic_ai.anthropic_model — needs the AsyncAnthropic compat shim (next release)
  • Parent-child trace context propagation between AgentRuntime span and HTTP child spans (needs Python-side context bridge)
  • jsonschema validation in validate_json mode (V0 only checks parseable JSON; Pydantic schema check coming)
  • True fail-fast incremental JSON validation (V0 validates at terminal; V0.2 will use XGrammar as the streaming validator backend)
  • Arrow trace store + parquet/DuckDB sinks (V0.1 of Phase G)
  • langchain-f3dx standalone PyPI package per LangChain partner-package convention (today the integration ships as the f3dx[langchain] extra; standalone-package split happens before LangChain partner-registry submission)
  • Public PyPI release (gated only on PyPI trusted-publisher config — see release workflow)

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 Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

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

f3dx-0.0.5-cp310-abi3-win_amd64.whl (2.4 MB view details)

Uploaded CPython 3.10+Windows x86-64

f3dx-0.0.5-cp310-abi3-musllinux_1_2_x86_64.whl (2.6 MB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ x86-64

f3dx-0.0.5-cp310-abi3-musllinux_1_2_aarch64.whl (2.5 MB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ ARM64

f3dx-0.0.5-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.4 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ x86-64

f3dx-0.0.5-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (2.3 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ARM64

f3dx-0.0.5-cp310-abi3-macosx_11_0_arm64.whl (2.2 MB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

f3dx-0.0.5-cp310-abi3-macosx_10_12_x86_64.whl (2.3 MB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

File details

Details for the file f3dx-0.0.5-cp310-abi3-win_amd64.whl.

File metadata

  • Download URL: f3dx-0.0.5-cp310-abi3-win_amd64.whl
  • Upload date:
  • Size: 2.4 MB
  • Tags: CPython 3.10+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for f3dx-0.0.5-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 33ad25ac89af7fe34b5a99240662645b4947e0062b37d6594dce785a88cfa5be
MD5 93c6a34159aefdc16a976e8b4388b38a
BLAKE2b-256 e6f2955a9af5103b112080c5f34f46cfbdba46faea51c9d2ffaf910b1d36d299

See more details on using hashes here.

Provenance

The following attestation bundles were made for f3dx-0.0.5-cp310-abi3-win_amd64.whl:

Publisher: release.yml on smigolsmigol/f3dx

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file f3dx-0.0.5-cp310-abi3-musllinux_1_2_x86_64.whl.

File metadata

  • Download URL: f3dx-0.0.5-cp310-abi3-musllinux_1_2_x86_64.whl
  • Upload date:
  • Size: 2.6 MB
  • Tags: CPython 3.10+, musllinux: musl 1.2+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for f3dx-0.0.5-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 05e8e6224891def9de56cebf9457955fbae3758011953d601180f16e6f2bde0c
MD5 47421ec2eebdf78402274568d08143b1
BLAKE2b-256 266457db5ffd5c7643a6a5426456108ebe953a7f98ebe7d3f9836add14768f34

See more details on using hashes here.

Provenance

The following attestation bundles were made for f3dx-0.0.5-cp310-abi3-musllinux_1_2_x86_64.whl:

Publisher: release.yml on smigolsmigol/f3dx

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file f3dx-0.0.5-cp310-abi3-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for f3dx-0.0.5-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 5d4a441a73455ed21f6ad05f25fff1cfd6fa348e2e20a73287f2cb6168b7e951
MD5 e1261765545f0ed740b8d3f96107084d
BLAKE2b-256 37bdf82602d19987e3065a6394560acad947799a2e3bb41b512287f8b7f1d4fe

See more details on using hashes here.

Provenance

The following attestation bundles were made for f3dx-0.0.5-cp310-abi3-musllinux_1_2_aarch64.whl:

Publisher: release.yml on smigolsmigol/f3dx

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file f3dx-0.0.5-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for f3dx-0.0.5-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8196873261264802383e7f3bd0ea4f8733bfcbda5c38e52783f20f5bcb597cb8
MD5 2455e7cc38a52a500acc771bae534b64
BLAKE2b-256 318772dbd6e5e529d836eac62b817bce4f42fccb05559d5493ded8fff2ed831b

See more details on using hashes here.

Provenance

The following attestation bundles were made for f3dx-0.0.5-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yml on smigolsmigol/f3dx

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file f3dx-0.0.5-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for f3dx-0.0.5-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 8a781e691fa8bdcea2369a1d2304dd722a96b5e5458b1756224116aa407b4d1d
MD5 d1c89582dd9d4eb261a5e63388f596b9
BLAKE2b-256 2b3c5a9a6b64e47e3c4279748c849489c6b43da56be09cb805dee081b46ef90b

See more details on using hashes here.

Provenance

The following attestation bundles were made for f3dx-0.0.5-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: release.yml on smigolsmigol/f3dx

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file f3dx-0.0.5-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

  • Download URL: f3dx-0.0.5-cp310-abi3-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 2.2 MB
  • Tags: CPython 3.10+, macOS 11.0+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for f3dx-0.0.5-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 13b3a1944d6106c53e816fb9353a6766c90b53851ffd91f8a11966b916a73282
MD5 c8859f9ca423ad5cbe87c069f218e51b
BLAKE2b-256 b1ecd50baef4dc9ffc90a1409508d18b28986504b203957079b67b9e5bcc169b

See more details on using hashes here.

Provenance

The following attestation bundles were made for f3dx-0.0.5-cp310-abi3-macosx_11_0_arm64.whl:

Publisher: release.yml on smigolsmigol/f3dx

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file f3dx-0.0.5-cp310-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for f3dx-0.0.5-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 d413330fcda7456038533946681aace928a9037f1aa52a2638c553830c7df382
MD5 c2da0e3aaab9cd50fe8b566c0c5ef251
BLAKE2b-256 8113c20a6fe412aa7f3c5062c359db74bf5f153c57e70e372000f81e3fa50375

See more details on using hashes here.

Provenance

The following attestation bundles were made for f3dx-0.0.5-cp310-abi3-macosx_10_12_x86_64.whl:

Publisher: release.yml on smigolsmigol/f3dx

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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