llmcpp-lambda-captures
Table of Contents
Lambda captures (llmcpp)
Lambda captures determine which enclosing values a generated body can use. The tool-server fixture captures the local counter by reference:
int hits = 0; // Capture and increment the local hit counter. auto count = __llm__ [&]() { Increment hits. }; count();
The matching mock submits ++hits;. Because the lambda captures by reference, calling it modifies the enclosing counter rather than a private copy.
The compiler exposes capture information through the task and context tools. The agent must work with the written capture list, rather than assuming access to every surrounding variable. The resulting closure follows ordinary C++ lifetime rules: capturing by reference does not extend the referent's lifetime. A generated body changes the statements, not the meaning of the capture.
Source: 06_tools.cpp.
llmcpp-lambda-captures.md · Last modified: by 127.0.0.1
