Class AdHocAgentState
setVariable walks strictly up the parent chain, and the scope execution is
an ancestor of every ad hoc child — and in an agentic scope the children are
the tools. The execution returned here is their sibling instead, so a child
writing the same name creates its own variable at the process instance. Event scope
keeps it out of child iteration and completion checks, and has it removed with the
scope like any event scope -- except when the scope is kept for compensation
(CIB7-2154).
Deliberately separate from the state execution
AdHocSubProcessActivityBehavior keeps for its adHocActivated marker:
sharing would tie the engine's "has this scope ever started anything" answer to
whether an agent happened to store something. The cost is one further execution per
instance.
What only a step writes is one map, held by the marker variable itself, so a step
writes one variable rather than one per counter (CIB7-2200). It is a TreeMap of
JDK types, serialized as Java whatever the engine's default format (see
javaSerialized(java.lang.Object)): every engine can read it, Cockpit shows it as a map, and
its bytes depend only on what it holds. That matters because the engine serializes an
object it read again when the command ends and writes it back if the bytes differ; a
hash map can come back with another table size, which would turn a read into a write.
For the same reason the map read is never changed in place: updateState(org.cibseven.bpm.engine.impl.pvm.delegate.ActivityExecution, java.lang.String, java.lang.Object)
builds a new one.
Within a command the changes collect, and the map is written once, when the command
closes, if it then differs from what was stored. A step changes the map several times
(the turn, the model call, every tool call, the read position in the results), and each
write of a variable is a history row of its own at history level full. The engine
tells its listeners that a command closes before it flushes, so the write still goes
with the step's transaction; a command that fails drops what collected, as the
transaction does.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intModel calls allowed within one turn — the second bound, and a different one: the turn cap cannot see a model that keeps calling tools and never ends its turn.static final intTurns allowed before the agent must stop.static final intstatic final StringThe layout of the map, kept in it, so a later version can tell an older one.static final Stringcamunda:propertyon the scope overridingDEFAULT_MAX_MODEL_CALLS.static final Stringcamunda:propertyon the scope overridingDEFAULT_MAX_TURNS.static final StringMarks this execution, and holds the map of what only a step writes. -
Method Summary
Modifier and TypeMethodDescriptionstatic intbeginTurn(ExecutionEntity scopeExecution, String turnId) Counts the turnturnIdbelongs to, once, and returns the count.calledThisTurn(ExecutionEntity scopeExecution) The tools the turn now running called, oldest first; empty before its first call.static voidcontinueTurn(ExecutionEntity scopeExecution) The model called tools and answers in a further step of the same turn.static intcountModelCall(ExecutionEntity scopeExecution, String stepId) Counts the model call of the stepstepId, once, and returns the count for the turn.static voidendTurn(ExecutionEntity scopeExecution) The turn is over: the model answered, or a limit ended it.static PvmExecutionImplfind(ActivityExecution scopeExecution) The agent state execution ofscopeExecution, ornullwhen nothing has been stored yet.static ExecutionEntityfindAdHocScope(ExecutionEntity execution) Walks up fromexecutionto the enclosing ad hoc sub process scope, or returnsnullwhen there is none.static PvmExecutionImplfindOrCreate(ActivityExecution scopeExecution) The agent state execution ofscopeExecution, created on first use.static booleanisCompletionRequested(ActivityExecution scopeExecution) WhetherrequestCompletion(org.cibseven.bpm.engine.impl.pvm.delegate.ActivityExecution)was called for this scope.static booleanisTurnInProgress(ExecutionEntity scopeExecution) Whether the next step continues a turn the model has not ended yet.static ObjectValuejavaSerialized(Object value) The value an internal variable of the agent holds: Java-serialized, whatever the engine's default serialization format (CIB7-2800).static intmodelCalls(ExecutionEntity scopeExecution) Model calls in the turn now running, zero before the first one is counted.static intpositiveProperty(ExecutionEntity scopeExecution, String property, int fallback) A positive-integercamunda:propertyof the scope, orfallback.static voidrecordCall(ExecutionEntity scopeExecution, String tool) Records that the turn now running calledtool, and the call was carried out.static voidrequestCompletion(ActivityExecution scopeExecution) Records that the scope should end once nothing is running in it any more.static ObjectstateValue(ActivityExecution scopeExecution, String key) One entry of the state map, ornull.static intturns(ExecutionEntity scopeExecution) Turns taken so far, zero before the first one is counted.static voidupdateState(ActivityExecution scopeExecution, String key, Object value) Sets one entry of the state map;nullremoves it.static voidupdateState(ActivityExecution scopeExecution, Map<String, ?> changes) Sets entries of the state map, anullvalue removing its key, and writes the map once, only if it changed.
-
Field Details
-
STATE_MARKER
Marks this execution, and holds the map of what only a step writes.A fixed marker is needed because some of the state has no fixed variable name — a conversation is keyed by a memory id — so recognition cannot work by looking for the payload.
- See Also:
-
LAYOUT_KEY
The layout of the map, kept in it, so a later version can tell an older one.- See Also:
-
LAYOUT
public static final int LAYOUT- See Also:
-
MAX_TURNS_PROPERTY
camunda:propertyon the scope overridingDEFAULT_MAX_TURNS.- See Also:
-
MAX_MODEL_CALLS_PROPERTY
camunda:propertyon the scope overridingDEFAULT_MAX_MODEL_CALLS.- See Also:
-
DEFAULT_MAX_TURNS
public static final int DEFAULT_MAX_TURNSTurns allowed before the agent must stop.A loop that invokes a language model per turn has no natural end, so an unbounded one is unbounded spend on a bad prompt. The scope's
MAX_TURNS_PROPERTYoverrides it.It stops the agent, not the work the agent already started. Over the cap no model is asked again, but a scope with a child still running is left standing and ends when that child does — ending it there would cancel a task someone may be halfway through, which is the same reason
completeScoperefuses andendOfTurnwaits.- See Also:
-
DEFAULT_MAX_MODEL_CALLS
public static final int DEFAULT_MAX_MODEL_CALLSModel calls allowed within one turn — the second bound, and a different one: the turn cap cannot see a model that keeps calling tools and never ends its turn. Each call is a step of its own (CIB7-2148). The same number bounds the tool calls one answer may ask for.- See Also:
-
-
Method Details
-
find
The agent state execution ofscopeExecution, ornullwhen nothing has been stored yet. Never creates one, so it is safe on a read path.Looks for
STATE_MARKERonly. It must not fall back to the behaviour's variable names — see the class comment. -
requestCompletion
Records that the scope should end once nothing is running in it any more.- See Also:
-
COMPLETION_REQUESTED
-
isCompletionRequested
WhetherrequestCompletion(org.cibseven.bpm.engine.impl.pvm.delegate.ActivityExecution)was called for this scope. -
stateValue
One entry of the state map, ornull. Never creates the state. -
updateState
Sets one entry of the state map;nullremoves it.- See Also:
-
updateState
-
javaSerialized
The value an internal variable of the agent holds: Java-serialized, whatever the engine's default serialization format (CIB7-2800). Under JSON, where Spin's map type detector is registered, as a host may register it, Spin names the type of a map after its first value, so a map of mixed values cannot be read back; and a whole number comes back as an Integer. Java serialization keeps the types, and every engine can write it, Spin or not, as it writestoolCall(CIB7-2136). -
findOrCreate
The agent state execution ofscopeExecution, created on first use.Created lazily so a scope no agent ever drives carries neither an extra execution nor an extra variable.
-
findAdHocScope
Walks up fromexecutionto the enclosing ad hoc sub process scope, or returnsnullwhen there is none.Identified by the activity's behaviour rather than by element name, the same way
TriggerAdHocActivitiesCmdand the migration validator do, so the check cannot drift from what the runtime actually does. Used by callers that only have the execution of an activity inside the scope — a service task, for instance — and need the scope's own execution. -
turns
Turns taken so far, zero before the first one is counted. -
beginTurn
Counts the turnturnIdbelongs to, once, and returns the count.A turn and its retry are one turn, not two: the id — the turn job's, in practice — is the same for both, so the retry finds it already counted. A
nullid counts every call as its own turn, which is the safe direction: a cap that bites early is better than one that never bites. -
recordCall
Records that the turn now running calledtool, and the call was carried out. -
calledThisTurn
The tools the turn now running called, oldest first; empty before its first call. -
modelCalls
Model calls in the turn now running, zero before the first one is counted. -
countModelCall
Counts the model call of the stepstepId, once, and returns the count for the turn. A step and its retry are one call against the cap, as a turn and its retry are one turn; anullid counts every call. -
isTurnInProgress
Whether the next step continues a turn the model has not ended yet. -
continueTurn
The model called tools and answers in a further step of the same turn. -
endTurn
The turn is over: the model answered, or a limit ended it. -
positiveProperty
A positive-integercamunda:propertyof the scope, orfallback.A value that is not a positive number falls back rather than failing: the value is a modelling mistake, and refusing to run would turn it into an outage, while the fallback still ends the loop.
-