Name: Towards AI Legal Name: Towards AI, Inc. Description: Towards AI is the world's leading artificial intelligence (AI) and technology publication. Read by thought-leaders and decision-makers around the world. Phone Number: +1-650-246-9381 Email: pub@towardsai.net
228 Park Avenue South New York, NY 10003 United States
Website: Publisher: https://towardsai.net/#publisher Diversity Policy: https://towardsai.net/about Ethics Policy: https://towardsai.net/about Masthead: https://towardsai.net/about
Name: Towards AI Legal Name: Towards AI, Inc. Description: Towards AI is the world's leading artificial intelligence (AI) and technology publication. Founders: Roberto Iriondo, , Job Title: Co-founder and Advisor Works for: Towards AI, Inc. Follow Roberto: X, LinkedIn, GitHub, Google Scholar, Towards AI Profile, Medium, ML@CMU, FreeCodeCamp, Crunchbase, Bloomberg, Roberto Iriondo, Generative AI Lab, Generative AI Lab VeloxTrend Ultrarix Capital Partners Denis Piffaretti, Job Title: Co-founder Works for: Towards AI, Inc. Louie Peters, Job Title: Co-founder Works for: Towards AI, Inc. Louis-FranΓ§ois Bouchard, Job Title: Co-founder Works for: Towards AI, Inc. Cover:
Towards AI Cover
Logo:
Towards AI Logo
Areas Served: Worldwide Alternate Name: Towards AI, Inc. Alternate Name: Towards AI Co. Alternate Name: towards ai Alternate Name: towardsai Alternate Name: towards.ai Alternate Name: tai Alternate Name: toward ai Alternate Name: toward.ai Alternate Name: Towards AI, Inc. Alternate Name: towardsai.net Alternate Name: pub.towardsai.net
5 stars – based on 497 reviews

Frequently Used, Contextual References

TODO: Remember to copy unique IDs whenever it needs used. i.e., URL: 304b2e42315e

Resources

Free: 6-day Agentic AI Engineering Email Guide.
Learnings from Towards AI's hands-on work with real clients.
πŸ¦€ Building AI Agents in Rust – part 11
Latest   Machine Learning

πŸ¦€ Building AI Agents in Rust – part 11

Last Updated on July 23, 2026 by Editorial Team

Author(s): Enzo Lombardi

Originally published on Towards AI.

Crossing into C

Part 10 got Eugene talking to DwarfStar without a socket, but it didn’t get rid of the process boundary. DwarfStarProvider still spawns ds4 as a child, writes a line to its stdin, and reads lines back until a ds4> prompt reappears in stdout. That works, and it’s honest about its own limit: it’s parsing terminal output that was never meant to be a wire format, and it trusts a banner string to mean β€œthis turn is done.” The REPL keeps its KV cache warm across turns, which was the whole point, but Eugene still can’t ask it for a sampling temperature, a token’s logprob, or a clean signal that generation actually finished versus the pipe just going quiet for a moment.

πŸ¦€ Building AI Agents in Rust – part 11

This post shows how to replace the subprocess/REPL text protocol with direct in-process FFI by using DwarfStar’s public C header boundary (ds4.h). It explains that DwarfStar exposes an engine and per-session KV-cache timeline, including prefix-aware session sync that reuses KV state by diffing the provided token prefix against the live checkpoint. With that seam, the author builds a Rust Provider that calls ds4_engine/session functions directly (no pipes), compiles the required C/Objective‑C sources into a Rust binary via build.rs (targeting Metal/CUDA as DwarfStar recommends), and wraps unsafe FFI narrowly to ensure resources are freed exactly once and C-side errors are surfaced as Rust Result failures. The resulting complete() implementation ends generation using the engine’s EOS token (not prompt strings), gaining token-level sampling control and explicit cache-reuse semantics while paying costs in C build integration and carefully pinned/unstable ABI assumptions. The article closes by emphasizing that the agent loop remains unchanged across integration strategiesβ€”HTTP, subprocess, or FFIβ€”because the Provider trait isolates transport and execution details.

Read the full blog for free on Medium.

Join thousands of data leaders on the AI newsletter. Join over 80,000 subscribers and keep up to date with the latest developments in AI. From research to projects and ideas. If you are building an AI startup, an AI-related product, or a service, we invite you to consider becoming aΒ sponsor.

Published via Towards AI


Towards AI Academy

We Build Enterprise-Grade AI. We'll Teach You to Master It Too.

15 engineers. 100,000+ students. Towards AI Academy teaches what actually survives production.

Start free β€” no commitment:

β†’ 6-Day Agentic AI Engineering Email Guide β€” one practical lesson per day

β†’ Agents Architecture Cheatsheet β€” 3 years of architecture decisions in 6 pages

Our courses:

β†’ AI Engineering Certification β€” 90+ lessons from project selection to deployed product. The most comprehensive practical LLM course out there.

β†’ Agent Engineering Course β€” Hands on with production agent architectures, memory, routing, and eval frameworks β€” built from real enterprise engagements.

β†’ AI for Work β€” Understand, evaluate, and apply AI for complex work tasks.

Note: Article content contains the views of the contributing authors and not Towards AI.