New PR in mlx boost speed :)

#1
by sb6666 - opened

This model and this PR https://github.com/ml-explore/mlx-lm/pull/454

mlx_lm.generate --model nightmedia/Qwen3-Next-80B-A3B-Instruct-qx64-mlx --max-tokens 20000
--prompt "If you were to write an Agnostic Agent as a CLI for a user to interact with Ollama API, and want to use FP, what language would you prefer"

If I were to write an Agnostic Agent as a CLI to interact with the Ollama API using Functional Programming (FP) principles, I would prefer:

Haskell


✅ Why Haskell?

1. Pure Functional Programming by Design

Haskell enforces immutability, pure functions, and explicit side effects via the IO monad — perfect for modeling an agent that:

  • Receives user input (side effect)
  • Makes HTTP requests to Ollama (side effect)
  • Processes responses (pure logic)
  • Outputs results (side effect)

This cleanly separates logic (pure FP) from effects (IO), making the agent “agnostic” — its core logic is testable, composable, and free from hidden state.

2. Strong Type System + Algebraic Data Types (ADTs)

You can model the Ollama API interactions with precise types:

data ModelRequest = ModelRequest
  { model :: String
  , prompt :: String
  , options :: Maybe Options
  }

data ModelResponse = ModelResponse
  { response :: String
  , done :: Bool
  , context :: [Int]
  }

data AgentAction
  = Ask ModelRequest
  | ListModels
  | Stop
  deriving (Show, Eq)

This makes the agent’s behavior explicit, self-documenting, and compile-time safe.

3. Excellent HTTP & JSON Support

Libraries like:

…make calling Ollama’s /api/generate, /api/tags, etc., clean and type-safe.

4. CLI Parsing with FP Principles

Use optparse-applicative — a composable, declarative CLI parser built on monoids and applicatives:

main :: IO ()
main = execParser opts >>= runAgent
  where
    opts = info (helper <*> agentParser) ...
    agentParser = Ask <$> modelArg <*> promptArg
                  <|> ListModels
                  <|> Stop

5. Agnostic by Design

The core agent logic (e.g., “respond to user input with model output”) is pure:

runAgent :: AgentAction -> IO ()
runAgent (Ask req) = do
  resp <- callOllama req  -- IO action
  putStrLn (response resp)

-- callOllama is the only impure function.
-- Everything else: parsing, validation, response formatting — pure.

This makes the agent agnostic to environment, testing, or UI — you can swap the CLI for a web UI or test suite without changing logic.

6. Immutability = No Hidden State

An “Agnostic Agent” implies no hidden state or global variables. Haskell enforces this. Each interaction is a pure transformation from input → output, with effects isolated.

7. Elegant Composition & Pipeline Thinking

You can compose the agent as a pipeline:

User Input → Parse → Validate → Transform to Ollama Request → Call API → Parse Response → Format Output → Print

Each step is a pure function. Easy to test, reuse, and reason about.


🆚 Why Not Other FP Languages?

Language Pros Cons for This Use Case
Elm Great for UIs No CLI/HTTP client ecosystem; not for backend/CLI
F# Great .NET integration Less pure FP; mutable by default; Ollama not a .NET focus
Scala Powerful FP + JVM Overkill; complex build; JVM startup time hurts CLI
PureScript Haskell-like, JS target Weak CLI/HTTP tooling; not ideal for native CLI
Rust + FP libraries Fast, safe Not FP-first; requires fighting ownership for pure style
Clojure Great for REPL/CLI Dynamic typing; less type safety for API contracts

Haskell strikes the best balance of:

  • Pure FP discipline
  • Strong typing for API safety
  • Mature CLI/HTTP ecosystem
  • No runtime overhead (native binaries via stack or cabal)

🚀 Bonus: Example Flow

main :: IO ()
main = do
  input <- getLine
  let action = parseInput input  -- pure
  case action of
    Ask req -> do
      resp <- callOllama req     -- IO
      putStrLn $ formatResponse resp
    ListModels -> do
      models <- listAvailableModels
      mapM_ putStrLn models
    Stop -> return ()

All logic is testable without IO, and the CLI is just a thin shell.


✅ Conclusion

Haskell is the ideal language to build an Agnostic Agent CLI for Ollama using Functional Programming — because it enforces purity, composition, and type safety, while offering mature tooling for CLI, HTTP, and JSON. The result is a robust, testable, maintainable, and truly agnostic system.

You get an agent that doesn’t care if it’s called from a terminal, a test suite, or a web hook — because its soul is pure.

Prompt: 42 tokens, 291.369 tokens-per-sec
Generation: 1205 tokens, 70.824 tokens-per-sec
Peak memory: 53.204 GB

Hardware: Base M3 Ultra 96GB RAM

Thank You for great model :)

Thank you, this means a lot to me, and really appreciate the confirmation :)

Sign up or log in to comment