Skip to content

Turns

panel_flowdash.turns

Turns: who changed a dashboard, in which request, and which nodes each change created.

A turn is one request to an agent, or one batch of a person's edits made between requests. A dashboard keeps its turns in the order they were opened, and each node records the turn that created it as its origin. Which later turns changed a node is not stored on the node: it comes from the edit history.

The editor opens and fills turns as edits happen, see :meth:~panel_flowdash.editor.FlowDash.end_turn and :func:agent_edits. An edit belongs to the agent when it is made inside a tool call of a panel-agents AgentRunner, or inside :func:agent_edits, and to the person using the editor otherwise.

MAX_QUESTION_LENGTH = 2000 module-attribute

MAX_TURNS = 200 module-attribute

TURN_ACTORS = ('agent', 'user') module-attribute

TURN_ID_PATTERN = re.compile('^[A-Za-z0-9][A-Za-z0-9_-]{0,63}$') module-attribute

TURN_STATUSES = ('pending',) module-attribute

_AGENT_EDITS = ContextVar('panel_flowdash_agent_edits', default=None) module-attribute

_MORE_LABELS = re.compile('And \\d+ more changes?') module-attribute

_SUMMARY_LABELS = 8 module-attribute

__all__ = ['MAX_QUESTION_LENGTH', 'MAX_TURNS', 'TURN_ACTORS', 'TURN_ID_PATTERN', 'TURN_STATUSES', 'AssetTurn', 'TurnError', 'agent_edits', 'changes_node', 'decode_turns', 'strip_questions', 'summary_cut_short'] module-attribute

__getattr__ = module_getattr(__name__, old_names(globals())) module-attribute

AssetTurn dataclass

One request to an agent, or one batch of a person's edits, that changed a dashboard.

Attributes:

Name Type Description
id str

Unique within the dashboard and never reused, so the nodes' origin and the edit history can refer to it.

actor str | None

"agent" or "user". A planned turn may leave it out.

at str | None

When the turn's first edit was made, as ISO 8601 UTC, e.g. "2026-11-17T20:14:03Z".

run str | None

The panel-agents run id of the agent's request.

question str | None

What the person asked the agent. Recorded by default; exports can leave it out, see :func:~panel_flowdash.editor.export_model.

summary str | None

What the turn changed, a few words per change.

status str | None

None for a turn that ran, "pending" for a planned one that has not.

actor = None class-attribute instance-attribute

at = None class-attribute instance-attribute

id instance-attribute

question = None class-attribute instance-attribute

run = None class-attribute instance-attribute

status = None class-attribute instance-attribute

summary = None class-attribute instance-attribute

from_dict(data) classmethod

Read a turn written by :meth:to_dict, ignoring keys it does not know.

Raises:

Type Description
TurnError

If a field has the wrong type or value, or one that is required is missing.

to_dict()

Return the turn as JSON data, leaving out fields that are not set.

TurnError

Bases: ValueError

A turn's data is malformed. key names the offending field.

key = key instance-attribute

reason = reason instance-attribute

TurnLog

The turns of the dashboard in an editor, and those still open to more edits.

A person's turn stays open until :meth:end_user_turn or an edit of the agent; an agent's turn stays open for the rest of its run, so an edit the person makes while the agent works becomes a turn of its own between two edits of the agent's turn.

turns = [] instance-attribute

add_pending(question)

Add a planned turn asking question, not run yet, and return it.

claim_pending(turn_id, run)

Make the pending turn turn_id the turn of request run's next edits, and return it.

The request's turn so far is closed. The pending turn stays pending until the request's first edit, which makes it the request's turn: the nodes it creates get it as their origin, so its question in the report shows them as its answer.

Raises:

Type Description
TurnError

If no pending turn has the id turn_id.

current()

Return the turn an edit made now belongs to, opening it if needed.

discard(run)

Drop the open turn of request run, e.g. once its edits were all taken back.

A pending turn the request took over is pending again, as it was.

drop_pending(ids)

Drop the pending turns ids; turns that ran are kept.

end_agent_turns(run=None)

Close the agent's open turns, or only request run's, so the next request's edits open a new one.

A pending turn the request claimed but made no edit for stays pending.

end_user_turn()

Close the person's open turn, so their next edit opens a new one.

prune(keep)

Drop the oldest closed turns not in keep until at most MAX_TURNS are left.

record(*labels)

Note an edit, described by labels, in the turn it belongs to, and return that turn.

reset(turns, *, keep_open=False)

Replace the turns, e.g. with a loaded dashboard's; keep_open keeps the open ones open.

snapshot()

Return copies of the turns, for a model to keep.

_AgentEdits dataclass

question instance-attribute

run instance-attribute

_agent_source()

Return the agent request the calling code edits for, or None for the person's own edits.

_clear_agent()

_node(ref)

_now()

_question(text)

_summary_labels(summary)

Return the labels :func:summarize joined into summary, without its count of the rest.

_without_excluded(filters, removed)

_without_removed(report, removed)

agent_edits(run=None, question=None)

Count the edits made inside the block as the agent's, in the turn of request run.

The dashboard tools wrap each call in it. Tools of your own that change an editor need it only when they do not run in a panel-agents AgentRunner, whose tool calls count as the agent's anyway.

Parameters:

Name Type Description Default
run str | None

The run id of the agent's request; edits of the same run share a turn. Defaults to the panel-agents run the block executes in.

None
question str | None

What the person asked, recorded on the turn when it opens.

None

change_labels(old, new)

Describe the change between two dashboard YAML documents as turn summary labels.

Unlike the diff shown to the person, the labels name what changed but not the values, so a summary never repeats a config value such as a query, and edges by their nodes alone, so it never names the hidden port of a node someone may not use.

changes_node(turn, name)

Whether turn's summary says it changed the node called name, beyond adding it.

A summary names at most a few changes, so a turn that changed many nodes may leave this one out.

decode_turns(value)

Return stored turns, which may be missing (None), as a list of :class:AssetTurn.

Raises TypeError unless they are a list, and :class:TurnError for a malformed turn or two turns with the same id. Turns are optional, so the stores catch this and drop just the turns, with a warning, rather than skipping the whole dashboard.

module_getattr(module, names)

Return a module __getattr__ resolving deprecated names (old to new) with a warning.

old_names(module_globals)

Return the deprecated class names a module keeps, old to new, for its own new classes.

person_context()

Return a copy of the current context in which edits count as the person's.

For work the agent's edits set off that acts for the person, e.g. a held back inspector draft checked again after the agent rewired its node: run in it, the draft's edits land in the person's own history batch, not in the agent's turn.

strip_questions(turns)

Return copies of exported turns without the questions asked in them.

summarize(labels)

Join change labels such as "Added kpi" into a summary, naming at most 8 of them.

summary_cut_short(turn)

Whether turn's summary left changes out ("And 3 more changes"), so it may not name every node it changed.