TensorCode

Written code and trained models in one program, with a line between them you can move. Open source, for Python and TypeScript.


presentation slides
TensorCode title slide with the github.com/limboid/tensorcode link
Capabilities: encode and decode arbitrary objects, develop and evolve multi-modal models, runtime code generation, differentiable programming, develop cognitive architectures
Reinforcement-learning loop diagram: an agent and a world exchanging action and observation
Hand-written step() function manually encoding inputs, deciding, and decoding the action tensor back to Python objects
Arbitrary object encoding and decoding with tc.encode and tc.decode
The fully hand-written step() function shown in full
The same step() function rewritten compactly with tc.encode and tc.decode
TensorCode step() alongside the Observation and Action class definitions it is inferred from
The same step() unchanged while Observation and Action grow extra typed fields
Observation and Action using a Union of Literals to type the direction field
Action using a tuple of direction literals, still decoded by the unchanged step()
How tc.encode turns an Observation object into query and key-value tensor pairs
Tensor-shape walkthrough showing how encoded objects batch across vision, text, and energy inputs
Runtime Code Generation: tc.exec, tc.select, tc.create, and tc.patterns.Factory examples
Differentiable Programming: @tc.If / .Elif / .Else decorators making control flow differentiable
Cognitive Architecture Development diagram: multi-modal fusion, memory, prediction, action, and training loss terms
Cognitive-architecture step() function, full listing
Cognitive-architecture step() highlighting the recurrent input and memory reads
Cognitive-architecture step() highlighting the global-workspace perception state
Cognitive-architecture step() highlighting the prediction stage
Cognitive-architecture step() highlighting the output and memory writes
Cognitive-architecture step() highlighting the training feedback and loss terms
Cognitive-architecture step() with the return statement highlighted
Closing capabilities slide with the github.com/limboid/tensorcode link

Problem

Building a multi-modal model means writing the same plumbing over and over: pick an encoder per input type, concatenate latents, run a decision network, then hand-decode the output tensor back into the Python objects the rest of your program expects. Every time the Observation or Action shape changes, that glue code changes with it. You end up thinking in tensors when you'd rather be thinking in objects, patterns, and architecture.

Solution

TensorCode introduces simple abstractions and functions for encoding and decoding arbitrary Python objects, differentiable programming (including differentiable control flow), and intelligent object creation, selection, and other runtime code-generation features.

Rather than just think about the underlying mathematical objects, TensorCode's Programming 2.0 paradigm gives your brain the abstractions it needs to apply ordinary software-engineering patterns — encapsulation, abstraction, composition, design patterns, and the concepts derived from them — to your underlying problem. If you're developing a multi-modal agent, building the next generation of end-to-end differentiable cognitive architectures, or just adding magic to an existing program, TensorCode may fit right into your stack.

import tensorcode as tc

def step(self, obs: Observation) -> Action:
    latent = tc.encode(obs)
    action = self.mlp(latent)
    return tc.decode(action, Action)

tc.encode turns any annotated object into a latent tensor; tc.decode turns a tensor back into a typed object. When the Observation or Action definition grows a new field, the encode and decode calls don't change — TensorCode infers the wiring from the type annotations.

How

The framework centers on a few primitives:

  • tc.encode / tc.decode — bidirectional conversion between arbitrary Python objects and tensors, driven by type annotations (Image, str, float, Union, Literal, tuples, nested classes).
  • Runtime code generation — tc.exec, tc.select, tc.create, and tc.patterns.Factory let a program describe what it wants in natural language and have TensorCode produce, choose, or run the object at runtime.
  • Differentiable programming — tc.If / .Elif / .Else decorators make control flow differentiable, so gradients flow through branches the same way they flow through arithmetic.
  • Cognitive-architecture building blocks — multi-modal fusion, short- and long-term memory, a global-workspace prediction loop, and composable loss terms for training the whole thing end to end.

Presentation

The deck below walks from a hand-wired RL agent to the same agent expressed with TensorCode primitives, then through runtime code generation, differentiable control flow, and a full differentiable cognitive architecture. The full deck is also available as a downloadable PDF.

Status

TensorCode came in two stretches. The first ran from April to December 2022 under Limboid: the original implementation is still at Limboid/tensorcode, the project notebook holds its design notes, and the deck above is from that period. By the end of it, encoding/decoding and runtime code generation were the furthest along; differentiable control flow and reinforcement programming were still in progress.

In September 2026 it came back under TensaCo as a rewrite for Python and TypeScript, at TensaCo/tensacode, published as tensorcode on PyPI and npm, with live demos at tensorcode.dev.

Lessons

The recurring lesson is that the bottleneck in multi-modal ML isn't the math — it's the abstractions. Giving the encode/decode boundary a name, and letting type annotations carry the wiring, is what makes the software-engineering toolkit (composition, design patterns, encapsulation) usable on a learning system at all.

Related

TensorCodejnumpyjnumpyFull Stack Artificial IntelligenceFull Stack Artificial Intel…The Tensor ComputerThe Tensor ComputerA Differentiable von Neumann ComputerA Differentiable von Neuman…notion-vibestartupnotion-vibestartupRecursive Omnimodal Video Action ModelRecursive Omnimodal V…ComputatrumComputatrumyt2ctxyt2ctxThe Multi-Agent Network (MAN)The Multi-Agent Netwo…MPNetsMPNetsFull-Stack Artificial IntelligenceFull-Stack Artificial…Software Engineering After AgentsSoftware Engineerin…belief-graph-orchestratorbelief-graph-orches…Teaching Computers to Use ComputersTeaching Computers …ComputerworldComputerworldChem-0Chem-0The Cortical CanvasThe Cortical CanvasLooped Attention in Video Diffusion TransformersLooped Attention in…RRP: relational attention for a structured latent packetRRP: relational att…Attention Is All You NeedAttention Is All Yo…Language Models are Few-Shot LearnersLanguage Models are…Pretrained Transformers as Universal Computation EnginesPretrained Transfor…AI systems engineeringAI systems engineer…👩🏽‍🌾 The Fertile Crescent👩🏽‍🌾 The Fertile…ComputatrumComputatrumDRAG TO ORBIT · SCROLL OR PINCH TO ZOOM