Computation Augmented Generation & MCP

Rick Hennigan, Wolfram Research

#WolframTechConf

Topics

Computation Augmented Generation (CAG)

CAG context vs traditional RAG

CAG context vs tool calling

CAG component APIs (coming soon)

Agent One: A full all-in-one solution

An LLM API with CAG built-in

Designed for compatibility

Model Context Protocol (MCP)

Some examples of MCP clients

Two types of Wolfram MCP servers (remote + local)

MCP limitations compared to full CAG

MCP example use cases

Computation Augmented Generation (CAG)

What is CAG?

We’ll first look at an example of traditional retrieval augmented generation (RAG) and compare it to CAG.

CAG context vs traditional RAG

RAG context generation

RAG is used to provide relevant context to the LLM so it can answer accurately. This is often implemented via SemanticSearch, which is built from static documents or pieces of text.

LLMPromptGenerator to implement documentation RAG:

docRAG=LLMPromptGenerator[Wolfram`Chatbook`RelatedDocumentation[#,"Prompt"]&]

Generates relevant documentation snippets from the user context:

docRAG["How can I give Wolfram super powers to Claude?"]

What it looks like in practice:

LLMSynthesize["How can I give Wolfram super powers to Claude?",LLMEvaluator-><|"Prompts"->docRAG|>]//({{"[◼]", "ImportMarkdownString" }})

Side note

Prompt generators and tools used by Notebook Assistant will soon be available programmatically:

LLMSynthesize["How can I give Wolfram super powers to Claude?",LLMEvaluator->"NotebookAssistant"]//({{"[◼]", "ImportMarkdownString" }})

CAG context vs traditional RAG

CAG context generation

Unlike RAG, this generates new content at runtime instead of being built from fixed static text.

LLMPromptGenerator that implements Wolfram|Alpha CAG:

waCAG=LLMPromptGenerator[Wolfram`Chatbook`RelatedWolframAlphaResults[#,"Prompt"]&]

Generates relevant Wolfram|Alpha results from the user context:

waCAG["Which generates more geothermal power, Iceland or New Zealand?"]

What it looks like in practice:

LLMSynthesize["Which generates more geothermal power, Iceland or New Zealand?",LLMEvaluator-><|"Prompts"->waCAG|>]//({{"[◼]", "ImportMarkdownString" }})

CAG context vs tool calling

How is this different from calling Wolfram|Alpha via LLMTool?

LLMs are often overconfident in their knowledge

Tools are called at the LLM’s discretion

It may try to answer without verifying via a tool call

You then need to do the extra work to verify the result

Example

Here is an LLMTool for calling Wolfram|Alpha:

waTool=Wolfram`Chatbook`$DefaultTools["WolframAlpha"]

The LLM can decide not to use it:

res=LLMSynthesize["Give me a table comparing the five most popular movies released in 1999",All,LLMEvaluator-><|"Tools"->waTool|>];

res["CompletionText"]//({{"[◼]", "ImportMarkdownString" }})

Here we see it made no tool calls, and therefore might have just made up the answer:

res["ToolRequests"]

CAG example for comparison

res=LLMSynthesize["Give me a table comparing the five most popular movies released in 1999",All,LLMEvaluator-><|"Prompts"->waCAG|>];

res["CompletionText"]//({{"[◼]", "ImportMarkdownString" }})

res["PromptText"]

CAG component APIs (coming soon)

cagAPI[name_String,query__]:=
URLRead[HTTPRequest[
"https://services.wolfram.com/api/cag/v1/"<>name,
<|"Body"->ExportByteArray[<|query|>,"RawJSON"],|>
],"Body"];

Context generation

The same CAG context generator available via API:

cagAPI["WolframAlphaContext",<|"context"->"Which generates more geothermal power, Iceland or New Zealand?"|>]

Documentation context:

cagAPI["WolframLanguageHints",<|"context"->"How can I give Wolfram super powers to Claude?"|>]

Tool calling

Use these along with the context generation APIs for best results.

Wolfram Language evaluation:

cagAPI["WolframLanguageCompute",<|"code"->"Prime[123456789]"|>]

Wolfram Alpha query results:

cagAPI["WolframAlphaResult",<|"input"->"123456789th prime number"|>]

Agent One: A full all-in-one solution

An LLM API with CAG built-in

result=ImportByteArray[
URLRead[
HTTPRequest[
CloudObject["user:cag-admin/CAG/api/1.0/AgentOne"],
<|
"Body"->ExportByteArray[<|
"messages"->{<|
"role"->"user",
"content"->"What's the 123456789th prime?"
|>}
|>,"RawJSON"],
"Method"->"POST"
|>
],"BodyByteArray"
],"RawJSON"]

result[["choices",1,"message","content"]]//({{"[◼]", "ImportMarkdownString" }})

Designed for compatibility

Example config for LibreChat:

FilePrint["LibreChat/librechat.yaml"]

SystemOpen[URLBuild["http://localhost:3080/c/new",{"endpoint"->"Wolfram","model"->"AgentOne"}]]

Model Context Protocol (MCP)

A standardized way for LLM-based applications to connect to tools and other resources

Any application with MCP support can now easily connect with Wolfram tools

Some examples of MCP clients

Chat interfaces

Claude Desktop

LibreChat

IDEs

Visual Studio Code

Cursor

Command line coding agents

Claude Code

Gemini CLI

Codex

Two types of Wolfram MCP servers

Remote (coming soon)

Does not require a Wolfram kernel to be installed

Uses CAG APIs to run tools remotely

Available via Wolfram MCP Service subscription

No local file access or persistent kernel sessions

Fixed set of predefined tools

Local (available now)

Runs locally via a Wolfram kernel on your machine

Can be used to interact with your files, e.g. analyze data, generate reports, etc.

Persistent Wolfram Language kernel session

Can run fully custom tools that you implement yourself (LLMTool) or select from existing named configurations

Does not require LLMKit subscription, but some of the predefined tools can utilize it for improved functionality

MCP limitations compared to full CAG

MCP does not have anything resembling LLMPromptGenerator

Context generation must be done via tool calls

This means you usually need to prod the model to get context

MCP example use cases

Chat apps

({{, InstallMCPServer }})["ClaudeDesktop"]

IDEs

({{, InstallMCPServer }})["Cursor","WolframLanguage"]

Coding agents

Export["ComputationalFitness/.mcp.json",({{, MCPServerObject }})["WolframLanguage"]["JSONConfiguration"],"String"]

Thanks, Claude

The end

Questions?