Goal Encoding in LLMs

Arnab Sen Sharma, Eric Todd, Sheridan Feucht, Andy Arditi, Rohit Gandikota, Natalie Shapira, Gabriele Sarti, Constanza Fierro, Lisa Schut, David Bau

Do LLMs have goals?

Language models now carry out tasks that unfold over thousands of tokens, and they behave as if they were pursuing a goal. We ask whether that behavior is backed by an explicit goal encoding inside the model’s computations.
We fix three criteria that functionally define a goal: (i) pre-commitment, (ii) plasticity, and (iii) persistence. We find an encoding that meets these criteria in the outputs of a sparse set of attention heads. We further ask how a depth-bounded transformer manages to keep such a goal alive across a long generation without running out of layers.

What is a goal?

Inspired by Bratman’s planning theory, we treat a goal as a functional state with the three properties below.

Pre-commitment

> no coffee coffee

The target state is settled before the action that realizes it begins.

Plasticity

press pods INSTANT instant

The same goal can be realized by different means, as the environment demands.

Persistence

released boil grind pour done!

It is sustained while the action is carried out, and released once it is done.

In a controlled coding setup, we find an encoding that meets all three criteria in the outputs of a sparse set of attention heads.
This encoding can be transplanted into a different context to verbalize the upcoming action in natural language and trigger its implementation in a different programming language. See the figure below, and browse the demo readouts →

GoalScope schema and readout results
GoalScope. (a) The goal heads’ outputs at one token form the encoding vg. (b) We plant this encoding into a neutral probe: (c.1) asked to describe what it is doing, the model verbalizes the next action; and (c.2) in an information-less C++ stub, the LM implements the same sub-goal with a different sequence of tokens.
Right: (c.1) faithfulness measures whether the natural language readout is aligned with the LM's next action; causality (c.2) measures whether the encoding can trigger the same action in a different environment (programming language).

How does a depth-bounded transformer LM achieve persistence?

Transformer LMs have a limited number of layers, and the only way they can pool information from a previous token is through the attention mechanism, which costs a layer. How, then, does a transformer LM keep a goal alive in its computation for many tokens?
We find that instead of carrying a goal encoding forward across the generated tokens, the LM frequently re-reads the goal from the task specification. Then the LM decides the next action by comparing the re-fetched goal with the progress made so far. We call this the non-recurrent goal-seeking account (NRGS) of how the transformer LM achieves persistence.

Non-recurrent implementation of goal-pursuit in a transformer LM
Non-recurrent implementation of goal-pursuit in a transformer LM. A goal such as implementing merge sort decomposes into sub-goals, each realized as a sequence of tokens. (i) An idealized agent forms an intention, acts on it until it is done, and moves on. (ii) A transformer cannot carry that commitment forward through a fixed number of layers, so at each step it re-reads the goal from the task span, computes its progress so far, and compares the two to pick the next token.
The LM frequently re-reads the goal from the task specification. When the LM is in the middle of pursuing a goal, we can control what it reads from the context using the goal heads, and the LM redirects to implement the next action of the transplanted goal. §5.1.1 · App. I.1
The same computational motif, implemented by the same goal heads, works at different levels of the hierarchy. The same intervention can redirect a sub-sub-goal, a sub-goal, and a broader goal, across very different coding situations. §5.1.1 · App. I.1
KV transfer of a sub-goal from a C++ prompt into a Python prompt, and the swapped rows of one goal head's KV cache
Sub-goal (Fig. 5). At the " =" pivot the goal heads read the source’s task span (red) instead of the destination’s (green). The model implements the source next action, in the destination’s language. The GoalScope readout also flips with it.
The task span, not the code progress, dictates the LM’s next operation. The next action is pre-committed in the earlier generated code. A goal encoding extracted from pre-implementation tokens can be decoded via GoalScope, and transplanting it into a different environment (C++) can trigger its execution. However, we find that the LM largely ignores this pre-commitment and instead re-reads the goal from the task span to decide the next operation. App. J · Fig. 27
Transplanting the task span vs. the code-progress span from a source run into a destination run
Task span vs. code progress. The two prompts share the first two sub-tasks, whose code is prefilled in the prompt (underlined), and differ only in the third. In the patched run we transplant the residual states of the source’s task span, its code-progress span, or both, and keep the destination’s states for everything else before the " =" pivot. Right: how often the model then implements the source’s next sub-task.
Progress dictates the next action (among other things). The goal heads’ queries carry part of the “what is already done” signal. Transferring them can redirect the model to implement the next sub-goal in the destination list that hasn't been completed in the source prompt yet. However, this explains only 57% of the cases in our evaluation set. Through targeted interventions, we find non-trivial evidence for other potential computations, such as the order of the tasks and the number of completed tasks, that also participate in selecting the next action. §5.1.2 · App. I.2
Query transfer: swapping only the goal heads' query at the pivot, and the effect of the source frontier's position
Query transfer. Left: the source has done a and b, the destination only a. At the " =" pivot we swap in only the goal heads’ query from the source run, the side that should carry “what is already done”. The patched model skips ahead to the destination’s third task. Right: the swap works much better when the source frontier sits at the same position in its task list as the patched target (order-matched) than when it does not (order-diff), so progress is not the only cue: position matters too.

Beyond Code

The goal heads were found on code, but GoalScope reads intentions elsewhere too, with no re-training.

GoalScope readouts in few-shot ICL and in an emergently misaligned model
GoalScope beyond code. Left: GoalScope can read out the implicit rule in few-shot ICL prompts. Right: the emergently misaligned model’s readouts at the start of its response.

Explore more examples in the demo: ICL → Chat (EM) →

A strip of four panels with shapes and letters; the star panel is highlighted What is the letter inside the star?
Answer: T
Non-recurrent progression of multi-step task in VLM setting! See our parallel work.

Is "goal" the right term for this encoding?

By our criteria, the encoding is pre-committed (decodable before the action) and plastic (portable to another environment). It is also persistent (sustained throughout the action). However, transformer LMs achieve persistence through frequent re-derivation rather than carrying a single running state.
Does this count as a "goal"? The answer depends on whether there is a requirement on the mechanical implementation of persistence: if a goal must be a single state that survives the whole action, then this encoding does not qualify. But if we don’t care about the implementation, and only care whether the goal is present when it causes action, then this encoding qualifies. We leave the semantics of whether this is a “goal” or not to the reader.

How to cite

The paper is available on arXiv.

bibliography

Arnab Sen Sharma, Eric Todd, Sheridan Feucht, Andy Arditi, Rohit Gandikota, Natalie Shapira, Gabriele Sarti, Constanza Fierro, Lisa Schut, David Bau. “Goal Encoding in LLMs.” arXiv preprint arXiv:2611.17297, 2026.

bibtex

@misc{sensharma2026goals,
  title         = {Goal Encoding in {LLMs}},
  author        = {Sen Sharma, Arnab and Todd, Eric and Feucht, Sheridan and Arditi, Andy and
                   Gandikota, Rohit and Shapira, Natalie and Sarti, Gabriele and Fierro, Constanza and
                   Schut, Lisa and Bau, David},
  year          = {2026},
  eprint        = {2611.17297},
  archivePrefix = {arXiv},
  primaryClass  = {cs.CL},
  url           = {https://arxiv.org/abs/2611.17297}
}